[PATCH RFC v3 14/17] mm/mglru: reparent folios from all generations
From: Kairui Song via B4 Relay
Date: Sat Oct 03 2026 - 09:03:33 EST
From: Kairui Song <kasong@xxxxxxxxxxx>
A lockless promotion racing with aging can reuse a generation index,
see folio_inc_lru_refs(). The retry repairs the folio flags, but
sort_folio() may have already moved the folio to the list of a
generation outside the [min_seq, max_seq] window.
__lru_gen_reparent_memcg() only splices the lists inside the child's
window, so such a folio would be left on a list of the dying memcg.
Splice the lists and move the counters of all MAX_NR_GENS generations
instead. Those outside the window are empty in the common case.
Assisted-by: LLM
Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
mm/vmscan.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 9cc06a95d931..1bc8e5056265 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4947,7 +4947,8 @@ static void __lru_gen_reparent_memcg(struct lruvec *child_lruvec, struct lruvec
child_lrugen = &child_lruvec->lrugen;
parent_lrugen = &parent_lruvec->lrugen;
- for (i = 0; i < get_nr_gens(child_lruvec, type); i++) {
+ /* Lockless promotion may leave folios outside the child's window */
+ for (i = 0; i < MAX_NR_GENS; i++) {
int gen = lru_gen_from_seq(child_lrugen->max_seq - i);
long nr_pages = atomic_long_read(&child_lrugen->nr_pages[gen][type][zone]);
--
2.55.0