Re: [PATCH v3 1/2] mm/vmscan: mitigate spurious kswapd_failures reset from direct reclaim
From: "Jiayuan Chen" <jiayuan.chen@linux.dev>
Date: 2026-01-19 03:04:22
Also in:
linux-mm, lkml
2026/1/17 01:00, "Johannes Weiner" <hannes@cmpxchg.org mailto:hannes@cmpxchg.org?to=%22Johannes%20Weiner%22%20%3Channes%40cmpxchg.org%3E > wrote: [...]
quoted
Great analysis, and I agree with both the fix and adding tracepoints. Two minor nits:quoted
@@ -2650,6 +2650,25 @@ static bool can_age_anon_pages(struct lruvec *lruvec, lruvec_memcg(lruvec)); } +static void pgdat_reset_kswapd_failures(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. + */ +static bool pgdat_balanced(pg_data_t *pgdat, int order, int highest_zoneidx); +static inline void pgdat_try_reset_kswapd_failures(struct pglist_data *pgdat,Please remove the inline, the compiler will figure it out.quoted
+ struct scan_control *sc) +{ + if (pgdat_balanced(pgdat, sc->order, sc->reclaim_idx)) + pgdat_reset_kswapd_failures(pgdat); +}As this is kswapd API, please move these down to after wakeup_kswapd(). I think we can streamline the names a bit. We already use "hopeless" for that state in the comments; can you please rename the functions kswapd_clear_hopeless() and kswapd_try_clear_hopeless()? We should then also replace the open-coded kswapd_failure checks with kswapd_test_hopeless(). But I can send a follow-up patch if you don't want to, just let me know.
Thanks, Johannes and Shakeel. I'll send an updated version with these fixes.