__for_each_mem_range(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… __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 β€” a u64 that gets used as the loop variable. It's the main character of the iteration, fr fr. πŸ‘‘
  • type_a β€” a ptr to the memblock_type you're iterating over. This is the source block, the one we're walking through. πŸšΆβ€β™€οΈ
  • type_b β€” a ptr to a memblock_type that gets excluded from the iteration. Anything hanging out in here does not get visited. Rude? A little. But iconic. πŸ’… (If it's NULL, nothing gets excluded β€” see above.)
  • nid β€” the node selector. Pass NUMA_NO_NODE if 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 a phys_addr_t where the start address of the range goes. Can be NULL β€” no pressure, it's optional. πŸ™ˆ
  • p_end β€” a ptr to a phys_addr_t where the end address of the range goes. Can be NULL too. Chillin'. πŸ¦‹
  • p_nid β€” a ptr to an int for the nid of the range. Also can be NULL. 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:

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