mm/vmscan: mitigate spurious kswapd_failures reset and add tracepoints
Subsystems (7)
v4 cover mm/vmscan: mitigate spurious kswapd_failures reset and add tracepoints
== Problem ==
We observed an issue in production on a multi-NUMA system where kswapd runs endlessly, causing sustained heavy IO READ pressure across the entire system.
The root cause is that direct reclaim triggered by cgroup memory.high keeps resetting kswapd_failures to 0, even when the node cannot be balanced. This prevents kswapd from ever stopping after reaching MAX_RECLAIM_RETRIES.
```bash
bpftrace -e '
#include <linux/mmzone.h>
#include <linux/shrinker.h>
kprobe:balance_pgdat {
$pgdat = (struct pglist_data *)arg0;
if ($pgdat->kswapd_failures > 0) {
printf("[node %d] [%lu] kswapd end, kswapd_failures %d\n",
$pgdat->node_id, jiffies, $pgdat->kswapd_failures);
}
}
tracepoint:vmscan:mm_vmscan_direct_reclaim_end {
printf("[cpu %d] [%ul] reset kswapd_failures %d \n", cpu, jiffies,
args.nr_reclaimed)
}
'
```The trace results showed that when kswapd_failures reaches 15, continuous direct reclaim keeps resetting it to 0. This was accompanied by a flood of kswapd_failures log entries, and shortly after, we observed massive refaults occurring.
== Solution ==
Patch 1 fixes the issue by only resetting kswapd_failures when the node is actually balanced. This introduces pgdat_try_reset_kswapd_failures() as a wrapper that checks pgdat_balanced() before resetting.
Patch 2 extends the wrapper to track why kswapd_failures was reset, adding tracepoints for better observability:
- mm_vmscan_reset_kswapd_failures: traces each reset with reason
- mm_vmscan_kswapd_reclaim_fail: traces each kswapd reclaim failure
---
v3 -> v4: https://lore.kernel.org/linux-mm/[email protected]/
- Add Acked-by tags
- Some modifications suggested by Johannes Weiner
v2 -> v3: https://lore.kernel.org/all/[email protected]/
- Add tracepoints for kswapd_failures reset and reclaim failure
- Expand commit message with test results
v1 -> v2: https://lore.kernel.org/all/[email protected]/
Jiayuan Chen (2):
mm/vmscan: mitigate spurious kswapd_failures reset from direct reclaim mm/vmscan: add tracepoint and reason for kswapd_failures reset
include/linux/mmzone.h | 17 ++++++++++-- include/trace/events/vmscan.h | 51 +++++++++++++++++++++++++++++++++++ mm/memory-tiers.c | 2 +- mm/page_alloc.c | 4 +-- mm/show_mem.c | 3 +-- mm/vmscan.c | 45 +++++++++++++++++++++++++------ mm/vmstat.c | 2 +- 7 files changed, 108 insertions(+), 16 deletions(-)
Signature · 1 line
2.43.0
PATCH v4 1/2 mm/vmscan: mitigate spurious kswapd_failures reset from direct reclaim
From: Jiayuan Chen <[email protected]>
When kswapd fails to reclaim memory, kswapd_failures is incremented. Once it reaches MAX_RECLAIM_RETRIES, kswapd stops running to avoid futile reclaim attempts. However, any successful direct reclaim unconditionally resets kswapd_failures to 0, which can cause problems.
We observed an issue in production on a multi-NUMA system where a process allocated large amounts of anonymous pages on a single NUMA node, causing its watermark to drop below high and evicting most file pages:
$ numastat -m
Per-node system memory usage (in MBs):
Node 0 Node 1 Total
--------------- --------------- ---------------
MemTotal 128222.19 127983.91 256206.11
MemFree 1414.48 1432.80 2847.29
MemUsed 126807.71 126551.11 252358.82
SwapCached 0.00 0.00 0.00
Active 29017.91 25554.57 54572.48
Inactive 92749.06 95377.00 188126.06
Active(anon) 28998.96 23356.47 52355.43
Inactive(anon) 92685.27 87466.11 180151.39
Active(file) 18.95 2198.10 2217.05
Inactive(file) 63.79 7910.89 7974.68With swap disabled, only file pages can be reclaimed. When kswapd is woken (e.g., via wake_all_kswapds()), it runs continuously but cannot raise free memory above the high watermark since reclaimable file pages are insufficient. Normally, kswapd would eventually stop after kswapd_failures reaches MAX_RECLAIM_RETRIES.
However, containers on this machine have memory.high set in their cgroup. Business processes continuously trigger the high limit, causing frequent direct reclaim that keeps resetting kswapd_failures to 0. This prevents kswapd from ever stopping.
The key insight is that direct reclaim triggered by cgroup memory.high performs aggressive scanning to throttle the allocating process. With sufficiently aggressive scanning, even hot pages will eventually be reclaimed, making direct reclaim "successful" at freeing some memory. However, this success does not mean the node has reached a balanced state - the freed memory may still be insufficient to bring free pages above the high watermark. Unconditionally resetting kswapd_failures in this case keeps kswapd alive indefinitely.
The result is that kswapd runs endlessly. Unlike direct reclaim which only reclaims from the allocating cgroup, kswapd scans the entire node's memory. This causes hot file pages from all workloads on the node to be evicted, not just those from the cgroup triggering memory.high. These pages constantly refault, generating sustained heavy IO READ pressure across the entire system.
Fix this by only resetting kswapd_failures when the node is actually balanced. This allows both kswapd and direct reclaim to clear kswapd_failures upon successful reclaim, but only when the reclaim actually resolves the memory pressure (i.e., the node becomes balanced).
--- include/linux/mmzone.h | 2 ++ mm/vmscan.c | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)
include/linux/mmzone.h +2 -0
@@ -1536,6 +1536,8 @@ static inline unsigned long pgdat_end_pfn(pg_data_t *pgdat)void build_all_zonelists (pg_data_t *pgdat);void wakeup_kswapd (struct zone *zone,gfp_t gfp_mask,int order,enum zone_type highest_zoneidx); +void kswapd_try_clear_hopeless (struct pglist_data *pgdat, +unsigned int order,int highest_zoneidx);bool __zone_watermark_ok (struct zone *z,unsigned int order,unsigned long mark,int highest_zoneidx,unsigned int alloc_flags,long free_pages);
mm/vmscan.c +20 -2
@@ -5067,7 +5067,7 @@ static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *blk_finish_plug (&plug); done:if (sc->nr_reclaimed > reclaimed) -atomic_set (&pgdat->kswapd_failures,0 ); +kswapd_try_clear_hopeless (pgdat, sc->order, sc->reclaim_idx); }/******************************************************************************
@@ -6141,7 +6141,7 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)* successful direct reclaim run will revive a dormant kswapd. */ if (reclaimable) -atomic_set (&pgdat->kswapd_failures,0 ); +kswapd_try_clear_hopeless (pgdat, sc->order, sc->reclaim_idx);else if (sc->cache_trim_mode) sc->cache_trim_mode_failed =1 ; }
@@ -7414,6 +7414,24 @@ void wakeup_kswapd(struct zone *zone, gfp_t gfp_flags, int order,wake_up_interruptible (&pgdat->kswapd_wait); } +static void kswapd_clear_hopeless (pg_data_t *pgdat) +{ +atomic_set (&pgdat->kswapd_failures,0 ); +} + +/* +* Reset kswapd_failures only when the node is balanced. Without this +* check, successful direct reclaim (e.g., from cgroup memory.high +* throttling) can keep resetting kswapd_failures even when the node +* cannot be balanced, causing kswapd to run endlessly. +*/ +void kswapd_try_clear_hopeless (struct pglist_data *pgdat, +unsigned int order,int highest_zoneidx) +{ +if (pgdat_balanced (pgdat, order, highest_zoneidx)) +kswapd_clear_hopeless (pgdat); +} +#ifdef CONFIG_HIBERNATION /* * Try to free `nr_to_reclaim' of memory, system-wide, and return the number of
Signature · 1 line
2.43.0
PATCH v4 2/2 mm/vmscan: add tracepoint and reason for kswapd_failures reset
In reply to Jiayuan ChenFrom: Jiayuan Chen <[email protected]>
Currently, kswapd_failures is reset in multiple places (kswapd, direct reclaim, PCP freeing, memory-tiers), but there's no way to trace when and why it was reset, making it difficult to debug memory reclaim issues.
This patch:
1. Introduce kswapd_clear_hopeless() as a wrapper function to centralize kswapd_failures reset logic.
2. Introduce kswapd_test_hopeless() to encapsulate hopeless node checks, replacing all open-coded kswapd_failures comparisons.
3. Add kswapd_clear_hopeless_reason enum to distinguish reset sources:
- KSWAPD_CLEAR_HOPELESS_KSWAPD: reset from kswapd context
- KSWAPD_CLEAR_HOPELESS_DIRECT: reset from direct reclaim
- KSWAPD_CLEAR_HOPELESS_PCP: reset from PCP page freeing
- KSWAPD_CLEAR_HOPELESS_OTHER: reset from other paths
4. Add tracepoints for better observability:
- mm_vmscan_kswapd_clear_hopeless: traces each reset with reason
- mm_vmscan_kswapd_reclaim_fail: traces each kswapd reclaim failure
Test results:
$ trace-cmd record -e vmscan:mm_vmscan_kswapd_clear_hopeless -e vmscan:mm_vmscan_kswapd_reclaim_fail $ # generate memory pressure $ trace-cmd report cpus=4 kswapd0-71 [000] 27.216563: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=1 kswapd0-71 [000] 27.217169: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=2 kswapd0-71 [000] 27.217764: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=3 kswapd0-71 [000] 27.218353: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=4 kswapd0-71 [000] 27.218993: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=5 kswapd0-71 [000] 27.219744: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=6 kswapd0-71 [000] 27.220488: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=7 kswapd0-71 [000] 27.221206: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=8 kswapd0-71 [000] 27.221806: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=9 kswapd0-71 [000] 27.222634: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=10 kswapd0-71 [000] 27.223286: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=11 kswapd0-71 [000] 27.223894: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=12 kswapd0-71 [000] 27.224712: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=13 kswapd0-71 [000] 27.225424: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=14 kswapd0-71 [000] 27.226082: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=15 kswapd0-71 [000] 27.226810: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=16 kswapd1-72 [002] 27.386869: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=1 kswapd1-72 [002] 27.387435: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=2 kswapd1-72 [002] 27.388016: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=3 kswapd1-72 [002] 27.388586: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=4 kswapd1-72 [002] 27.389155: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=5 kswapd1-72 [002] 27.389723: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=6 kswapd1-72 [002] 27.390292: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=7 kswapd1-72 [002] 27.392364: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=8 kswapd1-72 [002] 27.392934: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=9 kswapd1-72 [002] 27.393504: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=10 kswapd1-72 [002] 27.394073: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=11 kswapd1-72 [002] 27.394899: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=12 kswapd1-72 [002] 27.395472: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=13 kswapd1-72 [002] 27.396055: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=14 kswapd1-72 [002] 27.396628: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=15 kswapd1-72 [002] 27.397199: mm_vmscan_kswapd_reclaim_fail: nid=1 failures=16 kworker/u18:0-40 [002] 27.410151: mm_vmscan_kswapd_clear_hopeless: nid=0 reason=DIRECT kswapd0-71 [000] 27.439454: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=1 kswapd0-71 [000] 27.440048: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=2 kswapd0-71 [000] 27.440634: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=3 kswapd0-71 [000] 27.441211: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=4 kswapd0-71 [000] 27.441787: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=5 kswapd0-71 [000] 27.442363: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=6 kswapd0-71 [000] 27.443030: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=7 kswapd0-71 [000] 27.443725: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=8 kswapd0-71 [000] 27.444315: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=9 kswapd0-71 [000] 27.444898: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=10 kswapd0-71 [000] 27.445476: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=11 kswapd0-71 [000] 27.446053: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=12 kswapd0-71 [000] 27.446646: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=13 kswapd0-71 [000] 27.447230: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=14 kswapd0-71 [000] 27.447812: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=15 kswapd0-71 [000] 27.448391: mm_vmscan_kswapd_reclaim_fail: nid=0 failures=16 ann-423 [003] 28.028285: mm_vmscan_kswapd_clear_hopeless: nid=0 reason=PCP
--- include/linux/mmzone.h | 19 ++++++++++--- include/trace/events/vmscan.h | 51 +++++++++++++++++++++++++++++++++++ mm/memory-tiers.c | 2 +- mm/page_alloc.c | 4 +-- mm/show_mem.c | 3 +-- mm/vmscan.c | 29 +++++++++++++------- mm/vmstat.c | 2 +- 7 files changed, 91 insertions(+), 19 deletions(-)
include/linux/mmzone.h +15 -4
@@ -1534,16 +1534,27 @@ static inline unsigned long pgdat_end_pfn(pg_data_t *pgdat)#include <linux/memory_hotplug.h> void build_all_zonelists (pg_data_t *pgdat); -void wakeup_kswapd (struct zone *zone,gfp_t gfp_mask,int order, -enum zone_type highest_zoneidx); -void kswapd_try_clear_hopeless (struct pglist_data *pgdat, -unsigned int order,int highest_zoneidx);bool __zone_watermark_ok (struct zone *z,unsigned int order,unsigned long mark,int highest_zoneidx,unsigned int alloc_flags,long free_pages);bool zone_watermark_ok (struct zone *z,unsigned int order,unsigned long mark,int highest_zoneidx,unsigned int alloc_flags); + +enum kswapd_clear_hopeless_reason { +KSWAPD_CLEAR_HOPELESS_OTHER =0 , +KSWAPD_CLEAR_HOPELESS_KSWAPD , +KSWAPD_CLEAR_HOPELESS_DIRECT , +KSWAPD_CLEAR_HOPELESS_PCP , +}; + +void wakeup_kswapd (struct zone *zone,gfp_t gfp_mask,int order, +enum zone_type highest_zoneidx); +void kswapd_try_clear_hopeless (struct pglist_data *pgdat, +unsigned int order,int highest_zoneidx); +void kswapd_clear_hopeless (pg_data_t *pgdat,enum kswapd_clear_hopeless_reason reason); +bool kswapd_test_hopeless (pg_data_t *pgdat); +/* * Memory initialization context, use to differentiate memory added by * the platform statically or via memory hotplug interface.
include/trace/events/vmscan.h +51 -0
63 lines not on this page · raw message
mm/memory-tiers.c +1 -1
@@ -956,7 +956,7 @@ static ssize_t demotion_enabled_store(struct kobject *kobj,struct pglist_data *pgdat;for_each_online_pgdat (pgdat) -atomic_set (&pgdat->kswapd_failures,0 ); +kswapd_clear_hopeless (pgdat,KSWAPD_CLEAR_HOPELESS_OTHER ); }return count;
mm/page_alloc.c +2 -2
@@ -2916,9 +2916,9 @@ static bool free_frozen_page_commit(struct zone *zone,* 'hopeless node' to stay in that state for a while. Let * kswapd work again by resetting kswapd_failures. */ -if (atomic_read (&pgdat->kswapd_failures) >=MAX_RECLAIM_RETRIES && +if (kswapd_test_hopeless (pgdat) &&next_memory_node (pgdat->node_id) <MAX_NUMNODES ) -atomic_set (&pgdat->kswapd_failures,0 ); +kswapd_clear_hopeless (pgdat,KSWAPD_CLEAR_HOPELESS_PCP ); }return ret; }
mm/show_mem.c +1 -2
@@ -278,8 +278,7 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_z#endif K (node_page_state (pgdat,NR_PAGETABLE )),K (node_page_state (pgdat,NR_SECONDARY_PAGETABLE )), -str_yes_no (atomic_read (&pgdat->kswapd_failures) >= -MAX_RECLAIM_RETRIES ), +str_yes_no (kswapd_test_hopeless (pgdat)), K(node_page_state(pgdat, NR_BALLOON_PAGES))); }
mm/vmscan.c +20 -9
@@ -507,7 +507,7 @@ static bool skip_throttle_noprogress(pg_data_t *pgdat)* If kswapd is disabled, reschedule if necessary but do not * throttle as the system is likely near OOM. */ -if (atomic_read (&pgdat->kswapd_failures) >=MAX_RECLAIM_RETRIES ) +if (kswapd_test_hopeless (pgdat))return true;/*
@@ -6453,7 +6453,7 @@ static bool allow_direct_reclaim(pg_data_t *pgdat)int i;bool wmark_ok; -if (atomic_read (&pgdat->kswapd_failures) >=MAX_RECLAIM_RETRIES ) +if (kswapd_test_hopeless (pgdat))return true;for_each_managed_zone_pgdat (zone, pgdat, i,ZONE_NORMAL ) {
@@ -6862,7 +6862,7 @@ static bool prepare_kswapd_sleep(pg_data_t *pgdat, int order,wake_up_all (&pgdat->pfmemalloc_wait);/* Hopeless node, leave it to direct reclaim */ -if (atomic_read (&pgdat->kswapd_failures) >=MAX_RECLAIM_RETRIES ) +if (kswapd_test_hopeless (pgdat))return true;if (pgdat_balanced (pgdat, order, highest_zoneidx)) {
@@ -7134,8 +7134,11 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)* watermark_high at this point. We need to avoid increasing the * failure count to prevent the kswapd thread from stopping. */ -if (!sc.nr_reclaimed && !boosted) -atomic_inc (&pgdat->kswapd_failures); +if (!sc.nr_reclaimed && !boosted) { +int fail_cnt =atomic_inc_return (&pgdat->kswapd_failures); +/* kswapd context, low overhead to trace every failure */ +trace_mm_vmscan_kswapd_reclaim_fail (pgdat->node_id, fail_cnt); + } out:clear_reclaim_active (pgdat, highest_zoneidx);
@@ -7394,7 +7397,7 @@ void wakeup_kswapd(struct zone *zone, gfp_t gfp_flags, int order,return ;/* Hopeless node, leave it to direct reclaim if possible */ -if (atomic_read (&pgdat->kswapd_failures) >=MAX_RECLAIM_RETRIES || +if (kswapd_test_hopeless (pgdat) || (pgdat_balanced (pgdat, order, highest_zoneidx) && !pgdat_watermark_boosted (pgdat, highest_zoneidx))) {/*
@@ -7414,9 +7417,11 @@ void wakeup_kswapd(struct zone *zone, gfp_t gfp_flags, int order,wake_up_interruptible (&pgdat->kswapd_wait); } -static void kswapd_clear_hopeless (pg_data_t *pgdat) +void kswapd_clear_hopeless (pg_data_t *pgdat,enum kswapd_clear_hopeless_reason reason) { -atomic_set (&pgdat->kswapd_failures,0 ); +/* Only trace actual resets, not redundant zero-to-zero */ +if (atomic_xchg (&pgdat->kswapd_failures,0 )) +trace_mm_vmscan_kswapd_clear_hopeless (pgdat->node_id, reason); }/*
@@ -7429,7 +7434,13 @@ void kswapd_try_clear_hopeless(struct pglist_data *pgdat, unsigned int order, int highest_zoneidx) { if (pgdat_balanced(pgdat, order, highest_zoneidx)) - kswapd_clear_hopeless(pgdat); + kswapd_clear_hopeless(pgdat, current_is_kswapd() ? + KSWAPD_CLEAR_HOPELESS_KSWAPD : KSWAPD_CLEAR_HOPELESS_DIRECT); +} + +bool kswapd_test_hopeless (pg_data_t *pgdat) +{ +return atomic_read (&pgdat->kswapd_failures) >=MAX_RECLAIM_RETRIES ; }#ifdef CONFIG_HIBERNATION
mm/vmstat.c +1 -1
@@ -1855,7 +1855,7 @@ static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,"\n start_pfn: %lu" "\n reserved_highatomic: %lu" "\n free_highatomic: %lu" , -atomic_read (&pgdat->kswapd_failures) >=MAX_RECLAIM_RETRIES , +kswapd_test_hopeless (pgdat), zone->zone_start_pfn, zone->nr_reserved_highatomic, zone->nr_free_highatomic);
Signature · 1 line
2.43.0
Re: [PATCH v4 2/2] mm/vmscan: add tracepoint and reason for kswapd_failures reset
Quoted 4 lines · On Tue, 20 Jan 2026 10:43:49 +0800 Jiayuan Chen <[email protected]> wrote:
Acked-by Shakeel Butt <[email protected]>Suggested-by Johannes Weiner <[email protected]>Signed-off-by Jiayuan Chen <[email protected]>Signed-off-by Jiayuan Chen <[email protected]>
Quoted 9 lines
--- include/linux/mmzone.h | 19 ++++++++++--- include/trace/events/vmscan.h | 51 +++++++++++++++++++++++++++++++++++ mm/memory-tiers.c | 2 +- mm/page_alloc.c | 4 +-- mm/show_mem.c | 3 +-- mm/vmscan.c | 29 +++++++++++++------- mm/vmstat.c | 2 +- 7 files changed, 91 insertions(+), 19 deletions(-)
From a tracing POV:
-- Steve
Andrew Morton
maintainerQuoted 11 lines · On Tue, 20 Jan 2026 10:43:47 +0800 Jiayuan Chen <[email protected]> wrote:
== Problem ==
We observed an issue in production on a multi-NUMA system where kswapd runs endlessly, causing sustained heavy IO READ pressure across the entire system.
The root cause is that direct reclaim triggered by cgroup memory.high keeps resetting
kswapd_failuresto 0, even when the node cannot be balanced. This prevents kswapd from ever stopping after reachingMAX_RECLAIM_RETRIES.
Updated, thanks.
Quoted 3 lines
v3 -> v4: https://lore.kernel.org/linux-mm/[email protected]/
- Add Acked-by tags
- Some modifications suggested by Johannes Weiner
Here's how v4 altered mm.git:
include/linux/mmzone.h | 26 ++++++++----- include/trace/events/vmscan.h | 24 ++++++------ mm/memory-tiers.c | 2 - mm/page_alloc.c | 4 +- mm/show_mem.c | 3 - mm/vmscan.c | 60 +++++++++++++++++--------------- mm/vmstat.c | 2 - 7 files changed, 64 insertions(+), 57 deletions(-)
include/linux/mmzone.h renamed from include/linux/mmzone.h~b +15 -11
@@ -1531,26 +1531,30 @@ static inline unsigned long pgdat_end_pfreturn pgdat->node_start_pfn + pgdat->node_spanned_pages; } -enum reset_kswapd_failures_reason { -RESET_KSWAPD_FAILURES_OTHER =0 , -RESET_KSWAPD_FAILURES_KSWAPD , -RESET_KSWAPD_FAILURES_DIRECT , -RESET_KSWAPD_FAILURES_PCP , -}; - -void pgdat_reset_kswapd_failures (pg_data_t *pgdat,enum reset_kswapd_failures_reason reason); -#include <linux/memory_hotplug.h> void build_all_zonelists (pg_data_t *pgdat); -void wakeup_kswapd (struct zone *zone,gfp_t gfp_mask,int order, -enum zone_type highest_zoneidx);bool __zone_watermark_ok (struct zone *z,unsigned int order,unsigned long mark,int highest_zoneidx,unsigned int alloc_flags,long free_pages);bool zone_watermark_ok (struct zone *z,unsigned int order,unsigned long mark,int highest_zoneidx,unsigned int alloc_flags); + +enum kswapd_clear_hopeless_reason { +KSWAPD_CLEAR_HOPELESS_OTHER =0 , +KSWAPD_CLEAR_HOPELESS_KSWAPD , +KSWAPD_CLEAR_HOPELESS_DIRECT , +KSWAPD_CLEAR_HOPELESS_PCP , +}; + +void wakeup_kswapd (struct zone *zone,gfp_t gfp_mask,int order, +enum zone_type highest_zoneidx); +void kswapd_try_clear_hopeless (struct pglist_data *pgdat, +unsigned int order,int highest_zoneidx); +void kswapd_clear_hopeless (pg_data_t *pgdat,enum kswapd_clear_hopeless_reason reason); +bool kswapd_test_hopeless (pg_data_t *pgdat); +/* * Memory initialization context, use to differentiate memory added by * the platform statically or via memory hotplug interface.
include/trace/events/vmscan.h renamed from include/trace/events/vmscan.h~b +12 -12
@@ -40,16 +40,16 @@ {_VMSCAN_THROTTLE_CONGESTED, "VMSCAN_THROTTLE_CONGESTED"} \ ) : "VMSCAN_THROTTLE_NONE" -TRACE_DEFINE_ENUM (RESET_KSWAPD_FAILURES_OTHER ); -TRACE_DEFINE_ENUM (RESET_KSWAPD_FAILURES_KSWAPD ); -TRACE_DEFINE_ENUM (RESET_KSWAPD_FAILURES_DIRECT ); -TRACE_DEFINE_ENUM (RESET_KSWAPD_FAILURES_PCP ); - -#define reset_kswapd_src \ - {RESET_KSWAPD_FAILURES_KSWAPD, "KSWAPD"}, \ - {RESET_KSWAPD_FAILURES_DIRECT, "DIRECT"}, \ - {RESET_KSWAPD_FAILURES_PCP, "PCP"}, \ - {RESET_KSWAPD_FAILURES_OTHER, "OTHER"} +TRACE_DEFINE_ENUM (KSWAPD_CLEAR_HOPELESS_OTHER ); +TRACE_DEFINE_ENUM (KSWAPD_CLEAR_HOPELESS_KSWAPD ); +TRACE_DEFINE_ENUM (KSWAPD_CLEAR_HOPELESS_DIRECT ); +TRACE_DEFINE_ENUM (KSWAPD_CLEAR_HOPELESS_PCP ); + +#define kswapd_clear_hopeless_reason_ops \ + {KSWAPD_CLEAR_HOPELESS_KSWAPD, "KSWAPD"}, \ + {KSWAPD_CLEAR_HOPELESS_DIRECT, "DIRECT"}, \ + {KSWAPD_CLEAR_HOPELESS_PCP, "PCP"}, \ + {KSWAPD_CLEAR_HOPELESS_OTHER, "OTHER"}#define trace_reclaim_flags (file) ( \ (file ? RECLAIM_WB_FILE : RECLAIM_WB_ANON) | \
@@ -566,7 +566,7 @@ TRACE_EVENT(mm_vmscan_kswapd_reclaim_fai __entry->nid, __entry->failures) ); -TRACE_EVENT(mm_vmscan_reset_kswapd_failures, +TRACE_EVENT(mm_vmscan_kswapd_clear_hopeless, TP_PROTO(int nid, int reason),
@@ -584,7 +584,7 @@ TRACE_EVENT(mm_vmscan_reset_kswapd_failuTP_printk ("nid=%d reason=%s" , __entry->nid, -__print_symbolic (__entry->reason, reset_kswapd_src)) +__print_symbolic (__entry->reason, kswapd_clear_hopeless_reason_ops)) );#endif /* _TRACE_VMSCAN_H */
mm/memory-tiers.c renamed from mm/memory-tiers.c~b +1 -1
@@ -955,7 +955,7 @@ static ssize_t demotion_enabled_store(ststruct pglist_data *pgdat;for_each_online_pgdat (pgdat) -pgdat_reset_kswapd_failures (pgdat,RESET_KSWAPD_FAILURES_OTHER ); +kswapd_clear_hopeless (pgdat,KSWAPD_CLEAR_HOPELESS_OTHER ); }return count;
mm/page_alloc.c renamed from mm/page_alloc.c~b +2 -2
@@ -2945,9 +2945,9 @@ static bool free_frozen_page_commit(stru* 'hopeless node' to stay in that state for a while. Let * kswapd work again by resetting kswapd_failures. */ -if (atomic_read (&pgdat->kswapd_failures) >=MAX_RECLAIM_RETRIES && +if (kswapd_test_hopeless (pgdat) &&next_memory_node (pgdat->node_id) <MAX_NUMNODES ) -pgdat_reset_kswapd_failures (pgdat,RESET_KSWAPD_FAILURES_PCP ); +kswapd_clear_hopeless (pgdat,KSWAPD_CLEAR_HOPELESS_PCP ); }return ret; }
mm/show_mem.c renamed from mm/show_mem.c~b +1 -2
@@ -278,8 +278,7 @@ static void show_free_areas(unsigned int#endif K (node_page_state (pgdat,NR_PAGETABLE )),K (node_page_state (pgdat,NR_SECONDARY_PAGETABLE )), -str_yes_no (atomic_read (&pgdat->kswapd_failures) >= -MAX_RECLAIM_RETRIES ), +str_yes_no (kswapd_test_hopeless (pgdat)), K(node_page_state(pgdat, NR_BALLOON_PAGES))); }
mm/vmscan.c renamed from mm/vmscan.c~b +32 -28
108 lines not on this page · raw message
mm/vmstat.c renamed from mm/vmstat.c~b +1 -1
@@ -1840,7 +1840,7 @@ static void zoneinfo_show_print(struct s"\n start_pfn: %lu" "\n reserved_highatomic: %lu" "\n free_highatomic: %lu" , -atomic_read (&pgdat->kswapd_failures) >=MAX_RECLAIM_RETRIES , +kswapd_test_hopeless (pgdat), zone->zone_start_pfn, zone->nr_reserved_highatomic, zone->nr_free_highatomic);
_