Monday, May 06, 2013

Process Virtual Memory

Each process maps either 2^32 or 2^44 bytes of memory (depending on whether the OS is running in 32 or 64-bit mode). This works out to 4GB or 16TB. Not all of this memory is allocated (used); the virtual memory is used as address space that can be mapped to actual memory resources.

Virtual memory structure for a process can be described as in this diagram:


While this is part of the address space, it cannot be addressed directly by the process. It must be addressed via system calls.

Used by the program for variables and storage. It grows and shrinks in size depending on what routines are called and what their stack space requirements are. It is normally about 8MB in size.
Shared Libraries
Shared libraries are position independent so that they can be shared by all programs that want to use them. One common example is

This is the address space that is unallocated and unused. It does not tie up physical memory. For most processes, this is the largest portion of the virtual memory for the process.

Used for some types of working storage. It is allocated by the malloc function.

Uninitialized variables. These are not part of the executable file and their initial value is set to zeros.

Global variables, constants, static variables from the program.

Set of instructions from the compiler-generated executable file.

The virtual memory map for a process can be displayed using the pmap command.

Additional information is available on the Processes page.

No comments: