On a 32-bit architecture you have 0xffffffff
(4'294'967'295
or 4 GB) linear addresses (not physical space) to refer to a physical address.
Even with only 512 MB of physical storage (the real RAM stick connected to the bus), the kernel will still use 4'294'967'295
(4 GB) linear addresses to calculate the physical ones.
The linux kernel divides these 4 GB (of addresses) into the user space (high memory) and the kernel space (low memory) by 3/1, so the kernel space has 1'073'741'823
(1 GB) of linear addresses to use.
These 1 GB of linear addresses, are only accessible by the kernel and are getting divided up even further.
ZONE_DMA: Contains page frames of memory below 16 MB. This is used for old ISA buses, they are able to address only the first 16 MB of RAM.
ZONE_NORMAL: Contains page frames of memory at and above 16 MB and below 896 MB, these are the addresses, which the kernel can map/access directly.
ZONE_HIGHMEM: Contains page frames of memory at and above 896 MB, page frames above this border are not generally mapped to the kernel space and therefore not directly accessible by the kernel. Page frames from the user space can be temporarily or permanently mapped here.
How much real, physical RAM space is occupied by the different zones depends on the form and number of processes you run.
If you enter free -ml
in your console, you can see the usage including low- and high memory:
total used free shared buffers cached
Mem: 3022 2116 905 0 105 1342
Low: 839 196 642
High: 2182 1919 263
-/+ buffers/cache: 667 2354
Swap: 2859 93 2766
"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
Yes and yes.
Before we go any further, we should state this about memory.
Memory get's divided into two distinct areas:
Processes running under the user space have access only to a limited part of memory, whereas the kernel has access to all of the memory. Processes running in user space also don't have access to the kernel space. User space processes can only access a small part of the kernel via an interface exposed by the kernel - the system calls. If a process performs a system call, a software interrupt is sent to the kernel, which then dispatches the appropriate interrupt handler and continues its work after the handler has finished.
Kernel space code has the property to run in "kernel mode", which (in your typical desktop -x86- computer) is what you call code that executes under ring 0. Typically in x86 architecture, there are 4 rings of protection. Ring 0 (kernel mode), Ring 1 (may be used by virtual machine hypervisors or drivers), Ring 2 (may be used by drivers, I am not so sure about that though). Ring 3 is what typical applications run under. It is the least privileged ring, and applications running on it have access to a subset of the processor's instructions. Ring 0 (kernel space) is the most privileged ring, and has access to all of the machine's instructions. For example to this, a "plain" application (like a browser) can not use x86 assembly instructions
lgdt
to load the global descriptor table orhlt
to halt a processor.For an answer to this, please refer to the excellent answer by wag here