[RFC PATCH v4 06/16] mm/mglru: batch update lrugen->protected in inc_min_seq()
From: Barry Song (Xiaomi)
Date: Wed Aug 12 2026 - 08:24:09 EST
Avoid updating lrugen->protected with WRITE_ONCE() for each folio,
which may prevent potential compiler optimizations. Accumulate the
updates locally and apply them in a batch instead.
Signed-off-by: Barry Song (Xiaomi) <baohua@xxxxxxxxxx>
---
mm/vmscan.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index c6e3b92c8cae..10f690389f5d 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3930,7 +3930,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness)
/* prevent cold/hot inversion if the type is evictable */
for (zone = 0; zone < MAX_NR_ZONES; zone++) {
struct list_head *head = &lrugen->folios[old_gen][type][zone];
- unsigned long delta = 0;
+ unsigned long protected[MAX_NR_TIERS] = {}, delta = 0;
while (!list_empty(head)) {
struct folio *folio = lru_to_folio(head);
@@ -3952,8 +3952,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness)
if (refs + workingset != BIT(LRU_REFS_WIDTH) + 1) {
int tier = lru_tier_from_refs(refs, workingset);
- WRITE_ONCE(lrugen->protected[hist][type][tier],
- lrugen->protected[hist][type][tier] + nr_pages);
+ protected[tier] += nr_pages;
}
if (!--remaining)
@@ -3963,6 +3962,9 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness)
lrugen->nr_pages[old_gen][type][zone] - delta);
WRITE_ONCE(lrugen->nr_pages[target_gen][type][zone],
lrugen->nr_pages[target_gen][type][zone] + delta);
+ for (int tier = 0; tier < MAX_NR_TIERS; tier++)
+ WRITE_ONCE(lrugen->protected[hist][type][tier],
+ lrugen->protected[hist][type][tier] + protected[tier]);
if (!remaining)
return false;
}
--
2.34.1