lkml.org 
[lkml]   [2024]   [Mar]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper
From


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.

> static inline struct zone *zonelist_zone(struct zoneref *zoneref)
> {
> return zoneref->zone;
> diff --git a/mm/compaction.c b/mm/compaction.c
> index b961db601df4..023a09d0786d 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -2151,16 +2151,11 @@ static unsigned int fragmentation_score_zone_weighted(struct zone *zone)
> static unsigned int fragmentation_score_node(pg_data_t *pgdat)
> {
> unsigned int score = 0;
> + struct zone *zone;
> int zoneid;
>
> - for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) {
> - struct zone *zone;
> -
> - zone = &pgdat->node_zones[zoneid];
> - if (!populated_zone(zone))
> - continue;
> + for_each_populated_zone_pgdat(zone, pgdat)
> score += fragmentation_score_zone_weighted(zone);
> - }
>
> return score;
> }

\
 
 \ /
  Last update: 2024-05-27 15:49    [W:0.098 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site