alloc_pages_exact(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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:


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