Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] mm/mglru: Avoid reclaiming kept folios during retrying missed rotated folios
@ 2026-10-03  5:42 Barry Song (Xiaomi)
  2026-10-08  6:52 ` Baolin Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Barry Song (Xiaomi) @ 2026-10-03  5:42 UTC (permalink / raw)
  To: linux-mm
  Cc: akpm, kasong, qi.zheng, shakeel.butt, baohua, axelrasmussen,
	yuanchu.xie, weixugc, baoquan.he, baolin.wang, chenridong,
	Yu Zhao, Bo Zhang

Since commit 4d5d14a01e2c ("mm/mglru: rework workingset protection"),
`folio_test_referenced()` was accidentally removed when checking for
missed rotated folios. As a result, kept folios without an active set
could be added to the retry list and eventually reclaimed.

The impact should be very small, as we have the `folio_mapped(folio)`
check before retrying. Kept folios won't have `try_to_unmap()` called,
so this is really only applicable to folios that are unmapped by users
after `folio_referenced()` has been called.

I'm not sure if anyone else has seen any issues with this. Sending an
RFC to check whether it is worth fixing.

Fixes: 4d5d14a01e2c ("mm/mglru: rework workingset protection")
Cc: Yu Zhao <yuzhao@google.com>
Reported-by: Bo Zhang <zhangbo56@xiaomi.com>
Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
---
 mm/vmscan.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 91295070ca33..6a931b576b7d 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -994,8 +994,10 @@ static enum folio_references folio_check_references(struct folio *folio,
 		return FOLIOREF_KEEP;
 
 	if (lru_gen_enabled() && !lru_gen_switching()) {
-		if (!referenced_ptes)
+		if (!referenced_ptes) {
+			folio_clear_referenced(folio);
 			return FOLIOREF_RECLAIM;
+		}
 
 		return lru_gen_set_refs(folio, &vma_flags) ? FOLIOREF_ACTIVATE : FOLIOREF_KEEP;
 	}
@@ -5110,7 +5112,8 @@ static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
 			continue;
 
 		/* retry folios that may have missed folio_rotate_reclaimable() */
-		if (!skip_retry && !folio_test_active(folio) && !folio_mapped(folio) &&
+		if (!skip_retry && !folio_test_active(folio) &&
+		    !folio_test_referenced(folio) && !folio_mapped(folio) &&
 		    !folio_test_dirty(folio) && !folio_test_writeback(folio)) {
 			list_move(&folio->lru, &clean);
 			continue;
-- 
2.39.3 (Apple Git-146)



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-10-08 12:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-03  5:42 [RFC PATCH] mm/mglru: Avoid reclaiming kept folios during retrying missed rotated folios Barry Song (Xiaomi)
2026-10-08  6:52 ` Baolin Wang
2026-10-08 11:43   ` Kairui Song
2026-10-08 11:52     ` Kairui Song
2026-10-08 12:23       ` Kairui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox