* [PATCH 0/4] mm/mglru: cleanup series and a small correctness
@ 2026-12-02 6:17 Baoquan He
2026-12-02 6:17 ` [PATCH 1/4] mm/mglru: use a common helper to check evictable type Baoquan He
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Baoquan He @ 2026-12-02 6:17 UTC (permalink / raw)
To: linux-mm
Cc: akpm, kasong, baohua, qi.zheng, shakeel.butt, baoquan.he,
baolin.wang, hannes, mhocko
Four small cleanups in the MGLRU reclaim path. Three of them are pure
refactoring with no behaviour change; the fourth corrects a vmstat
counter that was being fed the wrong thing.
Baoquan He (4):
mm/mglru: use a common helper to check evictable type
mm/mglru: rename positive_ctrl_err() to should_reclaim()
mm/mglru: split reset_ctrl_pos() into _update and _reset
mm/mglru: stop counting isolation races as PGSCAN_SKIP in
scan_folios()
mm/vmscan.c | 118 +++++++++++++++++++++++++++++++---------------------
1 file changed, 70 insertions(+), 48 deletions(-)
--
2.52.0
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH 1/4] mm/mglru: use a common helper to check evictable type 2026-12-02 6:17 [PATCH 0/4] mm/mglru: cleanup series and a small correctness Baoquan He @ 2026-12-02 6:17 ` Baoquan He 2026-12-02 6:41 ` Barry Song 2026-12-02 6:17 ` [PATCH 2/4] mm/mglru: rename positive_ctrl_err() to should_reclaim() Baoquan He ` (2 subsequent siblings) 3 siblings, 1 reply; 11+ messages in thread From: Baoquan He @ 2026-12-02 6:17 UTC (permalink / raw) To: linux-mm Cc: akpm, kasong, baohua, qi.zheng, shakeel.butt, baoquan.he, baolin.wang, hannes, mhocko, Baoquan He From: Baoquan He <hebaoquan@kylinos.cn> inc_min_seq() open-codes the evictable type check that for_each_evictable_type() already expresses through min_type() and max_type(). Use a shared is_type_evictable() helper so the two cannot drift apart, and rename the done label to advance to make it clear that a skipped rotation still advances min_seq. No functional change. Signed-off-by: Baoquan He <hebaoquan@kylinos.cn> --- mm/vmscan.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index be89bc2528a9..257305fe1cce 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2785,6 +2785,11 @@ static bool should_clear_pmd_young(void) #define min_type(swappiness) (!(swappiness)) #define max_type(swappiness) ((swappiness) < SWAPPINESS_ANON_ONLY) +static inline bool is_type_evictable(int type, int swappiness) +{ + return type >= min_type(swappiness) && type <= max_type(swappiness); +} + #define evictable_min_seq(min_seq, swappiness) \ min((min_seq)[min_type(swappiness)], (min_seq)[max_type(swappiness)]) @@ -3976,13 +3981,9 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) int new_gen, old_gen = lru_gen_from_seq(lrugen->min_seq[type]); int target_gen = (old_gen + 1) % MAX_NR_GENS; - /* For file type, skip the check if swappiness is anon only */ - if (type && (swappiness == SWAPPINESS_ANON_ONLY)) - goto done; - - /* For anon type, skip the check if swappiness is zero (file only) */ - if (!type && !swappiness) - goto done; + /* A type that isn't being reclaimed needs no rotation */ + if (!is_type_evictable(type, swappiness)) + goto advance; VM_WARN_ON_ONCE(get_nr_gens(lruvec, type) != MAX_NR_GENS); VM_WARN_ON_ONCE(lru_gen_is_active(lruvec, old_gen) != @@ -4042,7 +4043,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) if (!remaining) return false; } -done: +advance: reset_ctrl_pos(lruvec, type, true); WRITE_ONCE(lrugen->min_seq[type], lrugen->min_seq[type] + 1); -- 2.52.0 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/4] mm/mglru: use a common helper to check evictable type 2026-12-02 6:17 ` [PATCH 1/4] mm/mglru: use a common helper to check evictable type Baoquan He @ 2026-12-02 6:41 ` Barry Song 2026-12-02 8:43 ` Baoquan He 0 siblings, 1 reply; 11+ messages in thread From: Barry Song @ 2026-12-02 6:41 UTC (permalink / raw) To: Baoquan He Cc: linux-mm, akpm, kasong, qi.zheng, shakeel.butt, baolin.wang, hannes, mhocko, Baoquan He On Wed, Dec 2, 2026 at 2:17 PM Baoquan He <baoquan.he@linux.dev> wrote: > > From: Baoquan He <hebaoquan@kylinos.cn> > > inc_min_seq() open-codes the evictable type check that > for_each_evictable_type() already expresses through min_type() and > max_type(). Use a shared is_type_evictable() helper so the two cannot > drift apart, and rename the done label to advance to make it clear that > a skipped rotation still advances min_seq. > > No functional change. > > Signed-off-by: Baoquan He <hebaoquan@kylinos.cn> > --- > mm/vmscan.c | 17 +++++++++-------- > 1 file changed, 9 insertions(+), 8 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index be89bc2528a9..257305fe1cce 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -2785,6 +2785,11 @@ static bool should_clear_pmd_young(void) > #define min_type(swappiness) (!(swappiness)) > #define max_type(swappiness) ((swappiness) < SWAPPINESS_ANON_ONLY) > > +static inline bool is_type_evictable(int type, int swappiness) > +{ > + return type >= min_type(swappiness) && type <= max_type(swappiness); > +} > + To be honest, I find this quite hard to follow. Can't we just say something more explicit, like this? is_type_unevictable: ((type == LRU_GEN_FILE) && (swappiness == SWAPPINESS_ANON_ONLY)) || ((type == LRU_GEN_ANON) && !swappiness) Thanks, Barry ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/4] mm/mglru: use a common helper to check evictable type 2026-12-02 6:41 ` Barry Song @ 2026-12-02 8:43 ` Baoquan He 2026-12-02 21:49 ` Andrew Morton 0 siblings, 1 reply; 11+ messages in thread From: Baoquan He @ 2026-12-02 8:43 UTC (permalink / raw) To: Barry Song Cc: linux-mm, akpm, kasong, qi.zheng, shakeel.butt, baolin.wang, hannes, mhocko, Baoquan He On 12/02/26 at 02:41pm, Barry Song wrote: > On Wed, Dec 2, 2026 at 2:17 PM Baoquan He <baoquan.he@linux.dev> wrote: > > > > From: Baoquan He <hebaoquan@kylinos.cn> > > > > inc_min_seq() open-codes the evictable type check that > > for_each_evictable_type() already expresses through min_type() and > > max_type(). Use a shared is_type_evictable() helper so the two cannot > > drift apart, and rename the done label to advance to make it clear that > > a skipped rotation still advances min_seq. > > > > No functional change. > > > > Signed-off-by: Baoquan He <hebaoquan@kylinos.cn> > > --- > > mm/vmscan.c | 17 +++++++++-------- > > 1 file changed, 9 insertions(+), 8 deletions(-) > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index be89bc2528a9..257305fe1cce 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -2785,6 +2785,11 @@ static bool should_clear_pmd_young(void) > > #define min_type(swappiness) (!(swappiness)) > > #define max_type(swappiness) ((swappiness) < SWAPPINESS_ANON_ONLY) > > > > +static inline bool is_type_evictable(int type, int swappiness) > > +{ > > + return type >= min_type(swappiness) && type <= max_type(swappiness); > > +} > > + > > To be honest, I find this quite hard to follow. Can't we just say > something more explicit, like this? LOL, I know people must complain about this. It's truly logically twisted so that mglru expert need think a while to make it clear, I like it a bit though, it's correct and neat. I will update it as you suggested. Thanks for careful reviewing, and sorry for the code, Barry. > > is_type_unevictable: > > ((type == LRU_GEN_FILE) && (swappiness == SWAPPINESS_ANON_ONLY)) > || > ((type == LRU_GEN_ANON) && !swappiness) > > > Thanks, > Barry ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/4] mm/mglru: use a common helper to check evictable type 2026-12-02 8:43 ` Baoquan He @ 2026-12-02 21:49 ` Andrew Morton 0 siblings, 0 replies; 11+ messages in thread From: Andrew Morton @ 2026-12-02 21:49 UTC (permalink / raw) To: Baoquan He Cc: Barry Song, linux-mm, kasong, qi.zheng, shakeel.butt, baolin.wang, hannes, mhocko, Baoquan He On Wed, 2 Dec 2026 16:43:19 +0800 Baoquan He <baoquan.he@linux.dev> wrote: > I will update it as you suggested. Whimper. mm.git presently has 56 patches which mention mglru in their changelogs. Can I ask that we defer new changes and focus on what we have now? ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/4] mm/mglru: rename positive_ctrl_err() to should_reclaim() 2026-12-02 6:17 [PATCH 0/4] mm/mglru: cleanup series and a small correctness Baoquan He 2026-12-02 6:17 ` [PATCH 1/4] mm/mglru: use a common helper to check evictable type Baoquan He @ 2026-12-02 6:17 ` Baoquan He 2026-12-02 9:59 ` Barry Song (Xiaomi) 2026-12-02 6:17 ` [PATCH 3/4] mm/mglru: split reset_ctrl_pos() into _update and _reset Baoquan He 2026-12-02 6:20 ` [PATCH 4/4] mm/mglru: stop counting isolation races as PGSCAN_SKIP in scan_folios() Baoquan He 3 siblings, 1 reply; 11+ messages in thread From: Baoquan He @ 2026-12-02 6:17 UTC (permalink / raw) To: linux-mm Cc: akpm, kasong, baohua, qi.zheng, shakeel.butt, baoquan.he, baolin.wang, hannes, mhocko, Baoquan He From: Baoquan He <hebaoquan@kylinos.cn> positive_ctrl_err() is named after control-theory jargon, which obscures what the function actually asks: whether the candidate position (pv) is worth reclaiming, i.e. it has a limited number of refaults or a lower refaulted/total than the current position (sp). Rename it to should_reclaim() so the reclaim decision is self-evident at its call site. Signed-off-by: Baoquan He <hebaoquan@kylinos.cn> --- mm/vmscan.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 257305fe1cce..ab5ba9997bd5 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3298,11 +3298,12 @@ static void reset_ctrl_pos(struct lruvec *lruvec, int type, bool carryover) } } -static bool positive_ctrl_err(struct ctrl_pos *sp, struct ctrl_pos *pv) +static bool should_reclaim(struct ctrl_pos *sp, struct ctrl_pos *pv) { /* - * Return true if the PV has a limited number of refaults or a lower - * refaulted/total than the SP. + * Return true if the candidate (PV) is worth reclaiming: it has a + * limited number of refaults, or a lower refaulted/total than the + * current position (SP). */ return pv->refaulted < MIN_LRU_BATCH || pv->refaulted * (sp->total + MIN_LRU_BATCH) * sp->gain <= @@ -4944,7 +4945,7 @@ static int get_tier_idx(struct lruvec *lruvec, int type) read_ctrl_pos(lruvec, type, LRU_TIER_MIN, LRU_TIER_MIN, 2, &sp); for (tier = LRU_TIER_MIN + 1; tier <= LRU_TIER_MAX; tier++) { read_ctrl_pos(lruvec, type, tier, tier, 3, &pv); - if (!positive_ctrl_err(&sp, &pv)) + if (!should_reclaim(&sp, &pv)) break; } -- 2.52.0 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/4] mm/mglru: rename positive_ctrl_err() to should_reclaim() 2026-12-02 6:17 ` [PATCH 2/4] mm/mglru: rename positive_ctrl_err() to should_reclaim() Baoquan He @ 2026-12-02 9:59 ` Barry Song (Xiaomi) 0 siblings, 0 replies; 11+ messages in thread From: Barry Song (Xiaomi) @ 2026-12-02 9:59 UTC (permalink / raw) To: baoquan.he Cc: akpm, baohua, baolin.wang, hannes, hebaoquan, kasong, linux-mm, mhocko, qi.zheng, shakeel.butt On Wed, Dec 2, 2026 at 2:17 PM Baoquan He <baoquan.he@linux.dev> wrote: > > From: Baoquan He <hebaoquan@kylinos.cn> > > positive_ctrl_err() is named after control-theory jargon, which > obscures what the function actually asks: whether the candidate position > (pv) is worth reclaiming, i.e. it has a limited number of refaults or a > lower refaulted/total than the current position (sp). > > Rename it to should_reclaim() so the reclaim decision is self-evident at > its call site. Yes, I agree we should definitely do something here. But simply renaming the function to should_reclaim() doesn't seem sufficient. Perhaps we could make things much clearer by doing something like this? diff --git a/mm/vmscan.c b/mm/vmscan.c index 443ee5d30531..65a0ae024524 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3483,7 +3483,7 @@ static bool iterate_mm_list_nowalk(struct lruvec *lruvec, unsigned long seq) * 1. The D term may discount the other two terms over time so that long-lived * generations can resist stale information. */ -struct ctrl_pos { +struct refault_stats { unsigned long refaulted; unsigned long total; int gain; @@ -3492,8 +3492,8 @@ struct ctrl_pos { /* * __noipa works around gcc-16 warning for uninitialized use of pos->refaulted */ -static void __noipa read_ctrl_pos(struct lruvec *lruvec, int type, int tier_min, - int tier_max, int gain, struct ctrl_pos *pos) +static void __noipa read_refault_stats(struct lruvec *lruvec, int type, int tier_min, + int tier_max, int gain, struct refault_stats *pos) { int i; struct lru_gen_folio *lrugen = &lruvec->lrugen; @@ -3511,7 +3511,7 @@ static void __noipa read_ctrl_pos(struct lruvec *lruvec, int type, int tier_min, } } -static void reset_ctrl_pos(struct lruvec *lruvec, int type, bool carryover) +static void reset_refault_stats(struct lruvec *lruvec, int type, bool carryover) { int hist, tier; struct lru_gen_folio *lrugen = &lruvec->lrugen; @@ -3547,8 +3547,10 @@ static void reset_ctrl_pos(struct lruvec *lruvec, int type, bool carryover) } } -static bool positive_ctrl_err(struct ctrl_pos *sp, struct ctrl_pos *pv) +static bool can_reclaim_tier(struct refault_stats *base, struct refault_stats *cand) { + struct refault_stats *sp = base, *pv = cand; + /* * Return true if the PV has a limited number of refaults or a lower * refaulted/total than the SP. @@ -4288,7 +4290,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) return false; } done: - reset_ctrl_pos(lruvec, type, true); + reset_refault_stats(lruvec, type, true); WRITE_ONCE(lrugen->min_seq[type], lrugen->min_seq[type] + 1); return true; @@ -4354,7 +4356,7 @@ static void try_to_inc_min_seq(struct lruvec *lruvec, int swappiness) if (min_seq[type] <= lrugen->min_seq[type]) continue; - reset_ctrl_pos(lruvec, type, true); + reset_refault_stats(lruvec, type, true); WRITE_ONCE(lrugen->min_seq[type], min_seq[type]); } } @@ -4389,7 +4391,7 @@ static bool inc_max_seq(struct lruvec *lruvec, unsigned long seq, int swappiness } for (type = 0; type < ANON_AND_FILE; type++) - reset_ctrl_pos(lruvec, type, false); + reset_refault_stats(lruvec, type, false); next = lru_gen_from_seq(lrugen->max_seq + 1); WRITE_ONCE(lrugen->timestamps[next], jiffies); @@ -5193,7 +5195,7 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, static int get_tier_idx(struct lruvec *lruvec, int type) { int tier; - struct ctrl_pos sp, pv; + struct refault_stats base, cand; /* * To leave a margin for fluctuations, use a larger gain factor (1:2). @@ -5202,9 +5204,9 @@ static int get_tier_idx(struct lruvec *lruvec, int type) * protects the tiers above it. */ for (tier = LRU_TIER_MIN + 1; tier <= LRU_TIER_MAX; tier++) { - read_ctrl_pos(lruvec, type, LRU_TIER_MIN, tier - 1, 1, &sp); - read_ctrl_pos(lruvec, type, tier, tier, 2, &pv); - if (!positive_ctrl_err(&sp, &pv)) + read_refault_stats(lruvec, type, LRU_TIER_MIN, tier - 1, 1, &base); + read_refault_stats(lruvec, type, tier, tier, 2, &cand); + if (!can_reclaim_tier(&base, &cand)) break; } ^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/4] mm/mglru: split reset_ctrl_pos() into _update and _reset 2026-12-02 6:17 [PATCH 0/4] mm/mglru: cleanup series and a small correctness Baoquan He 2026-12-02 6:17 ` [PATCH 1/4] mm/mglru: use a common helper to check evictable type Baoquan He 2026-12-02 6:17 ` [PATCH 2/4] mm/mglru: rename positive_ctrl_err() to should_reclaim() Baoquan He @ 2026-12-02 6:17 ` Baoquan He 2026-12-02 10:12 ` Barry Song 2026-12-02 6:20 ` [PATCH 4/4] mm/mglru: stop counting isolation races as PGSCAN_SKIP in scan_folios() Baoquan He 3 siblings, 1 reply; 11+ messages in thread From: Baoquan He @ 2026-12-02 6:17 UTC (permalink / raw) To: linux-mm Cc: akpm, kasong, baohua, qi.zheng, shakeel.butt, baoquan.he, baolin.wang, hannes, mhocko, Baoquan He From: Baoquan He <hebaoquan@kylinos.cn> The single function reset_ctrl_pos() handled two opposite operations controlled by a boolean 'carryover' flag: - carryover=true: fold retiring generation stats into the EMA, and optionally clear the slot (from inc_min_seq) - carryover=false: clear the slot for a new generation (from inc_max_seq) The boolean also controlled which seq to use (min_seq or max_seq+1) and whether to early-return. This made the logic unnecessarily twisted. Split it into two self-explanatory functions: - lru_gen_update_ctrl(): fold stats into EMA when retiring an old generation; also clears the single history slot when NR_HIST_GENS==1. - lru_gen_reset_ctrl(): clear the slot for the upcoming new generation; no-op when NR_HIST_GENS==1 since _update already handled it. No functional change. Signed-off-by: Baoquan He <hebaoquan@kylinos.cn> --- mm/vmscan.c | 76 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index ab5ba9997bd5..9211ffcdcea9 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3262,42 +3262,66 @@ static void __noipa read_ctrl_pos(struct lruvec *lruvec, int type, int tier_min, } } -static void reset_ctrl_pos(struct lruvec *lruvec, int type, bool carryover) +/* + * Fold the retiring generation's controller statistics into the running + * exponential moving average. Called when evicting an old generation + * (from inc_min_seq and try_to_inc_min_seq). + * + * With NR_HIST_GENS==1, the single slot must also be cleared for reuse. + */ +static void lru_gen_update_ctrl(struct lruvec *lruvec, int type) { - int hist, tier; + int tier; struct lru_gen_folio *lrugen = &lruvec->lrugen; - bool clear = carryover ? NR_HIST_GENS == 1 : NR_HIST_GENS > 1; - unsigned long seq = carryover ? lrugen->min_seq[type] : lrugen->max_seq + 1; + int hist_idx = lru_hist_from_seq(lrugen->min_seq[type]); lockdep_assert_held(&lruvec->lru_lock); - if (!carryover && !clear) - return; - - hist = lru_hist_from_seq(seq); - for (tier = 0; tier < MAX_NR_TIERS; tier++) { - if (carryover) { - unsigned long sum; + unsigned long sum; - sum = lrugen->avg_refaulted[type][tier] + - atomic_long_read(&lrugen->refaulted[hist][type][tier]); - WRITE_ONCE(lrugen->avg_refaulted[type][tier], sum / 2); + sum = lrugen->avg_refaulted[type][tier] + + atomic_long_read(&lrugen->refaulted[hist_idx][type][tier]); + WRITE_ONCE(lrugen->avg_refaulted[type][tier], sum / 2); - sum = lrugen->avg_total[type][tier] + - lrugen->protected[hist][type][tier] + - atomic_long_read(&lrugen->evicted[hist][type][tier]); - WRITE_ONCE(lrugen->avg_total[type][tier], sum / 2); - } + sum = lrugen->avg_total[type][tier] + + lrugen->protected[hist_idx][type][tier] + + atomic_long_read(&lrugen->evicted[hist_idx][type][tier]); + WRITE_ONCE(lrugen->avg_total[type][tier], sum / 2); - if (clear) { - atomic_long_set(&lrugen->refaulted[hist][type][tier], 0); - atomic_long_set(&lrugen->evicted[hist][type][tier], 0); - WRITE_ONCE(lrugen->protected[hist][type][tier], 0); + if (NR_HIST_GENS == 1) { + atomic_long_set(&lrugen->refaulted[hist_idx][type][tier], 0); + atomic_long_set(&lrugen->evicted[hist_idx][type][tier], 0); + WRITE_ONCE(lrugen->protected[hist_idx][type][tier], 0); } } } +/* + * Clear the controller statistics slot for the upcoming new generation. + * Called when opening a new generation (from inc_max_seq). + * + * With NR_HIST_GENS==1, there is nothing to do â the single slot was + * already cleared by lru_gen_update_ctrl(). + */ +static void lru_gen_reset_ctrl(struct lruvec *lruvec, int type) +{ + int tier; + struct lru_gen_folio *lrugen = &lruvec->lrugen; + int hist_idx = lru_hist_from_seq(lrugen->max_seq + 1); + + lockdep_assert_held(&lruvec->lru_lock); + + if (NR_HIST_GENS == 1) + return; + + for (tier = 0; tier < MAX_NR_TIERS; tier++) { + atomic_long_set(&lrugen->refaulted[hist_idx][type][tier], 0); + atomic_long_set(&lrugen->evicted[hist_idx][type][tier], 0); + WRITE_ONCE(lrugen->protected[hist_idx][type][tier], 0); + } +} + static bool should_reclaim(struct ctrl_pos *sp, struct ctrl_pos *pv) { /* @@ -4045,7 +4069,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) return false; } advance: - reset_ctrl_pos(lruvec, type, true); + lru_gen_update_ctrl(lruvec, type); WRITE_ONCE(lrugen->min_seq[type], lrugen->min_seq[type] + 1); return true; @@ -4111,7 +4135,7 @@ static void try_to_inc_min_seq(struct lruvec *lruvec, int swappiness) if (min_seq[type] <= lrugen->min_seq[type]) continue; - reset_ctrl_pos(lruvec, type, true); + lru_gen_update_ctrl(lruvec, type); WRITE_ONCE(lrugen->min_seq[type], min_seq[type]); } } @@ -4170,7 +4194,7 @@ static bool inc_max_seq(struct lruvec *lruvec, unsigned long seq, int swappiness } for (type = 0; type < ANON_AND_FILE; type++) - reset_ctrl_pos(lruvec, type, false); + lru_gen_reset_ctrl(lruvec, type); WRITE_ONCE(lrugen->timestamps[next], jiffies); /* make sure preceding modifications appear */ -- 2.52.0 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 3/4] mm/mglru: split reset_ctrl_pos() into _update and _reset 2026-12-02 6:17 ` [PATCH 3/4] mm/mglru: split reset_ctrl_pos() into _update and _reset Baoquan He @ 2026-12-02 10:12 ` Barry Song 0 siblings, 0 replies; 11+ messages in thread From: Barry Song @ 2026-12-02 10:12 UTC (permalink / raw) To: Baoquan He Cc: linux-mm, akpm, kasong, qi.zheng, shakeel.butt, baolin.wang, hannes, mhocko, Baoquan He On Wed, Dec 2, 2026 at 2:17 PM Baoquan He <baoquan.he@linux.dev> wrote: > > From: Baoquan He <hebaoquan@kylinos.cn> > > The single function reset_ctrl_pos() handled two opposite operations > controlled by a boolean 'carryover' flag: > > - carryover=true: fold retiring generation stats into the EMA, > and optionally clear the slot (from inc_min_seq) > - carryover=false: clear the slot for a new generation > (from inc_max_seq) > > The boolean also controlled which seq to use (min_seq or max_seq+1) > and whether to early-return. This made the logic unnecessarily twisted. > > Split it into two self-explanatory functions: > > - lru_gen_update_ctrl(): fold stats into EMA when retiring an > old generation; also clears the single history slot when > NR_HIST_GENS==1. > > - lru_gen_reset_ctrl(): clear the slot for the upcoming new > generation; no-op when NR_HIST_GENS==1 since _update already > handled it. > If we revise patch 2 along the lines of: https://lore.kernel.org/linux-mm/20261202095957.52379-1-baohua@kernel.org/ we would end up with the following names here: update_refault_stats() reset_refault_stats() Let's try to hide all the control-theory details inside the helpers. LRU callers shouldn't need to know anything about "ctrl". The interfaces should expose only LRU-related semantics. Thanks, Barry ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 4/4] mm/mglru: stop counting isolation races as PGSCAN_SKIP in scan_folios() 2026-12-02 6:17 [PATCH 0/4] mm/mglru: cleanup series and a small correctness Baoquan He ` (2 preceding siblings ...) 2026-12-02 6:17 ` [PATCH 3/4] mm/mglru: split reset_ctrl_pos() into _update and _reset Baoquan He @ 2026-12-02 6:20 ` Baoquan He 2026-12-02 9:22 ` Barry Song 3 siblings, 1 reply; 11+ messages in thread From: Baoquan He @ 2026-12-02 6:20 UTC (permalink / raw) To: linux-mm Cc: akpm, kasong, baohua, qi.zheng, shakeel.butt, baoquan.he, baolin.wang, hannes, mhocko, Baoquan He From: Baoquan He <hebaoquan@kylinos.cn> scan_folios() counted pages it failed to isolate because of a race (folio_try_get() or folio_test_clear_lru() failed) and reported them as PGSCAN_SKIP and nr_skipped. PGSCAN_SKIP is for pages skipped because they sit in zones above the reclaim target. MGLRU only iterates zones at or below that target, so it never has ineligible-zone pages at all; the only thing that fed PGSCAN_SKIP here was isolation races, which misrepresents the counter. Rename skipped_zone to isolate_failed and drop the PGSCAN_SKIP accounting. nr_skipped is passed as 0: the field is kept so the event still lines up with mm_vmscan_lru_isolate, and the races themselves are transient, the folios go back to the generation list and are retried. Signed-off-by: Baoquan He <hebaoquan@kylinos.cn> --- mm/vmscan.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9211ffcdcea9..9894221cbb6d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4867,7 +4867,6 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, int sorted = 0; int scanned = 0; int isolated = 0; - int skipped = 0; int gen, max_gen; unsigned long seq; unsigned long remaining = nr_to_scan; @@ -4901,7 +4900,7 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, /* Scan eligible zones in descending order. */ for (zone_idx = sc->reclaim_idx; zone_idx >= 0; zone_idx--) { LIST_HEAD(moved); - int skipped_zone = 0; + int isolate_failed = 0; struct zone *zone = &pgdat->node_zones[zone_idx]; struct list_head *head = &lrugen->folios[gen][type][zone_idx]; @@ -4925,18 +4924,15 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, isolated += delta; } else { list_move(&folio->lru, &moved); - skipped_zone += delta; + isolate_failed += delta; } - if (!--remaining || max(isolated, skipped_zone) >= MIN_LRU_BATCH) + if (!--remaining || max(isolated, isolate_failed) >= MIN_LRU_BATCH) break; } - if (skipped_zone) { + if (isolate_failed) list_splice(&moved, head); - __count_zid_vm_events(PGSCAN_SKIP, zone_idx, skipped_zone); - skipped += skipped_zone; - } if (!remaining || isolated >= MIN_LRU_BATCH) break; @@ -4947,10 +4943,10 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, mod_lruvec_state(lruvec, PGREFILL, sorted); mod_lruvec_state(lruvec, PGSCAN_ANON + type, isolated); trace_mm_vmscan_lru_isolate(sc, nr_to_scan, - scanned, skipped, isolated, + scanned, 0, isolated, type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); trace_mm_mglru_scan_folios(lruvec, sc, nr_to_scan, scanned, sorted, - skipped, isolated, type, tier); + 0, isolated, type, tier); *isolatedp = isolated; return scanned; -- 2.52.0 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 4/4] mm/mglru: stop counting isolation races as PGSCAN_SKIP in scan_folios() 2026-12-02 6:20 ` [PATCH 4/4] mm/mglru: stop counting isolation races as PGSCAN_SKIP in scan_folios() Baoquan He @ 2026-12-02 9:22 ` Barry Song 0 siblings, 0 replies; 11+ messages in thread From: Barry Song @ 2026-12-02 9:22 UTC (permalink / raw) To: Baoquan He Cc: linux-mm, akpm, kasong, qi.zheng, shakeel.butt, baolin.wang, hannes, mhocko, Baoquan He On Wed, Dec 2, 2026 at 2:20 PM Baoquan He <baoquan.he@linux.dev> wrote: > > From: Baoquan He <hebaoquan@kylinos.cn> > > scan_folios() counted pages it failed to isolate because of a race > (folio_try_get() or folio_test_clear_lru() failed) and reported them as > PGSCAN_SKIP and nr_skipped. > > PGSCAN_SKIP is for pages skipped because they sit in zones above the > reclaim target. MGLRU only iterates zones at or below that target, so it > never has ineligible-zone pages at all; the only thing that fed > PGSCAN_SKIP here was isolation races, which misrepresents the counter. > Yes, it doesn't seem particularly useful for MGLRU now, since we have separate lists for each zone, whereas CLRU uses (folio_zonenum(folio) > sc->reclaim_idx) to skip ineligible folios in a shared list. > Rename skipped_zone to isolate_failed and drop the PGSCAN_SKIP > accounting. nr_skipped is passed as 0: the field is kept so the event > still lines up with mm_vmscan_lru_isolate, and the races themselves are > transient, the folios go back to the generation list and are retried. [...] > @@ -4947,10 +4943,10 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, > mod_lruvec_state(lruvec, PGREFILL, sorted); > mod_lruvec_state(lruvec, PGSCAN_ANON + type, isolated); > trace_mm_vmscan_lru_isolate(sc, nr_to_scan, > - scanned, skipped, isolated, > + scanned, 0, isolated, Maybe we could use this argument to trace isolate_failed instead of always setting it to 0? The tracepoint is still in mm-new and hasn't reached mainline yet, so we should still have time to get your change in? Thanks, Barry ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-12-02 21:49 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 6:17 [PATCH 0/4] mm/mglru: cleanup series and a small correctness Baoquan He 2026-12-02 6:17 ` [PATCH 1/4] mm/mglru: use a common helper to check evictable type Baoquan He 2026-12-02 6:41 ` Barry Song 2026-12-02 8:43 ` Baoquan He 2026-12-02 21:49 ` Andrew Morton 2026-12-02 6:17 ` [PATCH 2/4] mm/mglru: rename positive_ctrl_err() to should_reclaim() Baoquan He 2026-12-02 9:59 ` Barry Song (Xiaomi) 2026-12-02 6:17 ` [PATCH 3/4] mm/mglru: split reset_ctrl_pos() into _update and _reset Baoquan He 2026-12-02 10:12 ` Barry Song 2026-12-02 6:20 ` [PATCH 4/4] mm/mglru: stop counting isolation races as PGSCAN_SKIP in scan_folios() Baoquan He 2026-12-02 9:22 ` Barry Song
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.