alloc_pages_exact(9)
π alloc_pages_exact β the Kernel API Manual page you didn't know you needed
okay so this is alloc_pages_exact, straight out of the Kernel API Manual, and bestie, it's genuinely one of the more relatable ones: it does exactly what it says on the tin π
β¨ NAME β¨
alloc_pages_exact β allocate an exact number of physically-contiguous pages. no rounding up, no extra baggage, we're being precise today π
π¦ SYNOPSIS π¦
void * alloc_pages_exact (size_t size , gfp_t gfp_mask );
πΈ ARGUMENTS πΈ
sizeβ the number of bytes to allocate. like, the actual amount you want, not a vibe-based estimate πgfp_maskβ the GFP flags for the allocation. must not contain__GFP_COMP. that's not a suggestion, that's a rule π«
π₯ DESCRIPTION π₯
so here's the tea: this function is similar to alloc_pages, except that it allocates the minimum number of pages to satisfy the request. that's the whole flex.
alloc_pages can only allocate memory in power-of-two pages. iconic but limiting, honestly. alloc_pages_exact said "not me being stuck with that" and just gives you what you asked for π«Ά
it's also limited by MAX_PAGE_ORDER. so like, there is a ceiling, no cap (well, yes cap actually, but you get it).
β οΈ Memory allocated by this function must be released by free_pages_exact. don't just ghost it, bestie. that's a leak and it's not cute π
β RETURN β
a pointer to the allocated area π or NULL in case of error π
π SEE ALSO π
Kernel file ./mm/page_alloc.c, plus this whole squad:
__get_pfnblock_flags_mask(9)get_pfnblock_bit(9)get_pfnblock_migratetype(9)__set_pfnblock_flags_mask(9)set_pfnblock_bit(9)clear_pfnblock_bit(9)set_pageblock_migratetype(9)__move_freepages_block_isolate(9)__putback_isolated_page(9)__free_pages(9)free_pages(9)alloc_pages_exact_nid(9)free_pages_exact(9)nr_free_zone_pages(9)nr_free_buffer_pages(9)find_next_best_node(9)free_reserved_pages(9)setup_per_zone_wmarks(9)__free_contig_range(9)alloc_contig_frozen_range(9)alloc_contig_range(9)alloc_contig_frozen_pages(9)alloc_contig_pages(9)free_contig_frozen_range(9)free_contig_range(9)alloc_pages_nolock(9)
and that's the page, bestie π huge shoutout to the source directory <pink>./mm</pink> and the date <cyan>October 2026</cyan> β this one dropped in October 2026 and honestly it ate π see you in the next man page, mwah π§
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms