Skip to content
Advertisement

Is there a different memory allocation path other than the buddy allocator in linux?

I’m understanding memory allocation in Linux and doing some changes in buddy allocator (__alloc_pages_nodemask) for my experiments. I create a new flag in struct page->flags (by adding a new flag in enum pageflags in page-flags.h. I set this bit permanently in __alloc_pages_nodemask (to not to be cleared once set and survive all further allocation and freeing. I modify PAGE_FLAGS_CHECK_AT_PREP to ensure it). But I’m not able to see expected behavior.

I’m guessing this is because Linux is also using some different path to allocate memory (probably during boot). Is my hypothesis correct?

Is there any different memory allocation path other than buddy allocator? Where can I find it?

Advertisement

Answer

I asked this question on kernel mailing list. David / dhildenb replied and his answer was helpful.

memblock is the early memory allocator during boot, before the buddy is up and running. The range allocator (e.g., alloc_contig_range()) is some kind of mechanism that builds up on top of the buddy. Other allcoators (hugetlb, slab, …) might cache some pages, but effectively get “physical memory” either via memblock or the buddy.

CMA is another special-purpose allocator which reserves physical memory areas via memblock and then uses the range allocator to actually allocate memory inside these reserved regions at runtime.

One can find the complete documentation and APIs for memblock in mm/memblock.c.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement