]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: memory-tiering: fix PGPROMOTE_CANDIDATE counting
authorRuan Shiyang <ruansy.fnst@fujitsu.com>
Tue, 29 Jul 2025 03:51:01 +0000 (11:51 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Sep 2025 00:24:35 +0000 (17:24 -0700)
Goto-san reported confusing pgpromote statistics where the
pgpromote_success count significantly exceeded pgpromote_candidate.

On a system with three nodes (nodes 0-1: DRAM 4GB, node 2: NVDIMM 4GB):
 # Enable demotion only
 echo 1 > /sys/kernel/mm/numa/demotion_enabled
 numactl -m 0-1 memhog -r200 3500M >/dev/null &
 pid=$!
 sleep 2
 numactl memhog -r100 2500M >/dev/null &
 sleep 10
 kill -9 $pid # terminate the 1st memhog
 # Enable promotion
 echo 2 > /proc/sys/kernel/numa_balancing

After a few seconds, we observeed `pgpromote_candidate < pgpromote_success`
$ grep -e pgpromote /proc/vmstat
pgpromote_success 2579
pgpromote_candidate 0

In this scenario, after terminating the first memhog, the conditions for
pgdat_free_space_enough() are quickly met, and triggers promotion.
However, these migrated pages are only counted for in PGPROMOTE_SUCCESS,
not in PGPROMOTE_CANDIDATE.

To solve these confusing statistics, introduce PGPROMOTE_CANDIDATE_NRL to
count the missed promotion pages.  And also, not counting these pages into
PGPROMOTE_CANDIDATE is to avoid changing the existing algorithm or
performance of the promotion rate limit.

Link: https://lkml.kernel.org/r/20250901090122.124262-1-ruansy.fnst@fujitsu.com
Link: https://lkml.kernel.org/r/20250729035101.1601407-1-ruansy.fnst@fujitsu.com
Fixes: c6833e10008f ("memory tiering: rate limit NUMA migration throughput")
Co-developed-by: Li Zhijian <lizhijian@fujitsu.com>
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Signed-off-by: Ruan Shiyang <ruansy.fnst@fujitsu.com>
Reported-by: Yasunori Gotou (Fujitsu) <y-goto@fujitsu.com>
Suggested-by: Huang Ying <ying.huang@linux.alibaba.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Huang Ying <ying.huang@linux.alibaba.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Valentin Schneider <vschneid@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/mmzone.h
kernel/sched/fair.c
mm/vmstat.c

index 0c5da9141983b795018c0aa2457b065507416564..9d3ea9085556f7e7c3c0e97d75d6b3d627c79776 100644 (file)
@@ -234,7 +234,21 @@ enum node_stat_item {
 #endif
 #ifdef CONFIG_NUMA_BALANCING
        PGPROMOTE_SUCCESS,      /* promote successfully */
-       PGPROMOTE_CANDIDATE,    /* candidate pages to promote */
+       /**
+        * Candidate pages for promotion based on hint fault latency.  This
+        * counter is used to control the promotion rate and adjust the hot
+        * threshold.
+        */
+       PGPROMOTE_CANDIDATE,
+       /**
+        * Not rate-limited (NRL) candidate pages for those can be promoted
+        * without considering hot threshold because of enough free pages in
+        * fast-tier node.  These promotions bypass the regular hotness checks
+        * and do NOT influence the promotion rate-limiter or
+        * threshold-adjustment logic.
+        * This is for statistics/monitoring purposes.
+        */
+       PGPROMOTE_CANDIDATE_NRL,
 #endif
        /* PGDEMOTE_*: pages demoted */
        PGDEMOTE_KSWAPD,
index b173a059315c2e076ef1d8347f8816d9c2c33937..82c8d804c54c119fc385970ed401656f360bb84a 100644 (file)
@@ -1923,11 +1923,13 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
                struct pglist_data *pgdat;
                unsigned long rate_limit;
                unsigned int latency, th, def_th;
+               long nr = folio_nr_pages(folio);
 
                pgdat = NODE_DATA(dst_nid);
                if (pgdat_free_space_enough(pgdat)) {
                        /* workload changed, reset hot threshold */
                        pgdat->nbp_threshold = 0;
+                       mod_node_page_state(pgdat, PGPROMOTE_CANDIDATE_NRL, nr);
                        return true;
                }
 
@@ -1941,8 +1943,7 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
                if (latency >= th)
                        return false;
 
-               return !numa_promotion_rate_limit(pgdat, rate_limit,
-                                                 folio_nr_pages(folio));
+               return !numa_promotion_rate_limit(pgdat, rate_limit, nr);
        }
 
        this_cpupid = cpu_pid_to_cpupid(dst_cpu, current->pid);
index 71cd1ceba191e15e74255a3eaf5d43a48f26eb34..e74f0b2a10215c7e7c598f76bd316d52636b4457 100644 (file)
@@ -1280,6 +1280,7 @@ const char * const vmstat_text[] = {
 #ifdef CONFIG_NUMA_BALANCING
        [I(PGPROMOTE_SUCCESS)]                  = "pgpromote_success",
        [I(PGPROMOTE_CANDIDATE)]                = "pgpromote_candidate",
+       [I(PGPROMOTE_CANDIDATE_NRL)]            = "pgpromote_candidate_nrl",
 #endif
        [I(PGDEMOTE_KSWAPD)]                    = "pgdemote_kswapd",
        [I(PGDEMOTE_DIRECT)]                    = "pgdemote_direct",