__free_contig_range(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– __free_contig_range β€” Kernel API Manual ✨

Okay bestie, so this page is __free_contig_range(9) β€” like, the kernel API manual entry, and it's genuinely iconic once you get the vibe. Buckle up πŸŽ€


🌸 NAME 🌸

__free_contig_range β€” frees a contiguous range of order-0 pages. That's it, that's the whole girl. πŸ’…


✨ SYNOPSIS ✨

void __free_contig_range (unsigned long pfn , unsigned long nr_pages );

Like, no return value, it just goes in and does the thing 🫢


πŸ¦‹ ARGUMENTS πŸ¦‹

  • pfn β€” the page frame number of the first page in the range. Like the starting address of the whole little squad, lowkey 🐾
  • nr_pages β€” how many pages you're freeing. Count 'em. ✨

πŸ’œ DESCRIPTION πŸ’œ

So for each order-0 struct page in that physically contiguous range, it puts a reference. And then β€” and this is the part β€” it frees any page whose reference count falls to zero. πŸ’€ Love that for them.

And ngl the implementation is functionally equivalent to calling __free_page for each struct page in a loop, except it's significantly faster. Like, same result, way better performance. It ate, honestly. πŸ”₯

Memory that was allocated with alloc_pages(order>=1) and then subsequently split to order-0 with split_page β€” that's the textbook example of appropriate contiguous pages you can free with this API. iykyk πŸ’…


⭐ CONTEXT ⭐

Okay so main character energy, but read the room:

  • βœ… You may call it in interrupt context.
  • βœ… You may call it while holding a normal spinlock.
  • ❌ You may NOT call it in NMI context.
  • ❌ You may NOT call it while holding a raw spinlock.
🚨 Bestie. Read the no-list again. NMI context and raw spinlocks are a hard no, fr fr. Do not test this. πŸ™ˆ

πŸŽ€ SEE ALSO πŸŽ€

The kernel file lives at ./mm/page_alloc.c, and here's the whole friend group 🌈:


Sources and version check: this one comes out of ./mm, dated October 2026, and it's __free_contig_range(9) all the way down. Slay. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from