Re: [PATCH 01/60] nodemask: add node-state iterators

From: Yury Norov

Date: Sun Nov 22 2026 - 10:32:34 EST


On Fri, Nov 20, 2026 at 01:08:52PM -0500, Gregory Price via B4 Relay wrote:
> 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_node_state_and? We've got for_each_node(), and we've got
for_each_node_state(), so let's figure out consistent naming.

Did you check the codebase for exsisting candidates for this helper?

> + for_each_and_bit(node, nodes_addr(mask), \
> + nodes_addr(node_states[state]), MAX_NUMNODES)
> +

Please use nr_node_ids instead of 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]);
> +}

At least the following {first,next}_{online,memory}_node must be
switched to the new helpers. Can you check through the rest of the
kernel to make sure all candidates of the proposed helpers are
converted?

> #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
>