alloc_contig_frozen_pages(9)
π alloc_contig_frozen_pages(9) β a Kernel API Manual moment π
okay so bestie, welcome to the alloc_contig_frozen_pages page β this is a Kernel API Manual entry and it's lowkey one of those "you need a big chunk of memory and the normal way isn't giving" situations. grab a strawberry π and let's get into it.
β¨ NAME β¨
alloc_contig_frozen_pages β tries to find and allocate a contiguous range of frozen pages. that's it, that's the vibe. π
πΈ SYNOPSIS πΈ
struct page * alloc_contig_frozen_pages (unsigned long nr_pages , gfp_t gfp_mask , int nid , nodemask_t *nodemask );
π ARGUMENTS π
nr_pagesβ how many contiguous pages you want. the whole point, honestly. πgfp_maskβ the GFP mask. the node/zone/placement hints in here limit the search; only some action and reclaim modifiers are supported. the reclaim modifiers are the ones that control allocation behavior during compaction/migration/reclaim. so yeah, not every flag is welcome at this party π«Άnidβ target node. where you'd like it to live.nodemaskβ mask for other possible nodes. the "backup plan" list, basically.
π¦ DESCRIPTION π¦
so this routine is literally just a wrapper around alloc_contig_frozen_range. that's the whole personality. π
what it does: it scans over zones on an applicable zonelist to find a contiguous pfn range which can then be tried for allocation with alloc_contig_frozen_range. think of it as doing the searching so the real allocator can do the taking.
this routine is intended for allocation requests which can not be fulfilled with the buddy allocator. so if buddy already said no, this is your girl. π₯
now the alignment tea β β the allocated memory is always aligned to a page boundary. and if nr_pages is a power of two, then the allocated range is also guaranteed to be aligned to that same nr_pages (e.g. a 1GB request would be aligned to 1GB). iconic behavior, honestly. β¨
β οΈ bestie the cleanup is not optional!! allocated frozen pages need be freed withfree_contig_frozen_range, or by manually callingfree_frozen_pageson each allocated frozen non-compound page β for compound frozen pages, they could be freed withfree_frozen_pagesdirectly. don't leave these hanging, it's giving memory leak π
π RETURN π
pointer to contiguous frozen pages on success π, or NULL if not successful π.
π SEE ALSO π
buckle up, this list is long and honestly kind of iconic. it's all from the kernel file ./mm/page_alloc.c:
__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_pages(9)free_contig_frozen_range(9)free_contig_range(9)alloc_pages_nolock(9)
go read those next, iykyk π
and that's the page!! this one came from ./mm, dated October 2026, in the Kernel API Manual β slay, go allocate something big, and remember to free it π§π periodt.
π¦ 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