Linux – ZONE_NORMAL and it’s association with Kernel/User-pages

armdriverskernellinuxmemory

Diagram

Above is presented a case where I have only 512 MB of physical memory. What I have read up so far, is that ZONE_NORMAL is mapped to the kernel virtual address space as shown. Essentially I have a 512 MB physical memory, out of which 496 MB worth of ZONE_NORMAL is mapped to the kernel virtual space. Based on this understanding, following are my question:

  • Does, ZONE_NORMAL consists of only kernel space pages ?
  • If ZONE_NORMAL consists only of kernel pages and is mapped completely to the kernel space virtual address range, where do the user space pages get located ?? There does not seem to be any room for user space pages in physical memory.

I am totally mixed up of the case where the physical memory is less than 4GB as shown in this case that I have put forth.

Would really appreciate if someone can throw light on this.

Best Answer

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
Related Question