for_each_free_mem_range(9)
β¨ for_each_free_mem_range β¨
okay so real talk: this is a page straight out of the Kernel API Manual, and it's about walking through the free areas of memblock. bestie, it's giving "low-level memory lore" and honestly? obsessed. let's get into it π
πΈ NAME πΈ
for_each_free_mem_range β iterate through free memblock areas
like, you loop over the free chunks. that's the whole vibe. periodt.
π¦ SYNOPSIS π¦
for_each_free_mem_range (i , nid , flags , p_start , p_end , p_nid );
copy that exactly, no cap β the spacing is part of the aesthetic π
π ARGUMENTS π
six whole parameters, and yes, every single one matters:
iβ au64used as the loop variable. it's your counter girlie, she's doing the walking πΆββοΈnidβ the node selector. passNUMA_NO_NODEif you want all the nodes, no picking favorites πflagsβ you pick which blocks you want based on memory attributes. choose wisely β¨p_startβ a ptr to aphys_addr_tfor the start address of the range. it can beNULL, she's flexible π«Άp_endβ a ptr to aphys_addr_tfor the end address of the range. also can beNULL, no pressure πp_nidβ a ptr to anintfor the nid of the range. and yep, can beNULLtoo. the whole trio is optional and i love that for them π
π₯ DESCRIPTION π₯
so what does it actually do? it walks over the free (memory && !reserved) areas of memblock. literally that's it, that's the job π
and the iconic part: it's available as soon as memblock is initialized. no waiting around, she's ready immediately. main character energy from the jump π
π SEE ALSO π
the whole friend group, fr fr β go read these too:
- Kernel file
./include/linux/memblock.h enum memblock_flags(9)struct memblock_region(9)struct memblock_type(9)struct memblock(9)for_each_physmem_range(9)__for_each_mem_range(9)__for_each_mem_range_rev(9)for_each_mem_range(9)for_each_mem_range_rev(9)for_each_reserved_mem_range(9)for_each_mem_pfn_range(9)for_each_free_mem_range_reverse(9)memblock_set_current_limit(9)memblock_region_memory_base_pfn(9)memblock_region_memory_end_pfn(9)memblock_region_reserved_base_pfn(9)memblock_region_reserved_end_pfn(9)for_each_mem_region(9)for_each_reserved_mem_region(9)
and that's the page, bestie π§π« sourced from ./include/linux, dated October 2026, and the manual entry is for_each_free_mem_range(9) in case you forgot already π mwah, go loop some memblock π
π¦ 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