Re: [PATCH v8 00/19] mm/mglru: frequency guided promotion (MGLRU-FG) and flag cleanup

From: Andrew Morton

Date: Thu Dec 03 2026 - 13:18:51 EST


On Fri, 04 Dec 2026 01:02:31 +0800 Kairui Song via B4 Relay <devnull+kasong.tencent.com@xxxxxxxxxx> wrote:

> This series implements MGLRU-FG following the idea proposed at LSF/MM/BPF
> this year [1], based on current mm-new. Depending on the workload, it
> improves the performance or reduces IO by roughly 10% to over 50%,
> fixes multiple long-standing issues with MGLRU metrics, and drops one
> page flag.

Thanks, I've updated mm-unstable.

> Changes in v8:
> - I ran a few end to end test, no observable difference from v7 as
> the code is basically identical, but micro benchmarks seems very
> slightly better.
> - Fix Zhengzhuo's tags, collect new tags,
> - Foldin a micro-optimization from Andrew:
> https://lore.kernel.org/linux-mm/20261201192218.3cbb143406a2744a33e555ec@xxxxxxxxxxxxxxxxxxxx/
> - Fix a racy usage of folio_set_workingset in MADV_COLD path, due to a
> rebase mistake in v7.
> - Fix a potential RCU lock warning during intermeidate commits, do not call
> folio_lruvec without holding RCU lock first. Final code is identical.
> And slighty change the patch order, helpers come first, then MGLRU changes.
> - Link to v7: https://patch.msgid.link/20261202-mglru-fg-v7-0-5965a96d86d0@xxxxxxxxxxx

Here's how v8 altered mm.git:


include/linux/mm_inline.h | 22 ++++++++--------------
mm/madvise.c | 2 +-
mm/vmscan.c | 2 +-
3 files changed, 10 insertions(+), 16 deletions(-)

--- a/include/linux/mm_inline.h~b
+++ a/include/linux/mm_inline.h
@@ -464,8 +464,7 @@ static inline bool lru_gen_del_folio(str
int type = folio_is_file_lru(folio);
int zone = folio_zonenum(folio);
int delta = folio_nr_pages(folio);
- enum lru_list lru = folio_is_file_lru(folio) * LRU_INACTIVE_FILE;
- unsigned long max_seq = READ_ONCE(lruvec->lrugen.max_seq);
+ enum lru_list lru = type * LRU_INACTIVE_FILE;

if (lru_get_gen_flags(flags) < 0)
return false;
@@ -482,7 +481,7 @@ static inline bool lru_gen_del_folio(str
gen = lru_get_gen_flags(flags);
refs = lru_get_refs_flags(flags);
new_flags = flags & ~LRU_GEN_MASK;
- if (!reclaiming && ((max_seq - gen) % MAX_NR_GENS) < MIN_NR_GENS)
+ if (!reclaiming && ((lruvec->lrugen.max_seq - gen) % MAX_NR_GENS) < MIN_NR_GENS)
new_flags |= BIT(PG_active);
} while (!try_cmpxchg(folio_flags(folio, 0), &flags, new_flags));

@@ -535,24 +534,19 @@ static inline bool lru_gen_del_folio(str
* lruvec lookup, accounting or promotion. Use folio_mark_accessed()
* everywhere else.
*/
-static __always_inline void folio_inc_lru_refs_fast(struct folio *folio)
+static inline void folio_inc_lru_refs_fast(struct folio *folio)
{
unsigned long new_flags, old_flags = READ_ONCE(*folio_flags(folio, 0));
- unsigned int refs;
- bool has_gen;

BUILD_BUG_ON(LRU_REFS_REFERENCED >= LRU_REFS_ACTIVATED);
do {
- has_gen = lru_get_gen_flags(old_flags) >= 0;
- refs = lru_get_refs_flags(old_flags);
- if (has_gen || lru_gen_enabled()) {
- if (refs)
- break;
- } else if (refs & LRU_REFS_REFERENCED) {
+ if (old_flags & BIT(PG_referenced))
break;
+ if (lru_get_gen_flags(old_flags) >= 0 || lru_gen_enabled()) {
+ if (old_flags & LRU_REFS_FLAGS)
+ break;
}
- new_flags = old_flags;
- lru_set_refs_flags(&new_flags, refs | LRU_REFS_REFERENCED);
+ new_flags = old_flags | BIT(PG_referenced);
} while (!try_cmpxchg(folio_flags(folio, 0), &old_flags, new_flags));
}

--- a/mm/madvise.c~b
+++ a/mm/madvise.c
@@ -380,7 +380,7 @@ static void madvise_cold_prep_folio(stru
if (!lru_gen_enabled()) {
folio_clear_lru_refs(folio);
if (folio_test_active(folio))
- folio_set_workingset(folio);
+ __folio_set_lru_refs(folio, LRU_REFS_WORKINGSET);
} else {
folio_test_clear_young(folio);
}
--- a/mm/vmscan.c~b
+++ a/mm/vmscan.c
@@ -1004,7 +1004,7 @@ bool folio_reset_lru_refs(struct folio *
reset = (gen != lru_gen_from_seq(seq));
if (lru_refs_is_active(refs)) {
enum zone_type zone = folio_zonenum(folio);
- enum lru_list lru = type * LRU_FILE;
+ enum lru_list lru = type * LRU_INACTIVE_FILE;

__update_lru_size_lockless(lruvec, lru + LRU_ACTIVE,
zone, -nr_pages);
_