Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: mglru: clear the reference counter for rejected folios
@ 2026-09-07  3:25 Baolin Wang
  2026-09-07  4:28 ` Barry Song
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Baolin Wang @ 2026-09-07  3:25 UTC (permalink / raw)
  To: akpm
  Cc: kasong, qi.zheng, shakeel.butt, baohua, axelrasmussen, yuanchu,
	weixugc, hannes, david, mhocko, ljs, ridong.chen, hebaoquan,
	baolin.wang, linux-mm, linux-kernel

As per the comment on LRU_REFS_FLAGS, when accessed folios are promoted to
a new generation, LRU_REFS_FLAGS should be cleared so that the reference
counter can start over.

For folios rejected by shrink_folio_list(), we clear LRU_REFS_FLAGS and
set the PG_active flag if the rejected folio is planned to be put back to
the oldest generation. That's fine.

But for those that are not put back to the oldest generation (which can
be treated as a promotion), we do not clear LRU_REFS_FLAGS, which can
violate the promotion mechanism. This means the rejected folio enters the
new generation with stale, inflated tier bits, which can inflate reference
counts and distort eviction statistics for these rejected folios.

Fix this by clearing LRU_REFS_FLAGS for rejected folios, and also do some
measurement. On my 32-core Arm machine, with the memcg limit set to 3G,
running 'make -j32' to build the kernel showed a small improvement in sys
time when using either a zram or NVMe swap device (averaged over 2 runs with
no significant variance).

zram swap:
		w/o patch	w/ patch
sys time:	1666.5s		1589.5s

NVMe swap:
		w/o patch	w/patch
sys time:	760s		741.5s

Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
 mm/vmscan.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 40d3f1b48a74..42c0a09938ab 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -5021,10 +5021,11 @@ static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
 		}
 
 		/* don't add rejected folios to the oldest generation */
-		if (lru_gen_folio_seq(lruvec, folio, false) == min_seq[type]) {
-			folio_set_lru_refs(folio, 0);
+		if (lru_gen_folio_seq(lruvec, folio, false) == min_seq[type])
 			folio_set_active(folio);
-		}
+
+		/* See the comments on LRU_REFS_FLAGS */
+		folio_set_lru_refs(folio, 0);
 	}
 
 	move_folios_to_lru(&list);
-- 
2.47.3



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

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

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07  3:25 [PATCH] mm: mglru: clear the reference counter for rejected folios Baolin Wang
2026-09-07  4:28 ` Barry Song
2026-09-07  5:53   ` Baolin Wang
2026-09-07  4:57 ` Kairui Song
2026-09-07  6:27   ` Baolin Wang
2026-09-08  2:30 ` Baoquan He
2026-09-08  2:34   ` Barry Song
2026-09-08  3:03     ` Baolin Wang
2026-09-08  4:01       ` Baolin Wang
2026-09-08  6:59         ` Baoquan He
2026-09-08  7:53           ` Baolin Wang
2026-09-08  8:23             ` Baoquan He
2026-09-08  9:39               ` Baolin Wang
2026-09-08 10:29                 ` Baoquan He

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