[PATCH 01/60] nodemask: add node-state iterators
From: Gregory Price via B4 Relay
Date: Fri Nov 20 2026 - 13:12:03 EST
From: "Gregory Price (Meta)" <gourry@xxxxxxxxxx>
Add first_node_state() and next_node_state(), so callers can walk any
node state the way first_memory_node and next_memory_node walk N_MEMORY.
Add for_each_node_mask_state(), which iterates a nodemask intersected
with a node state using the bitmap intersection helpers, without a
temporary nodemask.
Signed-off-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
---
include/linux/nodemask.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index 607373bd83ee..90bdcffa42ea 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -411,6 +411,11 @@ enum node_states {
extern nodemask_t node_states[NR_NODE_STATES];
+/* Iterate the nodes in a mask that also belong to the specified state. */
+#define for_each_node_mask_state(node, mask, state) \
+ for_each_and_bit(node, nodes_addr(mask), \
+ nodes_addr(node_states[state]), MAX_NUMNODES)
+
#if MAX_NUMNODES > 1
static __always_inline int node_state(int node, enum node_states state)
{
@@ -435,6 +440,12 @@ static __always_inline int num_node_state(enum node_states state)
#define for_each_node_state(__node, __state) \
for_each_node_mask((__node), node_states[__state])
+#define first_node_state(state) first_node(node_states[state])
+static __always_inline unsigned int next_node_state(int nid, enum node_states state)
+{
+ return next_node(nid, node_states[state]);
+}
+
#define first_online_node first_node(node_states[N_ONLINE])
#define first_memory_node first_node(node_states[N_MEMORY])
static __always_inline unsigned int next_online_node(int nid)
@@ -481,6 +492,12 @@ static __always_inline int num_node_state(enum node_states state)
#define for_each_node_state(node, __state) \
for ( (node) = 0; (node) == 0; (node) = 1)
+#define first_node_state(state) 0
+static __always_inline unsigned int next_node_state(int nid, enum node_states state)
+{
+ return MAX_NUMNODES;
+}
+
#define first_online_node 0
#define first_memory_node 0
#define next_online_node(nid) (MAX_NUMNODES)
--
2.56.1