__for_each_mem_range(9)
π
__for_each_mem_range β NAME β¨
Okay bestie, so this one is a macro from the Kernel API Manual (that's the (9) section, iykyk π«Ά), and it's literally a little loop machine: __for_each_mem_range iterates through the memblock areas from type_a that are not included in type_b. Or, if type_b is NULL, it just does type_a all on its own. No cap. π
πΈ SYNOPSIS πΈ
__for_each_mem_range (i , type_a , type_b , nid , flags , p_start ,
p_end , p_nid );
That's the whole vibe check β it's a macro, so it takes all its lil arguments by name, no return value energy here. β¨
π ARGUMENTS π
iβ au64that gets used as the loop variable. It's the main character of the iteration, fr fr. πtype_aβ a ptr to thememblock_typeyou're iterating over. This is the source block, the one we're walking through. πΆββοΈtype_bβ a ptr to amemblock_typethat gets excluded from the iteration. Anything hanging out in here does not get visited. Rude? A little. But iconic. π (If it'sNULL, nothing gets excluded β see above.)nidβ the node selector. PassNUMA_NO_NODEif you want all the nodes, because we're not about that exclusionary life. πflagsβ pick which blocks you want based on their memory attributes. Yes, you literally filter by flags. π©p_startβ a ptr to aphys_addr_twhere the start address of the range goes. Can beNULLβ no pressure, it's optional. πp_endβ a ptr to aphys_addr_twhere the end address of the range goes. Can beNULLtoo. Chillin'. π¦p_nidβ a ptr to anintfor the nid of the range. Also can beNULL. Three for three on the optional pointers, we love a flexible queen. πΈ
π¨ Bestie, real talk: those three pointer args are the outputs of the loop. If you pass NULL you're just saying "I don't need that one", so don't go dereferencing something you never asked for, okay? π
π₯ SEE ALSO π₯
The kernel file lives at ./include/linux/memblock.h β that's where all the good stuff is. π Then go look at all these, in this exact order 'cause that's how the page serves it:
enum memblock_flags(9)struct memblock_region(9)struct memblock_type(9)struct memblock(9)for_each_physmem_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(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)
Like, there's a reverse version __for_each_mem_range_rev and a for_each_mem_range without the underscores, so pick your fighter. π₯ And honestly? The _reverse variants ate too. π
Okay that's the whole page, bestie β go iterate some memblocks and slay. πβ¨
Mwah π β brought to you from the ./include/linux directory, dated October 2026, and yes the page name is still __for_each_mem_range(9) because we don't change the facts, we just change the vibe. π
π¦ 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