Why does allocating pages with order 10 or 11 using __get_free_pages () usually fail?

My system memory is plentiful (server with 24 GB). On my system, kernel space is allocated 320 MB and 120 MB for the kernel failure. The rest of the memory is used for other purposes. However, when I use __get_free_pages() to select adjacent pages with order 11, and the kernel does not allocate 2 ^ 10 pages. Why?

According to makelinux

The maximum allowable value for the order of 10 or 11 (corresponding to 1024 or 2048 pages), depending on the architecture. The chances of an order of-10 distribution running on something else other than the just loaded system with a large amount of memory are small.

Why is this so? Each page on my system is 4 KB (4096 bytes), 2 ^ 10 pages = 1024 pages, and the total size is 1024 * 4096 = 4 194 304 (bytes) ~ 4 MB. This is only 4 MB of continuous space, and the kernel is very small: vmlinuz - only 2.1 MB, and initrd - 15 MB. The total memory consumption of the entire kernel is ~ 300 MB. For the kernel should be more than enough to allocate 4 MB of contiguous pages. Even in a regular machine with a kernel / user 1 GB / 3 GB and I’m sure that the kernel will not use all 1 GB. But how can addition happen only with 4MB adjacent pages? And I think that in the kernel space the memory is not scattered in physical memory (due to the display of virtual memory), but it is linear and continuous.

I tried loading my kernel module first with a distribution of 2 ^ 10 pages, but it fails and resets the stack trace:

 [ 6.037056] [<ffffffff810041ec>] dump_trace+0x86/0x2de [ 6.037063] [<ffffffff8122fe83>] dump_stack+0x69/0x6f [ 6.037070] [<ffffffff8108704e>] warn_alloc_failed+0x13f/0x151 [ 6.037076] [<ffffffff8108786a>] __alloc_pages_nodemask+0x80a/0x871 [ 6.037081] [<ffffffff81087959>] __get_free_pages+0x12/0x50 
+6
source share
1 answer

If I remember correctly, __get_free_pages uses a buddy distribution that not only scatters its distribution across physical memory, it does it into the worst possible pattern for subsequent attempts to allocate large contiguous blocks. If my calculations are correct, then in your system with 24 GB of physical RAM, even if the space didn’t do anything at all, except for acceptance distributions, it would take less than 8192 order-0 (4 KB) allocations to render the allocation of block 4 MB with __get_free_pages not possible.

There is a thing called a continuous memory allocator , which should solve the real need for large physically adjacent allocations by device drivers; since June 2011, it has not been in the official core, but that was more than a year ago. You must learn this.

+6
source

Source: https://habr.com/ru/post/919733/


All Articles