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 --- 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