linux – Understanding High Memory and Low Memory on Linux
kernellinuxmemory
I'm interested in the difference between Highmem and Lowmem:
Why is there such a differentiation?
What do we gain by doing so?
What features does each have?
Best Answer
On a 32-bit architecture, the address space range for addressing RAM is:
0x00000000 - 0xffffffff
or 4'294'967'295 (4 GB).
The linux kernel splits that up 3/1 (could also be 2/2, or 1/3 1) into user space (high memory) and kernel space (low memory) respectively.
The user space range:
0x00000000 - 0xbfffffff
Every newly spawned user process gets an address (range) inside this area. User processes are generally untrusted and therefore are forbidden to access the kernel space. Further, they are considered non-urgent, as a general rule, the kernel tries to defer the allocation of memory to those processes.
The kernel space range:
0xc0000000 - 0xffffffff
A kernel processes gets its address (range) here. The kernel can directly access this 1 GB of addresses (well, not the full 1 GB, there are 128 MB reserved for high memory access).
Processes spawned in kernel space are trusted, urgent and assumed error-free, the memory request gets processed instantaneously.
Every kernel process can also access the user space range if it wishes to. And to achieve this, the kernel maps an address from the user space (the high memory) to its kernel space (the low memory), the 128 MB mentioned above are especially reserved for this.
1 Whether the split is 3/1, 2/2, or 1/3 is controlled by the CONFIG_VMSPLIT_... option; you can probably check under /boot/config* to see which option was selected for your kernel.
"High memory" and "low memory" do not apply to the virtual address space of processes, it's about physical memory instead.
In the process' virtual address space, the user space occupies the first 3GB, and the kernel space the fourth GB of this linear address space.
The first 896MB of the kernel space (not only kernel code, but its data also) is "directly" mapped to the first 896 MB of the physical memory. It is "direct" in the sense that there's always an offset of 0xc0000000 between any linear address of this 896MB part of the virtual kernel space and its corresponding address in physical memory (note however that the MMU is enabled and that page table entries are actually used for this).
The last 128MB part of the virtual kernel space is where are mapped some pieces of the physical "high memory" (> 896MB) : thus it can only map no more than 128MB of "high memory" at a time.
Reference: "Understanding the Linux Kernel", third edition - sections "8.1.3. Memory Zones" and "8.1.6. Kernel Mappings of High-Memory Page Frames".
Best Answer
On a 32-bit architecture, the address space range for addressing RAM is:
or
4'294'967'295
(4 GB).The linux kernel splits that up 3/1 (could also be 2/2, or 1/3 1) into user space (high memory) and kernel space (low memory) respectively.
The user space range:
Every newly spawned user process gets an address (range) inside this area. User processes are generally untrusted and therefore are forbidden to access the kernel space. Further, they are considered non-urgent, as a general rule, the kernel tries to defer the allocation of memory to those processes.
The kernel space range:
A kernel processes gets its address (range) here. The kernel can directly access this 1 GB of addresses (well, not the full 1 GB, there are 128 MB reserved for high memory access).
Processes spawned in kernel space are trusted, urgent and assumed error-free, the memory request gets processed instantaneously.
Every kernel process can also access the user space range if it wishes to. And to achieve this, the kernel maps an address from the user space (the high memory) to its kernel space (the low memory), the 128 MB mentioned above are especially reserved for this.
1 Whether the split is 3/1, 2/2, or 1/3 is controlled by the
CONFIG_VMSPLIT_...
option; you can probably check under/boot/config*
to see which option was selected for your kernel.