From 8adb83f004a71744106439b700de85e9fd6720f1 Mon Sep 17 00:00:00 2001 From: "Barry Song (Xiaomi)" Date: Tue, 28 Apr 2026 02:06:57 +0800 Subject: [PATCH 1/2] mm/mglru: avoid reclaim type fall back when isolation makes no progress ANBZ: #33015 cherry-picked from https://lore.kernel.org/all/20260428-mglru-reclaim-v7-6-02fabb92dc43@tencent.com/ While isolation makes no progress in scan_folios(), we quickly fall back to the other type in isolate_folios(). This is incorrect, as the current type may still have sufficient folios. Falling back can undermine the positive_ctrl_err() result from get_type_to_scan(), which is derived from swappiness. So just continue scanning this type for another round. Worth noting if the cold generations are all reclaimed, scan will no longer make any progress either, which may undermine the swappiness again. This is not a new issue and hence better be fixed later [1]. Link: https://lore.kernel.org/linux-mm/CAGsJ_4zjdOYEtuO6gNjABm7NDxW0skzBFNRNee-k2D6VwsYEQA@mail.gmail.com/ [1] Link: https://lore.kernel.org/20260428-mglru-reclaim-v7-6-02fabb92dc43@tencent.com Signed-off-by: Barry Song (Xiaomi) Signed-off-by: Kairui Song Reviewed-by: Kairui Song Cc: Axel Rasmussen Cc: Baolin Wang Cc: Chen Ridong Cc: Chris Li Cc: David Hildenbrand Cc: David Stevens Cc: Johannes Weiner Cc: Kalesh Singh Cc: Leno Hou Cc: Lorenzo Stoakes Cc: Michal Hocko Cc: Shakeel Butt Cc: Suren Baghdasaryan Cc: Vernon Yang Cc: Wei Xu Cc: Yafang Cc: Yuanchu Xie Cc: Yu Zhao Signed-off-by: Andrew Morton Signed-off-by: Baolin Wang --- mm/vmscan.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 2447fe5fa372..111f1cd8c372 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4832,7 +4832,13 @@ static int isolate_folios(unsigned long nr_to_scan, struct lruvec *lruvec, break; } - type = !type; + /* + * If type_scan > 0 and isolated == 0, avoid falling back to the + * other type, as this type remains sufficient. Falling back + * too readily can disrupt the positive_ctrl_err() bias. + */ + if (!type_scan) + type = !type; } return scanned; -- Gitee From ae4a33f26e03761ff23951b13bd97cbbb9d2d578 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 7 May 2026 15:45:23 +0800 Subject: [PATCH 2/2] mm/vmscan: fix unify writeback reclaim statistic and throttling ANBZ: #33015 cherry-picked from https://lore.kernel.org/all/20260428-mglru-reclaim-v7-0-02fabb92dc43@tencent.com/ Sync some fixes from the latest community patchset: Avoid potentially skewed stat counter Avoid potential over-rotation of tiny cgroup Signed-off-by: Kairui Song Signed-off-by: Baolin Wang --- mm/vmscan.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 111f1cd8c372..3fe6b3d1a89d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1976,7 +1976,7 @@ static void handle_reclaim_writeback(unsigned long nr_taken, * the flushers simply cannot keep up with the allocation * rate. Nudge the flusher threads in case they are asleep. */ - if (stat->nr_unqueued_dirty == nr_taken && nr_taken) { + if (stat->nr_unqueued_dirty == nr_taken) { wakeup_flusher_threads(WB_REASON_VMSCAN); /* * For cgroupv1 dirty throttling is achieved by waking up @@ -4880,7 +4880,9 @@ static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec, retry: reclaimed = shrink_folio_list(&list, pgdat, sc, &stat, false); sc->nr_reclaimed += reclaimed; - handle_reclaim_writeback(isolated, pgdat, sc, &stat); + /* Retry pass is only meant for clean folios without new isolation */ + if (isolated) + handle_reclaim_writeback(isolated, pgdat, sc, &stat); list_for_each_entry_safe_reverse(folio, next, &list, lru) { DEFINE_MIN_SEQ(lruvec); @@ -5012,9 +5014,6 @@ static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) struct mem_cgroup *memcg = lruvec_memcg(lruvec); nr_to_scan = get_nr_to_scan(lruvec, sc, memcg, swappiness); - if (!nr_to_scan) - need_rotate = true; - while (nr_to_scan > 0) { int delta; DEFINE_MAX_SEQ(lruvec); -- Gitee