lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZEdHpxPRwcGVOctJ@casper.infradead.org>
Date:   Tue, 25 Apr 2023 04:23:19 +0100
From:   Matthew Wilcox <willy@...radead.org>
To:     Andrew Morton <akpm@...ux-foundation.org>
Cc:     Yajun Deng <yajun.deng@...ux.dev>, david@...hat.com,
        osalvador@...e.de, gregkh@...uxfoundation.org, rafael@...nel.org,
        linux-mm@...ck.org, linux-kernel@...r.kernel.org,
        linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH] mmzone: Introduce for_each_populated_zone_pgdat()

On Mon, Apr 24, 2023 at 02:58:23PM -0700, Andrew Morton wrote:
> On Mon, 24 Apr 2023 04:50:37 +0100 Matthew Wilcox <willy@...radead.org> wrote:
> 
> > On Mon, Apr 24, 2023 at 11:07:56AM +0800, Yajun Deng wrote:
> > > Instead of define an index and determining if the zone has memory,
> > > introduce for_each_populated_zone_pgdat() helper that can be used
> > > to iterate over each populated zone in pgdat, and convert the most
> > > obvious users to it.
> > 
> > I don't think the complexity of the helper justifies the simplification
> > of the users.
> 
> Are you sure?
> 
> > > +++ b/include/linux/mmzone.h
> > > @@ -1580,6 +1580,14 @@ extern struct zone *next_zone(struct zone *zone);
> > >  			; /* do nothing */		\
> > >  		else
> > >  
> > > +#define for_each_populated_zone_pgdat(zone, pgdat, max) \
> > > +	for (zone = pgdat->node_zones;                  \
> > > +	     zone < pgdat->node_zones + max;            \
> > > +	     zone++)                                    \
> > > +		if (!populated_zone(zone))		\
> > > +			; /* do nothing */		\
> > > +		else
> > > +
> 
> But each of the call sites is doing this, so at least the complexity is
> now seen in only one place.

But they're not doing _that_.  They're doing something normal and
obvious like:

	for (zone = pgdat->node_zones; zone < pgdat->node_zones + max; zone++) {
		if (!populated_zone(zone)
			continue;
		...
	}

which clearly does what it's supposed to.  But with this patch, there's
macro expansion involved, and it's not a nice simple macro, it has a loop
_and_ an if-condition, and there's an else, and now I have to think hard
about whether flow control is going to do the right thing if the body
of the loop isn't simple.

> btw, do we need to do the test that way?  Why won't this work?
> 
> #define for_each_populated_zone_pgdat(zone, pgdat, max) \
> 	for (zone = pgdat->node_zones;                  \
> 	     zone < pgdat->node_zones + max;            \
> 	     zone++)                                    \
> 		if (populated_zone(zone))

I think it will work, except that this is now legal:

	for_each_populated_zone_pgdat(zone, pgdat, 3)
	else i++;

and really, I think that demonstrates why we don't want macros that are
that darn clever.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ