__free_contig_range(9)
π __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 π:
__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)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)
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
- 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