From: Kairui Song 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 --- mm/vmscan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 617f69c1d9f9..a9c224377234 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4936,7 +4936,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.56.0