linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Luis Chamberlain <mcgrof@kernel.org>,
	Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: akpm@linux-foundation.org, jhubbard@nvidia.com, mgorman@suse.de,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	dave@stgolabs.net, p.raghav@samsung.com, da.gomez@samsung.com
Subject: Re: [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper
Date: Fri, 15 Mar 2024 12:09:29 +0100	[thread overview]
Message-ID: <532c9e93-e8cc-4f6f-bf08-b5625022dd4f@suse.cz> (raw)
In-Reply-To: <ZfPe22p9U8PiRB0W@bombadil.infradead.org>

On 3/15/24 06:38, Luis Chamberlain wrote:
> On Thu, Mar 14, 2024 at 03:19:45PM +0800, Baolin Wang wrote:
>> 
>> 
>> On 2024/3/14 08:54, Luis Chamberlain wrote:
>> > We can just wrap most of the work done on fragmentation_score_node()
>> > into a pgdat helper for populated zones. Add the helper and use it.
>> > 
>> > Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
>> > ---
>> >   include/linux/mmzone.h | 8 ++++++++
>> >   mm/compaction.c        | 9 ++-------
>> >   2 files changed, 10 insertions(+), 7 deletions(-)
>> > 
>> > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
>> > index a497f189d988..1fd74c7100ec 100644
>> > --- a/include/linux/mmzone.h
>> > +++ b/include/linux/mmzone.h
>> > @@ -1597,6 +1597,14 @@ extern struct zone *next_zone(struct zone *zone);
>> >   			; /* do nothing */		\
>> >   		else
>> > +#define for_each_populated_zone_pgdat(zone, pgdat)	\
>> > +	for (zone = pgdat->node_zones;			\
>> > +	     zone;					\
>> > +	     zone = next_zone(zone))			\
>> > +		if (!populated_zone(zone))		\
>> > +			; /* do nothing */		\
>> > +		else
>> 
>> I think this will break the original logics, since the next_zone() will
>> iterate over all memory zones, instead of only the memory zones of the
>> specified node.
> 
> Definitely, thanks, so we'd need something like this in addition:

IMHO that's unnecessarily complex, why not just do the iteration all inline
without this next_zone_pgdat() helper?

Also maybe you could find more users if you created just a
for_each_zone_pgdat() and left the populated_zone() in the user? Otherwise
it's quite a specific helper with just one user.

> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 34b729fc751b..bd11d33ea14d 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -1568,6 +1568,7 @@ static inline struct pglist_data *NODE_DATA(int nid)
>  extern struct pglist_data *first_online_pgdat(void);
>  extern struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
>  extern struct zone *next_zone(struct zone *zone);
> +extern struct zone *next_zone_pgdat(struct zone *zone, struct pglist_data *pgdat);
>  
>  /**
>   * for_each_online_pgdat - helper macro to iterate over all online nodes
> @@ -1600,7 +1601,7 @@ extern struct zone *next_zone(struct zone *zone);
>  #define for_each_populated_zone_pgdat(zone, pgdat)	\
>  	for (zone = pgdat->node_zones;			\
>  	     zone;					\
> -	     zone = next_zone(zone))			\
> +	     zone = next_zone_pgdat(zone, pgdat))	\
>  		if (!populated_zone(zone))		\
>  			; /* do nothing */		\
>  		else
> diff --git a/mm/compaction.c b/mm/compaction.c
> index 015126803017..96434f6fc1ad 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -2152,7 +2152,6 @@ static unsigned int fragmentation_score_node(pg_data_t *pgdat)
>  {
>  	unsigned int score = 0;
>  	struct zone *zone;
> -	int zoneid;
>  
>  	for_each_populated_zone_pgdat(zone, pgdat)
>  		score += fragmentation_score_zone_weighted(zone);
> diff --git a/mm/mmzone.c b/mm/mmzone.c
> index c01896eca736..043a6dc16c05 100644
> --- a/mm/mmzone.c
> +++ b/mm/mmzone.c
> @@ -43,6 +43,18 @@ struct zone *next_zone(struct zone *zone)
>  	return zone;
>  }
>  
> +/*
> + * next_zone_pgdat - helper magic for for_each_zone() per node
> + */
> +struct zone *next_zone_pgdat(struct zone *zone, struct pglist_data *pgdat)
> +{
> +	if (!zone || !pgdat)
> +		return NULL;
> +	if (zone < pgdat->node_zones + MAX_NR_ZONES - 1)
> +		return ++zone;
> +	return NULL;
> +}
> +
>  static inline int zref_in_nodemask(struct zoneref *zref, nodemask_t *nodes)
>  {
>  #ifdef CONFIG_NUMA



  parent reply	other threads:[~2024-03-15 11:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14  0:54 [PATCH 0/3] mm: random cleanups Luis Chamberlain
2024-03-14  0:54 ` [PATCH 1/3] mm/show_mem: simplify ifdef on si_meminfo_node() Luis Chamberlain
2024-03-14  1:13   ` Kefeng Wang
2024-03-14  0:54 ` [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper Luis Chamberlain
2024-03-14  7:19   ` Baolin Wang
2024-03-15  5:38     ` Luis Chamberlain
2024-03-15  9:39       ` Baolin Wang
2024-03-15 11:09       ` Vlastimil Babka [this message]
2024-03-15 17:48         ` Luis Chamberlain
2024-03-14 11:40   ` kernel test robot
2024-03-14  0:54 ` [PATCH 3/3] mm/vmstat: simplfy extfrag_show_print with fragmentation_index() Luis Chamberlain
2024-03-15 11:13   ` Vlastimil Babka
2024-03-15 14:36   ` Davidlohr Bueso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=532c9e93-e8cc-4f6f-bf08-b5625022dd4f@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=da.gomez@samsung.com \
    --cc=dave@stgolabs.net \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mcgrof@kernel.org \
    --cc=mgorman@suse.de \
    --cc=p.raghav@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox