3

When I check pagetypeinfo

cat /proc/pagetypeinfo

I see three types of memory zones;

  • DMA
  • DMA32
  • Normal

How Linux choose a memory zone to allocate a new page?

metdos
  • 13,411
  • 17
  • 77
  • 120
  • It depends on the number of free pages in each zone, the priority of the zones and the NUMA node associated with the CPU that issued the request. See http://utcc.utoronto.ca/~cks/space/blog/linux/KernelMemoryZones and https://www.kernel.org/doc/Documentation/vm/numa. – Frédéric Hamidi Aug 05 '13 at 15:27

2 Answers2

6

These memory zones are defined only for the 32 bit systems and not in the 64 bit.

Rememember these are the kernel accessible main memory we are talking about. In a 32 bit (4GB) system, the split between the kernel and the user space is 1:3. Meaning kernel can access 1GB and the user space 3GB. The kernel's 1GB is split as follows:

Zone_DMA (0-16MB): Permanently mapped into the kernel address space.
For compatibility reasons for older ISA devices that can address only the lower 16MB of main memory.

Zone_Normal (16MB-896MB): Permanently mapped into the kernel address space.
Many kernel operations can only take place using ZONE_NORMAL so it is the most performance critical zone and is the memory mostly allocated by the kernel.

ZONE_HIGH_MEM (896MB-above): not permanently mapped into the kernel's address space.
Kernel can access entire 4GB main memory. kernel's 1GB through Zone_DMA & Zone_Normal and user's 3GB through ZONE_HIGH_MEM. With Intel's Physical Address Extension (PAE), one gets 4 extra bits to address the main memory resulting in 36 bits, a total of 64GB of memory that can be accessed. The delta address space (36 bit address - 32 bit address) is where ZONE_HIGH_MEM is used to map to the user accessed main memory (ie between 2GB - 4GB).

Read more:

http://www.quora.com/Linux-Kernel/Why-is-there-ZONE_HIGHMEM-in-the-x86-32-Linux-kernel-but-not-in-the-x86-64-kernel
http://www.quora.com/Linux-Kernel/What-is-the-difference-between-high-memory-and-normal-memory
Linux 3/1 virtual address split

Community
  • 1
  • 1
brokenfoot
  • 11,083
  • 10
  • 59
  • 80
  • 1
    This is not quite accurate - the DMA32 zone exists on the x86-64 architecture and its introduction is explained here: http://lwn.net/Articles/152337/ - basically, it is equivalent to DMA, used for drivers which need it. Other kernel memory uses will end up in Normal but will go into DMA32 if there is not enough space (e.g. if there is only 3GB, most of it is likely to be in zone DMA32, so it'll have to use that). – GreenReaper Jun 30 '15 at 06:10
  • Yes, GreenReaper, I noticed that too. – Peter Teoh Jul 21 '17 at 06:01
  • @brokenfoot But on x64 platform, I still can see these zones indeed: "zone_DMA","zone_DMA32" and "zone_normal".So maybe it's not solely on x32 platform. – John Jun 22 '20 at 04:00
1

For every memory allocation request (for eg via kmalloc), based on the flags passed to the function,kernel selects the memory zone. these requests internally triggers the kernel function alloc_pages().

zonelist is an argument that gets passed to alloc_pages(), that Points to a zonelist data structure describing, in order of preference, the mem- ory zones suitable for the memory allocation.

refer the memory management chapter in book Understanding the Linux kernel

kiran bobbu
  • 133
  • 2
  • 11