User Tools

Site Tools


foss:wikishelf:linux:memory

Linux kernel memory management

Quick introduction

Linux process virtual memory

Each process in Linux (and this has similarities in many Unix systems too) is allocated a virtual address space. On a 32bit system, this virtual address space is up to 4GiB (2^32). On a 64bit system (Intel or AMD IA32, aka x86_64 or x64), this virtual address space is up to 256TiB (2^48, current CPUs from Intel and AMD which support long mode, aka x64, only address 48 bits of memory).

Each process' virtual memory contains a kernel space and a user space area. On a 32bit system, the splits depends if PAE is activated or not, so it can be 3GiB/1GiB or 2GiB/2GiB. On 64bit, it is always (AFAIK) half/half, so the first 47bit (128TiB) are for user space, and at the end of the 64 bit area, there is 128TiB reserved for the kernel.

Virtual memory comprises the code, data and BSS of the running process (more later on that), it includes also the stack and heap, and the memory mapping area. This area contains any shared memory (IPC, shared objects) and can also contains (AFAIK) mapped files in memory. Learn more in the dedicated section below.

Some more info about mapped files

One can mapped files bigger than available memory, so the VIRT size can be bigger than the memory. The kernel is clever enough to load/unload the data from the storage to memory to accelerate I/O as much as the available physical free RAM permits it.

Some tools like top reports the virtual size of a process (top has a column named VIRT), as a user, you should not pay too much attention to this information. This is mainly intended for (hard core) developers.

Kernel memory layout

x86 32bit

[todo]

x86 64bit

[todo]

foss/wikishelf/linux/memory.txt · Last modified: 2015/05/01 23:32 (external edit)