Why do we need zone_highmem on x86?

In the linux kernel, mem_map is an array that contains all the "struct page" descriptors. These pages include 128MiB of memory in lowmem for dynamic display of highmem.

Since the size of lowmem is 1GiB, so the mem_map array has only 1GiB / 4KiB = 256KiB entries. If each record size is 32 bytes, mem_map = 8MiB. But if we could use mem_map to map all 4GiB physical memory (if we have so much physical memory available on x86-32), then the mem_map array will occupy 32MiB, is that not so much kernel memory (or am I mistaken?).

So my question is: why should we use this 128MiB in low to indirectly display highmem in the first place? Or in another way, why not map all of this maximum 4GiB physical memory (if available) in the kernel directly?

Note. If my understanding of the above kernel source is incorrect, correct it. Thanks!

+6
memory-management linux linux-kernel
source share
3 answers

Have a look here: http://www.xml.com/ldd/chapter/book/ch13.html

Low kernel memory is a โ€œrealโ€ memory card addressed by 32-bit x86 pointers.

The memory core is a โ€œvirtualโ€ memory card addressed by x86 virtual structures.

You do not want to map all of this to the kernel address space, because you cannot always access everything, and you need most of your memory for virtual memory segments (virtual, paginated process space).

At least the way I read it. Wow, this is a difficult question you asked.

To add more confusion, Chapter 13 says that some PCI devices cannot address 32-bit space, which was the reason for my previous comment:

On x86, some core memory usage is limited to the first Gigabyte memory due to DMA addressing issues. I am not 100% familiar with this topic, but there is a compatibility mode for DMA on the PCI bus. Perhaps this is what you are looking for.

+1
source share

3.6 GB is not a ceiling when using the physical address extension, which is usually necessary on most modern x86 boards, especially with a hot memory connection.

0
source share

Or in another way, why not display all of these maximum 4GiB physical memory (if available) in the kernel directly?

One reason is user space: each use process uses its own virtual address space. Suppose you have 4 GB of RAM on x86. Therefore, if we assume that 1 GB of memory belongs to the kernel (~ 800 directly mapped to + ~ 200 vmalloc), all the remaining ~ 3Gb should be dynamically distributed between processes rotating in user space. So, how can you map your 4Gbs directly when you have multiple address spaces?

why do we need zone_highmem on x86?

The reason is the same. The kernel reserves only ~ 800Mb for low values. All other memory will be allocated and connected to a specific virtual address only on demand. For example, if you execute binary code, a new virtual address space will be created, and some pages will be allocated to store binary code and data (heap, stack ...). Thus, the key attribute of high mem is servicing dynamic memory allocation requests, you never know in advance what will be caused by user space ...

0
source share

All Articles