diff mbox series

[v2] mm/vmstat: Move pgdemote_* to per-node stats

Message ID 20231103031450.1456523-1-lizhijian@fujitsu.com (mailing list archive)
State New
Headers show
Series [v2] mm/vmstat: Move pgdemote_* to per-node stats | expand

Commit Message

Li Zhijian Nov. 3, 2023, 3:14 a.m. UTC
Demotion will migrate pages across nodes. Previously, only the global
demotion statistics were accounted for. Changed them to per-node
statistics, making it easier to observe where demotion occurs on each
node.

This will help to identify which nodes are under pressure.

This patch also make pgdemote_* behind CONFIG_NUMA_BALANCING, since
demotion is not available for !CONFIG_NUMA_BALANCING

With this patch, here is a sample where node0 node1 are DRAM,
node3 is PMEM:
Global stats:
$ grep demote /proc/vmstat
pgdemote_kswapd 254288
pgdemote_direct 113497
pgdemote_khugepaged 0

Per-node stats:
$ grep demote /sys/devices/system/node/node0/vmstat # demotion source
pgdemote_kswapd 68454
pgdemote_direct 83431
pgdemote_khugepaged 0
$ grep demote /sys/devices/system/node/node1/vmstat # demotion source
pgdemote_kswapd 185834
pgdemote_direct 30066
pgdemote_khugepaged 0
$ grep demote /sys/devices/system/node/node3/vmstat # demotion target
pgdemote_kswapd 0
pgdemote_direct 0
pgdemote_khugepaged 0

Reported-by: kernel test robot <lkp@intel.com> # compling errors
Closes: https://lore.kernel.org/oe-kbuild-all/202311030137.Vu2ki6zm-lkp@intel.com/
Acked-by: "Huang, Ying" <ying.huang@intel.com>
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>

---
V2: split it as a separate patch from previous patch set.
    account them to the source node instead destination and add Acked-by # Huang, Ying
---
 include/linux/mmzone.h        |  4 ++++
 include/linux/vm_event_item.h |  3 ---
 mm/vmscan.c                   | 12 ++++++++----
 mm/vmstat.c                   |  6 +++---
 4 files changed, 15 insertions(+), 10 deletions(-)

Comments

Li Zhijian Dec. 28, 2023, 3:52 a.m. UTC | #1
Andrew,



On 03/11/2023 11:14, Li Zhijian wrote:
> Demotion will migrate pages across nodes. Previously, only the global
> demotion statistics were accounted for. Changed them to per-node
> statistics, making it easier to observe where demotion occurs on each
> node.
> 
> This will help to identify which nodes are under pressure.
> 
> This patch also make pgdemote_* behind CONFIG_NUMA_BALANCING, since
> demotion is not available for !CONFIG_NUMA_BALANCING

I just realized that moving pgdemote_* behind CONFIG_NUMA_BALANCING was wrong.
Demotion works well without CONFIG_NUMA_BALANCING.

Since this patch was already in the mm-stable branch, is it possible to
replace this patch from mm-stable or post a fixup for this


Thanks
Zhijian


> 
> With this patch, here is a sample where node0 node1 are DRAM,
> node3 is PMEM:
> Global stats:
> $ grep demote /proc/vmstat
> pgdemote_kswapd 254288
> pgdemote_direct 113497
> pgdemote_khugepaged 0
> 
> Per-node stats:
> $ grep demote /sys/devices/system/node/node0/vmstat # demotion source
> pgdemote_kswapd 68454
> pgdemote_direct 83431
> pgdemote_khugepaged 0
> $ grep demote /sys/devices/system/node/node1/vmstat # demotion source
> pgdemote_kswapd 185834
> pgdemote_direct 30066
> pgdemote_khugepaged 0
> $ grep demote /sys/devices/system/node/node3/vmstat # demotion target
> pgdemote_kswapd 0
> pgdemote_direct 0
> pgdemote_khugepaged 0
> 
> Reported-by: kernel test robot <lkp@intel.com> # compling errors
> Closes: https://lore.kernel.org/oe-kbuild-all/202311030137.Vu2ki6zm-lkp@intel.com/
> Acked-by: "Huang, Ying" <ying.huang@intel.com>
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> 
> ---
> V2: split it as a separate patch from previous patch set.
>      account them to the source node instead destination and add Acked-by # Huang, Ying
> ---
>   include/linux/mmzone.h        |  4 ++++
>   include/linux/vm_event_item.h |  3 ---
>   mm/vmscan.c                   | 12 ++++++++----
>   mm/vmstat.c                   |  6 +++---
>   4 files changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 4106fbc5b4b3..ad0309eea850 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -206,6 +206,10 @@ enum node_stat_item {
>   #ifdef CONFIG_NUMA_BALANCING
>   	PGPROMOTE_SUCCESS,	/* promote successfully */
>   	PGPROMOTE_CANDIDATE,	/* candidate pages to promote */
> +	/* PGDEMOTE_*: pages demoted */
> +	PGDEMOTE_KSWAPD,
> +	PGDEMOTE_DIRECT,
> +	PGDEMOTE_KHUGEPAGED,
>   #endif
>   	NR_VM_NODE_STAT_ITEMS
>   };
> diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
> index 8abfa1240040..d1b847502f09 100644
> --- a/include/linux/vm_event_item.h
> +++ b/include/linux/vm_event_item.h
> @@ -41,9 +41,6 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
>   		PGSTEAL_KSWAPD,
>   		PGSTEAL_DIRECT,
>   		PGSTEAL_KHUGEPAGED,
> -		PGDEMOTE_KSWAPD,
> -		PGDEMOTE_DIRECT,
> -		PGDEMOTE_KHUGEPAGED,
>   		PGSCAN_KSWAPD,
>   		PGSCAN_DIRECT,
>   		PGSCAN_KHUGEPAGED,
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 6f13394b112e..cc70dcefc60a 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1110,12 +1110,14 @@ void drop_slab(void)
>   
>   static int reclaimer_offset(void)
>   {
> +#ifdef CONFIG_NUMA_BALANCING
>   	BUILD_BUG_ON(PGSTEAL_DIRECT - PGSTEAL_KSWAPD !=
>   			PGDEMOTE_DIRECT - PGDEMOTE_KSWAPD);
> -	BUILD_BUG_ON(PGSTEAL_DIRECT - PGSTEAL_KSWAPD !=
> -			PGSCAN_DIRECT - PGSCAN_KSWAPD);
>   	BUILD_BUG_ON(PGSTEAL_KHUGEPAGED - PGSTEAL_KSWAPD !=
>   			PGDEMOTE_KHUGEPAGED - PGDEMOTE_KSWAPD);
> +#endif
> +	BUILD_BUG_ON(PGSTEAL_DIRECT - PGSTEAL_KSWAPD !=
> +			PGSCAN_DIRECT - PGSCAN_KSWAPD);
>   	BUILD_BUG_ON(PGSTEAL_KHUGEPAGED - PGSTEAL_KSWAPD !=
>   			PGSCAN_KHUGEPAGED - PGSCAN_KSWAPD);
>   
> @@ -1677,8 +1679,10 @@ static unsigned int demote_folio_list(struct list_head *demote_folios,
>   	migrate_pages(demote_folios, alloc_demote_folio, NULL,
>   		      (unsigned long)&mtc, MIGRATE_ASYNC, MR_DEMOTION,
>   		      &nr_succeeded);
> -
> -	__count_vm_events(PGDEMOTE_KSWAPD + reclaimer_offset(), nr_succeeded);
> +#ifdef CONFIG_NUMA_BALANCING
> +	mod_node_page_state(pgdat, PGDEMOTE_KSWAPD + reclaimer_offset(),
> +			    nr_succeeded);
> +#endif
>   
>   	return nr_succeeded;
>   }
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> index 00e81e99c6ee..f141c48c39e4 100644
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -1244,6 +1244,9 @@ const char * const vmstat_text[] = {
>   #ifdef CONFIG_NUMA_BALANCING
>   	"pgpromote_success",
>   	"pgpromote_candidate",
> +	"pgdemote_kswapd",
> +	"pgdemote_direct",
> +	"pgdemote_khugepaged",
>   #endif
>   
>   	/* enum writeback_stat_item counters */
> @@ -1275,9 +1278,6 @@ const char * const vmstat_text[] = {
>   	"pgsteal_kswapd",
>   	"pgsteal_direct",
>   	"pgsteal_khugepaged",
> -	"pgdemote_kswapd",
> -	"pgdemote_direct",
> -	"pgdemote_khugepaged",
>   	"pgscan_kswapd",
>   	"pgscan_direct",
>   	"pgscan_khugepaged",
Andrew Morton Dec. 28, 2023, 6:22 p.m. UTC | #2
On Thu, 28 Dec 2023 03:52:25 +0000 "Zhijian Li (Fujitsu)" <lizhijian@fujitsu.com> wrote:

> > This patch also make pgdemote_* behind CONFIG_NUMA_BALANCING, since
> > demotion is not available for !CONFIG_NUMA_BALANCING
> 
> I just realized that moving pgdemote_* behind CONFIG_NUMA_BALANCING was wrong.
> Demotion works well without CONFIG_NUMA_BALANCING.
> 
> Since this patch was already in the mm-stable branch, is it possible to
> replace this patch from mm-stable or post a fixup for this

A fixup would be preferred, please.  With the appropriate Fixes:
diff mbox series

Patch

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 4106fbc5b4b3..ad0309eea850 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -206,6 +206,10 @@  enum node_stat_item {
 #ifdef CONFIG_NUMA_BALANCING
 	PGPROMOTE_SUCCESS,	/* promote successfully */
 	PGPROMOTE_CANDIDATE,	/* candidate pages to promote */
+	/* PGDEMOTE_*: pages demoted */
+	PGDEMOTE_KSWAPD,
+	PGDEMOTE_DIRECT,
+	PGDEMOTE_KHUGEPAGED,
 #endif
 	NR_VM_NODE_STAT_ITEMS
 };
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 8abfa1240040..d1b847502f09 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -41,9 +41,6 @@  enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 		PGSTEAL_KSWAPD,
 		PGSTEAL_DIRECT,
 		PGSTEAL_KHUGEPAGED,
-		PGDEMOTE_KSWAPD,
-		PGDEMOTE_DIRECT,
-		PGDEMOTE_KHUGEPAGED,
 		PGSCAN_KSWAPD,
 		PGSCAN_DIRECT,
 		PGSCAN_KHUGEPAGED,
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 6f13394b112e..cc70dcefc60a 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1110,12 +1110,14 @@  void drop_slab(void)
 
 static int reclaimer_offset(void)
 {
+#ifdef CONFIG_NUMA_BALANCING
 	BUILD_BUG_ON(PGSTEAL_DIRECT - PGSTEAL_KSWAPD !=
 			PGDEMOTE_DIRECT - PGDEMOTE_KSWAPD);
-	BUILD_BUG_ON(PGSTEAL_DIRECT - PGSTEAL_KSWAPD !=
-			PGSCAN_DIRECT - PGSCAN_KSWAPD);
 	BUILD_BUG_ON(PGSTEAL_KHUGEPAGED - PGSTEAL_KSWAPD !=
 			PGDEMOTE_KHUGEPAGED - PGDEMOTE_KSWAPD);
+#endif
+	BUILD_BUG_ON(PGSTEAL_DIRECT - PGSTEAL_KSWAPD !=
+			PGSCAN_DIRECT - PGSCAN_KSWAPD);
 	BUILD_BUG_ON(PGSTEAL_KHUGEPAGED - PGSTEAL_KSWAPD !=
 			PGSCAN_KHUGEPAGED - PGSCAN_KSWAPD);
 
@@ -1677,8 +1679,10 @@  static unsigned int demote_folio_list(struct list_head *demote_folios,
 	migrate_pages(demote_folios, alloc_demote_folio, NULL,
 		      (unsigned long)&mtc, MIGRATE_ASYNC, MR_DEMOTION,
 		      &nr_succeeded);
-
-	__count_vm_events(PGDEMOTE_KSWAPD + reclaimer_offset(), nr_succeeded);
+#ifdef CONFIG_NUMA_BALANCING
+	mod_node_page_state(pgdat, PGDEMOTE_KSWAPD + reclaimer_offset(),
+			    nr_succeeded);
+#endif
 
 	return nr_succeeded;
 }
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 00e81e99c6ee..f141c48c39e4 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1244,6 +1244,9 @@  const char * const vmstat_text[] = {
 #ifdef CONFIG_NUMA_BALANCING
 	"pgpromote_success",
 	"pgpromote_candidate",
+	"pgdemote_kswapd",
+	"pgdemote_direct",
+	"pgdemote_khugepaged",
 #endif
 
 	/* enum writeback_stat_item counters */
@@ -1275,9 +1278,6 @@  const char * const vmstat_text[] = {
 	"pgsteal_kswapd",
 	"pgsteal_direct",
 	"pgsteal_khugepaged",
-	"pgdemote_kswapd",
-	"pgdemote_direct",
-	"pgdemote_khugepaged",
 	"pgscan_kswapd",
 	"pgscan_direct",
 	"pgscan_khugepaged",