mm: random cleanups
Subsystems (4)
cover mm: random cleanups
Here's a few random minor cleanups I spotted while reviewing a few mm/*.c files. No functional changes.
Luis Chamberlain (3):
mm/show_mem: simplify ifdef on si_meminfo_node() mm/compaction: add and use for_each_populated_zone_pgdat() helper mm/vmstat: simplfy extfrag_show_print with fragmentation_index()
include/linux/mmzone.h | 8 ++++++++ mm/compaction.c | 9 ++------- mm/show_mem.c | 5 +---- mm/vmstat.c | 11 +++++------ 4 files changed, 16 insertions(+), 17 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 mm/show_mem: simplify ifdef on si_meminfo_node()
There is an ifdef where the same exact values are used at the end, so remove the else and keep the same values for both conditions.
--- mm/show_mem.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
mm/show_mem.c +1 -4
@@ -108,12 +108,9 @@ void si_meminfo_node(struct sysinfo *val, int nid) free_highpages +=zone_page_state (zone,NR_FREE_PAGES ); } } +#endif val->totalhigh = managed_highpages; val->freehigh = free_highpages; -#else - val->totalhigh = managed_highpages; - val->freehigh = free_highpages; -#endif val->mem_unit =PAGE_SIZE ; }#endif
Signature · 1 line
2.43.0
Re: [PATCH 1/3] mm/show_mem: simplify ifdef on si_meminfo_node()
Quoted 17 lines · Luis Chamberlain
There is an ifdef where the same exact values are used at the end, so remove the else and keep the same values for both conditions.
Signed-off-by Luis Chamberlain <[email protected]>--- mm/show_mem.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)mm/show_mem.c +0
-0@@ -108,12 +108,9 @@ void si_meminfo_node(struct sysinfo *val, int nid) free_highpages +=zone_page_state (zone,NR_FREE_PAGES ); } }
mm/show_mem.c void si_meminfo_node(struct sysinfo *val, int nid) · line 116
Quoted 10 lines
mm/show_mem.c +1
-4+#endif val->totalhigh = managed_highpages; val->freehigh = free_highpages; -#else - val->totalhigh = managed_highpages; - val->freehigh = free_highpages; -#endif val->mem_unit = PAGE_SIZE; }#endif
More cleanup?
mm/show_mem.c +1 -6
@@ -94,26 +94,21 @@ void si_meminfo_node(struct sysinfo *val, int nid)unsigned long free_highpages =0 ;pg_data_t *pgdat =NODE_DATA (nid); -for (zone_type =0 ; zone_type <MAX_NR_ZONES ; zone_type++) - managed_pages +=zone_managed_pages (&pgdat->node_zones[zone_type]); - val->totalram = managed_pages; - val->sharedram =node_page_state (pgdat,NR_SHMEM ); - val->freeram =sum_zone_node_page_state (nid,NR_FREE_PAGES ); -#ifdef CONFIG_HIGHMEM for (zone_type =0 ; zone_type <MAX_NR_ZONES ; zone_type++) {struct zone *zone = &pgdat->node_zones[zone_type]; + managed_pages +=zone_managed_pages (zone);if (is_highmem (zone)) { managed_highpages +=zone_managed_pages (zone); free_highpages += zone_page_state(zone,
NR_FREE_PAGES);
}
}
+
+ val->totalram = managed_pages;
+ val->sharedram = node_page_state(pgdat, NR_SHMEM);
+ val->freeram = sum_zone_node_page_state(nid, NR_FREE_PAGES);
val->totalhigh = managed_highpages;
val->freehigh = free_highpages;-#else
- val->totalhigh = managed_highpages;
- val->freehigh = free_highpages;
-#endif
val->mem_unit = PAGE_SIZE;
}
PATCH 2/3 mm/compaction: add and use for_each_populated_zone_pgdat() helper
In reply to Luis ChamberlainWe 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.
--- include/linux/mmzone.h | 8 ++++++++ mm/compaction.c | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-)
include/linux/mmzone.h +8 -0
@@ -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 + static inline struct zone *zonelist_zone(struct zoneref *zoneref) {return zoneref->zone;
mm/compaction.c +2 -7
@@ -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; }
Signature · 1 line
2.43.0
Baolin Wang
reviewerRe: [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper
Quoted 14 lines · Luis Chamberlain
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 <[email protected]>--- include/linux/mmzone.h | 8 ++++++++ mm/compaction.c | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-)include/linux/mmzone.h +0
-0
include/linux/mmzone.h extern struct zone *next_zone(struct zone *zone); · line 1606
Quoted 10 lines
include/linux/mmzone.h +7
-0@@ -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.
Quoted 26 lines
include/linux/mmzone.h +0
-0static inline struct zone *zonelist_zone (struct zoneref *zoneref) {return zoneref->zone;mm/compaction.c +2
-7@@ -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; }
Re: [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper
Quoted 22 lines · Baolin Wang
Quoted 19 lines · Luis Chamberlain
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 <[email protected]>--- include/linux/mmzone.h | 8 ++++++++ mm/compaction.c | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-)include/linux/mmzone.h +3
-0@@ -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; \
Quoted 8 lines
include/linux/mmzone.h extern struct zone *next_zone(struct zone *zone); · line 1605
Quoted 4 lines
include/linux/mmzone.h +4
-0+ 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:
include/linux/mmzone.h +2 -1
@@ -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
mm/compaction.c +0 -1
@@ -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);
mm/mmzone.c +12 -0
@@ -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
Baolin Wang
reviewerRe: [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper
Quoted 72 lines · Luis Chamberlain
Quoted 22 lines · Baolin Wang
Quoted 19 lines · Luis Chamberlain
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 <[email protected]>--- include/linux/mmzone.h | 8 ++++++++ mm/compaction.c | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-)include/linux/mmzone.h +3
-0@@ -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; \Quoted 8 lines
include/linux/mmzone.h extern struct zone *next_zone(struct zone *zone); · line 1605
Quoted 4 lines
include/linux/mmzone.h +4
-0+ 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:
include/linux/mmzone.h +2
-1@@ -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 */ \ elsemm/compaction.c +0
-1@@ -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);mm/mmzone.c +0
-0
mm/mmzone.c struct zone *next_zone(struct zone *zone) · line 52
Quoted 10 lines
mm/mmzone.c +7
-0@@ -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 ;
Seems unnecessary, you already accessed them before calling next_zone_pgdat(). Otherwise, looks good to me.
Quoted 8 lines
mm/mmzone.c +5
-0+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
Re: [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper
In reply to Luis ChamberlainQuoted 32 lines · Luis Chamberlain
Quoted 22 lines · Baolin Wang
Quoted 19 lines · Luis Chamberlain
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 <[email protected]>--- include/linux/mmzone.h | 8 ++++++++ mm/compaction.c | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-)include/linux/mmzone.h +3
-0@@ -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; \Quoted 8 lines
include/linux/mmzone.h extern struct zone *next_zone(struct zone *zone); · line 1605
Quoted 4 lines
include/linux/mmzone.h +4
-0+ 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.
Quoted 1 line
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.
Quoted 56 lines
include/linux/mmzone.h +2
-1@@ -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 */ \ elsemm/compaction.c +0
-1@@ -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);mm/mmzone.c +12
-0@@ -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
Re: [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper
Quoted 33 lines · Vlastimil Babka
Quoted 32 lines · Luis Chamberlain
Quoted 30 lines · Baolin Wang
Quoted 14 lines · Luis Chamberlain
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 <[email protected]>--- include/linux/mmzone.h | 8 ++++++++ mm/compaction.c | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-)include/linux/mmzone.h +0
-0include/linux/mmzone.h extern struct zone *next_zone(struct zone *zone); · line 1605
Quoted 9 lines
include/linux/mmzone.h +7
-0@@ -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 */ \ + elseI 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.
Quoted 4 lines
Quoted 1 line
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?
Sure.
Quoted 3 lines
Also maybe you could find more users if you created just a
for_each_zone_pgdat()and left thepopulated_zone()in the user? Otherwise it's quite a specific helper with just one user.
Indeed, this was the only immediately clear user for_each_populated_zone_pgdat() which stood out, but I'll look more closely. I added this helper because in an RFC patch I had another use case:
https://lkml.kernel.org/r/[email protected]
Granted this is just an RFC. So happy to drop this if we don't have other users
Luis
kernel test robot
build botRe: [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper
In reply to Luis Chamberlainkernel test robot noticed the following build warnings:
Hi Luis,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Luis-Chamberlain/mm-show_mem-simplify-ifdef-on-si_meminfo_node/20240314-085917 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20240314005436.2962962-3-mcgrof%40kernel.org patch subject: [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper config: openrisc-defconfig (https://download.01.org/0day-ci/archive/20240314/[email protected]/config) compiler: or1k-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240314/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
mm/compaction.c: In function 'fragmentation_score_node':
>> mm/compaction.c:2252:13: warning: unused variable 'zoneid' [-Wunused-variable]
2252 | int zoneid;
| ^~~~~~vim +/zoneid +2252 mm/compaction.c
2240
2241 /*
2242 * The per-node proactive (background) compaction process is started by its
2243 * corresponding kcompactd thread when the node's fragmentation score
2244 * exceeds the high threshold. The compaction process remains active till
2245 * the node's score falls below the low threshold, or one of the back-off
2246 * conditions is met.
2247 */
2248 static unsigned int fragmentation_score_node(pg_data_t *pgdat)
2249 {
2250 unsigned int score = 0;
2251 struct zone *zone;
> 2252 int zoneid;
2253
2254 for_each_populated_zone_pgdat(zone, pgdat)
2255 score += fragmentation_score_zone_weighted(zone);
2256
2257 return score;
2258 }
2259
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 3/3 mm/vmstat: simplfy extfrag_show_print with fragmentation_index()
In reply to Luis Chamberlainfragmentation_index() already uses the stack for the struct contig_page_info, so just use that and enhance the documentation for fragmentation_index().
--- mm/vmstat.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
mm/vmstat.c +5 -6
@@ -1129,7 +1129,10 @@ unsigned int extfrag_for_order(struct zone *zone, unsigned int order) info.free_pages); } -/* Same as __fragmentation index but allocs contig_page_info on stack */ +/* +* Same as __fragmentation index but allocs contig_page_info on stack, +* useful when walking a zone as interrupts are disabled. +*/ int fragmentation_index (struct zone *zone,unsigned int order) {struct contig_page_info info;
@@ -2227,15 +2230,11 @@ static void extfrag_show_print(struct seq_file *m,unsigned int order;int index; -/* Alloc on stack as interrupts are disabled for zone walk */ -struct contig_page_info info; -seq_printf (m,"Node %d, zone %8s " , pgdat->node_id, zone->name);for (order =0 ; order <NR_PAGE_ORDERS ; ++order) { -fill_contig_page_info (zone, order, &info); - index =__fragmentation_index (order, &info); + index =fragmentation_index (zone, order);seq_printf (m,"%2d.%03d " , index /1000 , index %1000 ); }
Signature · 1 line
2.43.0
Re: [PATCH 3/3] mm/vmstat: simplfy extfrag_show_print with fragmentation_index()
Quoted 4 lines · Luis Chamberlain
fragmentation_index()already uses the stack for the structcontig_page_info, so just use that and enhance the documentation forfragmentation_index().Signed-off-by Luis Chamberlain <[email protected]>
Quoted 37 lines
--- mm/vmstat.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)mm/vmstat.c +5
-6@@ -1129,7 +1129,10 @@ unsigned int extfrag_for_order(struct zone *zone, unsigned int order) info.free_pages); } -/* Same as __fragmentation index but allocs contig_page_info on stack */ +/* +* Same as __fragmentation index but allocs contig_page_info on stack, +* useful when walking a zone as interrupts are disabled. +*/ int fragmentation_index (struct zone *zone,unsigned int order) {struct contig_page_info info;@@ -2227,15 +2230,11 @@ static void extfrag_show_print(struct seq_file *m,unsigned int order;int index; -/* Alloc on stack as interrupts are disabled for zone walk */ -struct contig_page_info info; -seq_printf (m,"Node %d, zone %8s " , pgdat->node_id, zone->name);for (order =0 ; order <NR_PAGE_ORDERS ; ++order) { -fill_contig_page_info (zone, order, &info); - index =__fragmentation_index (order, &info); + index =fragmentation_index (zone, order);seq_printf (m,"%2d.%03d " , index /1000 , index %1000 ); }
Re: [PATCH 3/3] mm/vmstat: simplfy extfrag_show_print with fragmentation_index()
In reply to Luis ChamberlainQuoted 3 lines · Luis Chamberlain
fragmentation_index()already uses the stack for the structcontig_page_info, so just use that and enhance the documentation forfragmentation_index().
Quoted 1 line
Signed-off-by Luis Chamberlain <[email protected]>