Re: [PATCH 01/22] mm: add node-state-filtered zone and node iterators
From: Gregory Price (Meta)
Date: Wed Nov 18 2026 - 10:18:06 EST
On 2026-11-18 16:29 +0800, Richard Cheng wrote:
> On Sat, Nov 14, 2026 at 02:09:38AM +0800, Gregory Price (Meta) wrote:
> > +/**
> > + * for_each_zone_node_state - iterate zones in intersect(nodemask, node_state(state))
> > + * @zone: The current zone in the iterator
> > + * @z: The current pointer within zonelist->_zonerefs being iterated
> > + * @zlist: The zonelist being iterated
> > + * @highidx: The zone index of the highest zone to return
> > + * @nodemask: Nodemask allowed by the allocator
> > + * @state: The node state the zone's node must be in
> > + *
> > + * The state filter is part of the iteration rather than a trailing if, so that
> > + * this expands to a single for statement: a macro ending in an unbraced if
> > + * silently steals a following else from the caller.
> > + */
> > +#define for_each_zone_node_state(zone, z, zlist, highidx, nodemask, state) \
> > + for (z = first_zones_zonelist_state(zlist, highidx, nodemask, state), \
> > + zone = zonelist_zone(z); \
> > + zone; \
> > + z = next_zones_zonelist_state(++z, highidx, nodemask, state), \
> > + zone = zonelist_zone(z))
> > +
>
> A question on consistency. This one is a single for statement, with 2 new helper functions.
> for_each_populated_zone_state() in the same patch uses "if (!cond) ; else" form instead.
>
> Both forms keep a caller's else correct. The only difference I can find is that the if/else
> form give a -Wdangling-else warning when the loop is the unbraced body of an if.
>
> Is that the reason for the 2 helper function here? If the warning doesn't matter, this could
> use the same short form and drop the 2 functions. If it does matter, should
> for_each_populated_zone_state() be a single statement too ?
>
Yeah I was getting that warning from various checks. I'd convinced
byself this was a false-positive, but it does look very funky indeed.
Let me look into this again, it's possible I can massage this better to
use the short form still. It's also possible that I should just use a
different shape entirely than trying to use the existing pattern.
--
~Gregory