From: Chris Mason With MGLRU enabled, clean page cache that was reparented from a removed memory cgroup can stay unreclaimable for as long as the parent has no other evictable folios on the same node. try_to_shrink_lruvec() derives its scan count from lruvec_evictable_size(), and with a count of 0 it runs neither eviction nor aging. lruvec_evictable_size() adds up nr_pages[] only for the generations from min_seq to max_seq. That sum is complete only if the count of a generation is 0 by the time min_seq advances past it. But try_to_inc_min_seq() ignores the counts: it advances min_seq past a generation as soon as the lists of that generation are empty. A folio that folio_update_gen() promoted is counted in its new generation, but stays on the list of the generation that it came from. Normally min_seq stops at that list, before it reaches the new generation. Reparenting moves each list and each count to the same index in the parent, where that index can stand for a different age: index (seq % MAX_NR_GENS) 0 1 2 3 seq in the child 0 1 2 3 seq in the parent 4 5 6 3 folio F: on folios[0], counted in nr_pages[3] child: folios[0] holds min_seq at 0 parent: folios[3] is empty, so min_seq goes from 3 to 4 sum: nr_pages[0] + nr_pages[1] + nr_pages[2] = 0, without F The fix used here is to add up nr_pages[] of all MAX_NR_GENS generations in lruvec_evictable_size(). Fixes: 163bc3d68c9f ("mm/mglru: restructure the reclaim loop") Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) [Barry: Rebased onto mm-new and added comments] Signed-off-by: Barry Song (Xiaomi) --- mm/vmscan.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index cbed395955d4..60c416819c57 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4272,8 +4272,6 @@ static void lruvec_evictable_size(struct lruvec *lruvec, struct scan_control *sc struct lru_gen_folio *lrugen = &lruvec->lrugen; struct mem_cgroup *memcg = lruvec_memcg(lruvec); int nid = lruvec_pgdat(lruvec)->node_id; - DEFINE_MAX_SEQ(lruvec); - DEFINE_MIN_SEQ(lruvec); nr[LRU_GEN_ANON] = 0; nr[LRU_GEN_FILE] = 0; @@ -4281,7 +4279,12 @@ static void lruvec_evictable_size(struct lruvec *lruvec, struct scan_control *sc for_each_evictable_type(type, swappiness) { if (type == LRU_GEN_ANON && !can_reclaim_anon_pages(memcg, nid, sc)) continue; - for (seq = min_seq[type]; seq <= max_seq; seq++) + /* + * Reparenting can leave folios accounted for in + * generations outside [min_seq, max_seq]. Count + * them as well to ensure reclaim makes progress. + */ + for (seq = 0; seq < MAX_NR_GENS; seq++) nr[type] += lruvec_gen_size(lrugen, type, seq, max_zone); } } -- 2.39.3 (Apple Git-146)