alloc_contig_pages(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 if nid doesn'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_page on 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:


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