for_each_free_mem_range(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ 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 β€” a u64 used as the loop variable. it's your counter girlie, she's doing the walking πŸšΆβ€β™€οΈ
  • nid β€” the node selector. pass NUMA_NO_NODE if 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 a phys_addr_t for the start address of the range. it can be NULL, she's flexible 🫢
  • p_end β€” a ptr to a phys_addr_t for the end address of the range. also can be NULL, no pressure πŸ’œ
  • p_nid β€” a ptr to an int for the nid of the range. and yep, can be NULL too. 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:


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