for_each_node_numadist(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… for_each_node_numadist(9) β€” the Kernel API Manual, but make it make sense

okay bestie, so this is a page from the Kernel API Manual (for_each_node_numadist(9)), and it's literally about walking NUMA nodes in order of how far away they are. no cap, it's giving "shortest road trip first" energy πŸš—βœ¨


✨ NAME ✨

for_each_node_numadist β€” iterate over nodes in increasing distance order, starting from a given node πŸ¦‹


🌸 SYNOPSIS 🌸

for_each_node_numadist (node , unvisited );

that's the whole vibe, she's a macro πŸ’…


πŸŽ€ ARGUMENTS πŸŽ€

  • node β€” this one's doing double duty fr: it's the iteration variable and it's your starting node. main character energy πŸ‘‘
  • unvisited β€” a nodemask that keeps track of the unvisited nodes. think of it as the "still gotta get to these" checklist πŸ“

πŸ’– DESCRIPTION πŸ’–

so this macro iterates over NUMA node IDs in increasing distance from the starting node, and it yields MAX_NUMNODES when all the nodes have been visited. that's the finish line, that's the credits rolling 🎬

note (and this part matters, bestie): by the time the loop completes, the unvisited nodemask will be fully cleared β€” unless the loop exits early. so if you bounce out of the loop mid-way, don't come crying that the mask is still messy 😭

now, the difference between for_each_node and for_each_node_numadist? iconic contrast, honestly:

  • for_each_node lets you iterate over nodes in numerical order (1, 2, 3, boring but reliable ✨)
  • for_each_node_numadist iterates over nodes in increasing order of distance (nearest-first, like a good friend 🫢)

the complexity of this iterator is O(N^2), where N represents the number of nodes, because each iteration involves scanning all nodes to find the one with the shortest distance. yeah, she's doing a lot of work per lap, lowkey expensive but she's worth it πŸ”₯

⚠️ requires rcu_lock to be held. not a suggestion, not a vibe, an actual requirement β€” hold that lock, bestie πŸ’€

🌈 SEE ALSO 🌈


okay that's the page!! this one lives in ./include/linux, dated October 2026, and it's been a whole journey β€” stay locked, stay close to your nodes, and slay πŸ’œπŸ§šβ­

πŸ“¦ where this page comes from