Re: [PATCH 01/60] nodemask: add node-state iterators
From: Gregory Price (Meta)
Date: Mon Nov 23 2026 - 09:01:54 EST
On 2026-11-22 10:32 -0500, Yury Norov wrote:
> 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_node_mask_and() would be more consistent, change just requires
passing node_state[N_MEMORY_X] instead of just the node state bit.
> > + for_each_and_bit(node, nodes_addr(mask), \
> > + nodes_addr(node_states[state]), MAX_NUMNODES)
> > +
>
> Please use nr_node_ids instead of MAX_NUMNODES.
>
I followed for_each_node_mask() which uses MAX_NUMANODES but let me
look.
> > #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?
>
I originally intended to delete first/next_memory_node, to make
usage of N_MEMORY a bit more obviously, but dropped it to save an
extra patch or two. I will probably add that back in.
But yeah i can update these otherwise.
--
~Gregory