mm, pcp: add high order page info in /proc/zoneinfo
Subsystems (4)
cover mm, pcp: add high order page info in /proc/zoneinfo
From: Xin Hao <[email protected]>
With /proc/zoneinfo we can simply get the number of pages used each cpu, but we can't get more detailed information about the distribution of those pages, such as the count of high order pages, through these patches, we can know the usage of each order page in detail, which will be helpful for us to analyze the pcp memory usage of application on the related cpus.
By the way, on my intel 32 cores machine, i found that the 'struct per_cpu_pages' size increases 64 bytes, it seems like a bad news, i did some tests like stress-ng, but it did not see any performance degradation, and maybe use 'pcp->list' is also a possible way to get high order pages count, but it will increase the /proc/zoneinfo query time, so any meaningful suggestions are welcome!
Xin Hao (2):
mm, pcp: rename pcp->count to pcp->total_count mm, pcp: add more detail info about high order page count
include/linux/mmzone.h | 3 ++- mm/page_alloc.c | 46 +++++++++++++++++++++++------------------- mm/show_mem.c | 6 +++--- mm/vmstat.c | 22 ++++++++++++-------- 4 files changed, 44 insertions(+), 33 deletions(-)
Signature · 1 line
2.31.1
RFC PATCH 1/2 mm, pcp: rename pcp->count to pcp->total_count
From: Xin Hao <[email protected]>
Just a rename for avoiding name conflicts in the next patch
--- include/linux/mmzone.h | 2 +- mm/page_alloc.c | 42 +++++++++++++++++++++--------------------- mm/show_mem.c | 6 +++--- mm/vmstat.c | 6 +++--- 4 files changed, 28 insertions(+), 28 deletions(-)
include/linux/mmzone.h +1 -1
@@ -683,7 +683,7 @@ enum zone_watermarks {struct per_cpu_pages {spinlock_t lock;/* Protects lists field */ -int count;/* number of pages in the list */ +int total_count;/* total number of pages in the list */ int high;/* high watermark, emptying needed */ int high_min;/* min high watermark */ int high_max;/* max high watermark */
mm/page_alloc.c +21 -21
154 lines not on this page · raw message
mm/show_mem.c +3 -3
@@ -197,7 +197,7 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_zcontinue ;for_each_online_cpu (cpu) - free_pcp +=per_cpu_ptr (zone->per_cpu_pageset, cpu)->count; + free_pcp +=per_cpu_ptr (zone->per_cpu_pageset, cpu)->total_count; } printk("active_anon:%lu inactive_anon:%lu isolated_anon:%lu\n"
@@ -299,7 +299,7 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_z free_pcp =0 ;for_each_online_cpu (cpu) - free_pcp +=per_cpu_ptr (zone->per_cpu_pageset, cpu)->count; + free_pcp +=per_cpu_ptr (zone->per_cpu_pageset, cpu)->total_count;show_node (zone); printk(KERN_CONT
@@ -342,7 +342,7 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_zK (zone_page_state (zone,NR_MLOCK )),K (zone_page_state (zone,NR_BOUNCE )),K (free_pcp), -K (this_cpu_read (zone->per_cpu_pageset->count)), +K (this_cpu_read (zone->per_cpu_pageset->total_count)), K(zone_page_state(zone, NR_FREE_CMA_PAGES)));printk ("lowmem_reserve[]:" );for (i =0 ; i <MAX_NR_ZONES ; i++)
mm/vmstat.c +3 -3
@@ -846,7 +846,7 @@ static int refresh_cpu_vm_stats(bool do_pagesets)* if not then there is nothing to expire. */ if (!__this_cpu_read (pcp->expire) || - !__this_cpu_read (pcp->count)) + !__this_cpu_read (pcp->total_count))continue ;/*
@@ -862,7 +862,7 @@ static int refresh_cpu_vm_stats(bool do_pagesets)continue ; } -if (__this_cpu_read (pcp->count)) { +if (__this_cpu_read (pcp->total_count)) {drain_zone_pages (zone,this_cpu_ptr (pcp)); changes++; }
@@ -1745,7 +1745,7 @@ static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,"\n high: %i" "\n batch: %i" , i, - pcp->count, + pcp->total_count, pcp->high, pcp->batch);#ifdef CONFIG_SMP
Signature · 1 line
2.31.1
RFC PATCH 2/2 mm, pcp: add more detail info about high order page count
In reply to Vern HaoFrom: Xin Hao <[email protected]>
With this patch, we can see the distribution of pages of different orders on each cpu, just like below.
#cat /proc/zoneinfo
....
cpu: 2
total_count: 14286
order0 : 1260
order1 : 13
order2 : 42
order3 : 4
order4 : 0
order5 : 0
order6 : 0
order7 : 0
order8 : 0
order9 : 25
order10: 0
order11: 0
order12: 0
high: 14541
batch: 63--- include/linux/mmzone.h | 1 + mm/page_alloc.c | 4 ++++ mm/vmstat.c | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-)
include/linux/mmzone.h +1 -0
@@ -684,6 +684,7 @@ enum zone_watermarks {struct per_cpu_pages {spinlock_t lock;/* Protects lists field */ int total_count;/* total number of pages in the list */ +int count[NR_PCP_LISTS ];/* per-order page counts */ int high;/* high watermark, emptying needed */ int high_min;/* min high watermark */ int high_max;/* max high watermark */
mm/page_alloc.c +4 -0
@@ -1228,6 +1228,7 @@ static void free_pcppages_bulk(struct zone *zone, int count,list_del (&page->pcp_list); count -= nr_pages; pcp->total_count -= nr_pages; + pcp->count[order] -=1 ;/* MIGRATE_ISOLATE page should not go to pcplists */ VM_BUG_ON_PAGE (is_migrate_isolate (mt), page);
@@ -2478,6 +2479,7 @@ static void free_unref_page_commit(struct zone *zone, struct per_cpu_pages *pcp, pindex =order_to_pindex (migratetype, order);list_add (&page->pcp_list, &pcp->lists[pindex]); pcp->total_count +=1 << order; + pcp->count[order] +=1 ; batch =READ_ONCE (pcp->batch);/*
@@ -2858,6 +2860,7 @@ struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order, migratetype, alloc_flags); pcp->total_count += alloced << order; + pcp->count[order] += alloced;if (unlikely (list_empty (list)))return NULL ; }
@@ -2865,6 +2868,7 @@ struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order, page = list_first_entry(list, struct page, pcp_list);list_del (&page->pcp_list); pcp->total_count -=1 << order; + pcp->count[order] -=1 ; }while (check_new_pages (page, order));return page;
mm/vmstat.c +12 -6
@@ -1735,19 +1735,25 @@ static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,seq_printf (m,"\n pagesets" );for_each_online_cpu (i) { +int j;struct per_cpu_pages *pcp;struct per_cpu_zonestat __maybe_unused *pzstats; pcp =per_cpu_ptr (zone->per_cpu_pageset, i);seq_printf (m,"\n cpu: %i" -"\n count: %i" -"\n high: %i" -"\n batch: %i" , +"\n total_count: %i" , i, - pcp->total_count, - pcp->high, - pcp->batch); + pcp->total_count); +for (j =0 ; j <NR_PCP_LISTS ; j++) +seq_printf (m, +"\n order%-2i: %-3i" , + j, pcp->count[j]); +seq_printf (m, +"\n high: %i" +"\n batch: %i" , + pcp->high, + pcp->batch);#ifdef CONFIG_SMP pzstats =per_cpu_ptr (zone->per_cpu_zonestats, i); seq_printf(m, "\n vm stats threshold: %d",
Signature · 1 line
2.31.1
Re: [PATCH RFC v1 2/2] mm, pcp: add more detail info about high order page count
Quoted 8 lines · Vern Hao
From: Xin Hao <[email protected]>
With this patch, we can see the distribution of pages of different orders on each cpu, just like below.
#cat /proc/zoneinfo .... cpu: 2 total_count: 14286
I don't think we should be changing the naming of the field if there are existing users that parse /proc/zoneinfo.
Quoted 112 lines
order0 : 1260 order1 : 13 order2 : 42 order3 : 4 order4 : 0 order5 : 0 order6 : 0 order7 : 0 order8 : 0 order9 : 25 order10: 0 order11: 0 order12: 0 high: 14541 batch: 63Signed-off-by Xin Hao <[email protected]>--- include/linux/mmzone.h | 1 + mm/page_alloc.c | 4 ++++ mm/vmstat.c | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-)include/linux/mmzone.h +1
-0@@ -684,6 +684,7 @@ enum zone_watermarks {struct per_cpu_pages {spinlock_t lock;/* Protects lists field */ int total_count;/* total number of pages in the list */ +int count[NR_PCP_LISTS ];/* per-order page counts */ int high;/* high watermark, emptying needed */ int high_min;/* min high watermark */ int high_max;/* max high watermark */ mm/page_alloc.c +4
-0@@ -1228,6 +1228,7 @@ static void free_pcppages_bulk(struct zone *zone, int count,list_del (&page->pcp_list); count -= nr_pages; pcp->total_count -= nr_pages; + pcp->count[order] -=1 ;/* MIGRATE_ISOLATE page should not go to pcplists */ VM_BUG_ON_PAGE (is_migrate_isolate (mt), page);@@ -2478,6 +2479,7 @@ static void free_unref_page_commit(struct zone *zone, struct per_cpu_pages *pcp, pindex =order_to_pindex (migratetype, order);list_add (&page->pcp_list, &pcp->lists[pindex]); pcp->total_count +=1 << order; + pcp->count[order] +=1 ; batch =READ_ONCE (pcp->batch);/* @@ -2858,6 +2860,7 @@ struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order, migratetype, alloc_flags); pcp->total_count += alloced << order; + pcp->count[order] += alloced;if (unlikely (list_empty (list)))return NULL ; }@@ -2865,6 +2868,7 @@ struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order, page = list_first_entry(list, struct page, pcp_list);list_del (&page->pcp_list); pcp->total_count -=1 << order; + pcp->count[order] -=1 ; }while (check_new_pages (page, order));return page;mm/vmstat.c +12
-6@@ -1735,19 +1735,25 @@ static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,seq_printf (m,"\n pagesets" );for_each_online_cpu (i) { +int j;struct per_cpu_pages *pcp;struct per_cpu_zonestat __maybe_unused *pzstats; pcp =per_cpu_ptr (zone->per_cpu_pageset, i);seq_printf (m,"\n cpu: %i" -"\n count: %i" -"\n high: %i" -"\n batch: %i" , +"\n total_count: %i" , i, - pcp->total_count, - pcp->high, - pcp->batch); + pcp->total_count); +for (j =0 ; j <NR_PCP_LISTS ; j++) +seq_printf (m, +"\n order%-2i: %-3i" , + j, pcp->count[j]); +seq_printf (m, +"\n high: %i" +"\n batch: %i" , + pcp->high, + pcp->batch);#ifdef CONFIG_SMP pzstats =per_cpu_ptr (zone->per_cpu_zonestats, i); seq_printf(m, "\n vm stats threshold: %d",Signature · 1 line
2.31.1
Re: [PATCH RFC v1 2/2] mm, pcp: add more detail info about high order page count
In reply to Vern HaoQuoted 24 lines · Vern Hao
From: Xin Hao <[email protected]>
With this patch, we can see the distribution of pages of different orders on each cpu, just like below.
#cat /proc/zoneinfo .... cpu: 2 total_count: 14286 order0 : 1260 order1 : 13 order2 : 42 order3 : 4 order4 : 0 order5 : 0 order6 : 0 order7 : 0 order8 : 0 order9 : 25 order10: 0 order11: 0 order12: 0 high: 14541 batch: 63
Quoted 1 line
Signed-off-by Xin Hao <[email protected]>
I am not a major fan because increasing the size of a per-cpu structure for debugging purposes incurs a cost for everyone while only a tiny minority may care. There is a mild risk it would break existing parsers of that file although maybe that's not a big deal. However, the same information could be extracted by locking the pcp structures and counting the items per list. It would increase the cost of reading zoneinfo but it's unlikely the file is read at high frequency. If that was a concern, a separate proc file could be used. Finally, the same information likely can be extracted via a systemtap script, a BPF script (if it can get to the right symbols and locking, I didn't check) or via a kernel probe. Even with that information, it's not clear what meaningful action a user can take, so this is a developer-only feature really with a cost incurred for everybody.
Signature · 2 lines
Mel Gorman SUSE Labs
Quoted 9 lines · Vern Hao
From: Xin Hao <[email protected]>
With
/proc/zoneinfowe can simply get the number of pages used each cpu, but we can't get more detailed information about the distribution of those pages, such as the count of high order pages, through these patches, we can know the usage of each order page in detail, which will be helpful for us to analyze the pcp memory usage of application on the related cpus.
Could you elaborate on the use case for this?
I'm not exactly sure what is meant by analyzing the pcp memory usage of an application; this would be a property of page allocations and freeing on individual cpus for orders that have pcp lists. That's traditionally not a property of an individual application.
Quoted 22 lines
By the way, on my intel 32 cores machine, i found that the 'struct
per_cpu_pages' size increases 64 bytes, it seems like a bad news, i did some tests like stress-ng, but it did not see any performance degradation, and maybe use 'pcp->list' is also a possible way to get high order pages count, but it will increase the/proc/zoneinfoquery time, so any meaningful suggestions are welcome!Xin Hao (2):
mm, pcp: renamepcp->counttopcp->total_countmm, pcp: add more detail info about high order page countinclude/linux/mmzone.h | 3 ++- mm/page_alloc.c | 46 +++++++++++++++++++++++------------------- mm/show_mem.c | 6 +++--- mm/vmstat.c | 22 ++++++++++++-------- 4 files changed, 44 insertions(+), 33 deletions(-)Signature · 1 line
2.31.1