[PATCH RFC 07/32] mm/mglru: don't reset folios LRU refs count on protection by default

From: Kairui Song via B4 Relay

Date: Fri May 01 2026 - 17:07:23 EST


From: Kairui Song <kasong@xxxxxxxxxxx>

Only reset the folio's ref count info when it's being protected from PID
to avoid over protection. No need to clear it if the folio is moved to
younger gen due to other reason.

Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
mm/vmscan.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 026b56828fdb..c6857a933ebf 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3227,7 +3227,7 @@ static int folio_update_gen(struct folio *folio, int new_gen)
}

/* protect pages accessed multiple times through file descriptors */
-static int folio_inc_gen(struct lruvec *lruvec, struct folio *folio)
+static int folio_inc_gen(struct lruvec *lruvec, struct folio *folio, bool reset)
{
int refs;
int type = folio_is_file_lru(folio);
@@ -3247,7 +3247,8 @@ static int folio_inc_gen(struct lruvec *lruvec, struct folio *folio)

new_gen = (old_gen + 1) % MAX_NR_GENS;
lru_gen_set_flags(&new_flags, new_gen);
- lru_refs_set_flags(&new_flags, min(refs, LRU_REFS_WORKINGSET));
+ if (reset)
+ lru_refs_set_flags(&new_flags, min(refs, LRU_REFS_WORKINGSET));
} while (!try_cmpxchg(folio_flags(folio, 0), &old_flags, new_flags));

lru_gen_update_size(lruvec, folio, old_gen, new_gen);
@@ -3861,7 +3862,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness)
VM_WARN_ON_ONCE_FOLIO(folio_is_file_lru(folio) != type, folio);
VM_WARN_ON_ONCE_FOLIO(folio_zonenum(folio) != zone, folio);

- new_gen = folio_inc_gen(lruvec, folio);
+ new_gen = folio_inc_gen(lruvec, folio, false);
list_move_tail(&folio->lru, &lrugen->folios[new_gen][type][zone]);

WRITE_ONCE(lrugen->protected[hist][type][tier],
@@ -4607,7 +4608,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c
if (tier > tier_idx) {
int hist = lru_hist_from_seq(lrugen->min_seq[type]);

- gen = folio_inc_gen(lruvec, folio);
+ gen = folio_inc_gen(lruvec, folio, true);
list_move_tail(&folio->lru, &lrugen->folios[gen][type][zone]);

WRITE_ONCE(lrugen->protected[hist][type][tier],
@@ -4618,7 +4619,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c

/* ineligible */
if (zone > sc->reclaim_idx) {
- gen = folio_inc_gen(lruvec, folio);
+ gen = folio_inc_gen(lruvec, folio, false);
list_move_tail(&folio->lru, &lrugen->folios[gen][type][zone]);
return true;
}

--
2.54.0