for_each_node_numadist(9)
π 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_nodelets you iterate over nodes in numerical order (1, 2, 3, boring but reliable β¨)for_each_node_numadistiterates 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 π
- Kernel file
./include/linux/topology.h for_each_numa_hop_mask(9)
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
- 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