[RFC PATCH v5 08/14] mm/mglru: lift youngest gen protection for higher priority
From: Barry Song (Xiaomi)
Date: Thu Oct 22 2026 - 18:03:28 EST
From: Kairui Song <kasong@xxxxxxxxxxx>
The forced protection of younger gens is in contradict of the goal of
minimizing the IO cost for reclaim. And under high pressure, MGLRU runs
into premature OOM constantly, where classical LRU never goes OOM.
The problem is when aging can't catch up with reclaimer, reclaimers will
all abort early seeing there is only empty gens, or only two gens left.
Proactive aging won't help eigher because there will be limited threads
doing aging, but there could be unlimited threads doing reclaim, which
is a fundommental limitation of MGLRU. One way to avoid this is to use a
aging lock, like in commit .... However, aging lock caused several
jitter when under huge pressure, and was reported to be causing
obserable lags already on Android.
What's more, the gen model somehow contradicts with the goal of
swappiness, which aim to reduce IO cost intead of following hotness
blindly.
So instead, let's lift the protection based on priority. With default
priority, we still fully respect the MIN_NR_GEN protection. But as the
priority raised, allow it to reclaim younger gens step by step.
OOM is gone, and swappiness is fair after this commit.
Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
Signed-off-by: Barry Song (Xiaomi) <baohua@xxxxxxxxxx>
---
mm/vmscan.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 0e37f5c8f355..12aca97be56b 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4929,12 +4929,14 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
VM_WARN_ON_ONCE(!list_empty(list));
/*
- * Respect the gen hotness distribution at low priority to avoid
- * aging and scan cost, but prefer to satisfy the reclaimers request
- * when under pressure to respect swappiness more and reduce IO cost.
+ * Respect hotness at default priority, and only reach into the
+ * newest generation when under severe pressure, so hot folios are
+ * not evicted as soon as priority is raised.
*/
if (sc->priority == DEF_PRIORITY)
- seq = lrugen->min_seq[type];
+ seq = lrugen->max_seq - MIN_NR_GENS;
+ else if (sc->priority > DEF_PRIORITY / 2)
+ seq = lrugen->max_seq - 1;
else
seq = lrugen->max_seq;
--
2.34.1