Skip to content

Commit d221dd5

Browse files
Byungchul Parkakpm00
authored andcommitted
mm, vmscan: retry kswapd's priority loop with cache_trim_mode off on failure
With cache_trim_mode on, reclaim logic doesn't bother reclaiming anon pages. However, it should be more careful to use the mode because it's going to prevent anon pages from being reclaimed even if there are a huge number of anon pages that are cold and should be reclaimed. Even worse, that leads kswapd_failures to reach MAX_RECLAIM_RETRIES and stopping kswapd from functioning until direct reclaim eventually works to resume kswapd. So kswapd needs to retry its scan priority loop with cache_trim_mode off again if the mode doesn't work for reclaim. The problematic behavior can be reproduced by: CONFIG_NUMA_BALANCING enabled sysctl_numa_balancing_mode set to NUMA_BALANCING_MEMORY_TIERING numa node0 (8GB local memory, 16 CPUs) numa node1 (8GB slow tier memory, no CPUs) Sequence: 1) echo 3 > /proc/sys/vm/drop_caches 2) To emulate the system with full of cold memory in local DRAM, run the following dummy program and never touch the region: mmap(0, 8 * 1024 * 1024 * 1024, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0); 3) Run any memory intensive work e.g. XSBench. 4) Check if numa balancing is working e.i. promotion/demotion. 5) Iterate 1) ~ 4) until numa balancing stops. With this, you could see that promotion/demotion are not working because kswapd has stopped due to ->kswapd_failures >= MAX_RECLAIM_RETRIES. Interesting vmstat delta's differences between before and after are like: +-----------------------+-------------------------------+ | interesting vmstat | before | after | +-----------------------+-------------------------------+ | nr_inactive_anon | 321935 | 1664772 | | nr_active_anon | 1780700 | 437834 | | nr_inactive_file | 30425 | 40882 | | nr_active_file | 14961 | 3012 | | pgpromote_success | 356 | 1293122 | | pgpromote_candidate | 21953245 | 1824148 | | pgactivate | 1844523 | 3311907 | | pgdeactivate | 50634 | 1554069 | | pgfault | 31100294 | 6518806 | | pgdemote_kswapd | 30856 | 2230821 | | pgscan_kswapd | 1861981 | 7667629 | | pgscan_anon | 1822930 | 7610583 | | pgscan_file | 39051 | 57046 | | pgsteal_anon | 386 | 2192033 | | pgsteal_file | 30470 | 38788 | | pageoutrun | 30 | 412 | | numa_hint_faults | 27418279 | 2875955 | | numa_pages_migrated | 356 | 1293122 | +-----------------------+-------------------------------+ Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Byungchul Park <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Yu Zhao <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b14d167 commit d221dd5

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

mm/vmscan.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ struct scan_control {
108108
/* Can folios be swapped as part of reclaim? */
109109
unsigned int may_swap:1;
110110

111+
/* Not allow cache_trim_mode to be turned on as part of reclaim? */
112+
unsigned int no_cache_trim_mode:1;
113+
114+
/* Has cache_trim_mode failed at least once? */
115+
unsigned int cache_trim_mode_failed:1;
116+
111117
/* Proactive reclaim invoked by userspace through memory.reclaim */
112118
unsigned int proactive:1;
113119

@@ -2271,7 +2277,8 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc)
22712277
* anonymous pages.
22722278
*/
22732279
file = lruvec_page_state(target_lruvec, NR_INACTIVE_FILE);
2274-
if (file >> sc->priority && !(sc->may_deactivate & DEACTIVATE_FILE))
2280+
if (file >> sc->priority && !(sc->may_deactivate & DEACTIVATE_FILE) &&
2281+
!sc->no_cache_trim_mode)
22752282
sc->cache_trim_mode = 1;
22762283
else
22772284
sc->cache_trim_mode = 0;
@@ -5986,6 +5993,8 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)
59865993
*/
59875994
if (reclaimable)
59885995
pgdat->kswapd_failures = 0;
5996+
else if (sc->cache_trim_mode)
5997+
sc->cache_trim_mode_failed = 1;
59895998
}
59905999

59916000
/*
@@ -6918,6 +6927,16 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)
69186927
sc.priority--;
69196928
} while (sc.priority >= 1);
69206929

6930+
/*
6931+
* Restart only if it went through the priority loop all the way,
6932+
* but cache_trim_mode didn't work.
6933+
*/
6934+
if (!sc.nr_reclaimed && sc.priority < 1 &&
6935+
!sc.no_cache_trim_mode && sc.cache_trim_mode_failed) {
6936+
sc.no_cache_trim_mode = 1;
6937+
goto restart;
6938+
}
6939+
69216940
if (!sc.nr_reclaimed)
69226941
pgdat->kswapd_failures++;
69236942

0 commit comments

Comments
 (0)