alloc_contig_pages(9)
π alloc_contig_pages(9)
okay so bestie, welcome to the Kernel API Manual β¨ this one's a little function called alloc_contig_pages and it's lowkey doing some heavy lifting in ./mm. let's get into it π«Ά
πΈ NAME πΈ
alloc_contig_pages β tries to find and allocate contiguous range of pages π
β¨ SYNOPSIS β¨
struct page * alloc_contig_pages (unsigned long nr_pages , gfp_t
gfp_mask , int nid , nodemask_t *nodemask );
like, that's the whole vibe. four args, one struct page * coming back at you π
π¦ ARGUMENTS π¦
nr_pagesβ how many contiguous pages you wanna allocate. like, no gaps, they gotta be besties and sit next to each other fr fr.gfp_maskβ the GFP mask π that's the allocation flavour, yk?nidβ target node π― the node you're actually aiming at.nodemaskβ mask for other possible nodes π so ifniddoesn't work out there's a backup plan, iconic.
π DESCRIPTION π
so here's the tea β this routine is a wrapper around alloc_contig_frozen_pages. cute, right?
but bestie, listen β it can't be used to allocate compound pages. not a thing. π the refcount of each allocated page will be set to one.
and the way you free these bad boys? two options:
free_contig_rangeβ the easy way, ate π- or by manually calling
__free_pageon each allocated page β the DIY way, main character energy π₯
ngl, remember the refcount thing. every single page comes back with refcount one, no cap.
β RETURN β
pointer to contiguous pages on success π or NULL if not successful π that's it. that's the return. vibe check passed either way.
π SEE ALSO π
Kernel file ./mm/page_alloc.c β go read up, iykyk π and like, the whole friend group:
__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(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)free_contig_frozen_range(9)free_contig_range(9)alloc_pages_nolock(9)
aaaand that's the page, bestie π§ this lil slice of ./mm is dated October 2026 and lives under source/version ./mm in the alloc_contig_pages(9) era π go forth and allocate contiguously, slay π
β¨
π¦ 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