Re: [PATCH v6 08/18] mm/mglru: make folio lru referenced times count a generic API
From: Ridong Chen
Date: Thu Nov 26 2026 - 22:33:24 EST
On 11/27/2026 10:20 AM, Kairui Song wrote:
On Fri, Nov 27, 2026 at 10:01 AM Kairui Song <ryncsn@xxxxxxxxx> wrote:
On Fri, Nov 27, 2026 at 9:48 AM Ridong Chen <ridong.chen@xxxxxxxxx> wrote:
On 11/25/2026 8:36 PM, Kairui Song wrote:
On 11/23/26 19:53, Kairui Song via B4 Relay wrote:Hi David
From: Kairui Song<kasong@xxxxxxxxxxx>I'm starting to feel like all of these mglru/reclaim thingies should go into a
Pure code shuffle, no behavior change.
Make the folio LRU refs helpers available regardless of CONFIG_LRU_GEN.
Without MGLRU the extra bits are never set, so they are inert. Move the
lru_gen_* helpers into the CONFIG_LRU_GEN section. This prepares for
unifying the API for checking folio referenced and workingset status.
folio_migrate_lru_refs() now migrates the complete refs count,
including PG_workingset (bit 1 of the encoding), bitwise identical to
the direct copy dropped from folio_migrate_flags().
lru_set_refs_flags() skips the nonexistent mask bits when
LRU_REFS_WIDTH collapses to 0, preserving the two independent flags for
!CONFIG_LRU_GEN builds.
Tested-by: Zhao Zhenzhuo<zhaozhengzhuo@xxxxxxxxxxxxx>
Reviewed-by: Kunwu Chan<kunwu.chan@xxxxxxxxx>
Tested-by: Andrew Morton<akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Kairui Song<kasong@xxxxxxxxxxx>
---
include/linux/mm_inline.h | 55 ++++++++++++++++++++++++-----------------------
dedicated helper.
I saw your comment on other patches too, about the header mm_inline.h,
about ~690 / 860 lines of code in it is for MGLRU / CLRU only. The
rest ~200 are for VMA / TLB / MMU.
Can you do that as a prio cleanup in this series, so we don't have to mess withPerhaps we can instead move the non LRU helpers in it?
mm_inline.h in later patches anymore?
These helpers:
- anon_vma_name_get
- anon_vma_name_put
- anon_vma_name_reuse
- dup_anon_vma_name
- free_anon_vma_name
- anon_vma_name_eq
- pfnmap_track_ctx_release
- init_tlb_flush_pending
- inc_tlb_flush_pending
- dec_tlb_flush_pending
- mm_tlb_flush_pending
- mm_tlb_flush_nested
- copy_pte_marker
- num_pages_contiguous
All other helper in mm_inline.h are for LRU. So we rename mm_inline.h
to mm_lru.h?
Moving the VMA/TLB helpers out looks good to me as a first step.
For the LRU part, there is already mm/vmscan.h, added by "mm/vmscan:
move struct scan_control to a dedicated header" in mm-new. Most LRU
helpers are only used inside mm/, e.g. lruvec_add_folio(),
lruvec_add_folio_tail(), lru_gen_add_folio() and the refs encoding
helpers, so they could move there instead of staying in a public
header. Barry also suggested moving lruvec_add_folio() and friends
to mm/vmscan.h in another thread.
A few are used outside mm/ and need to stay public:
folio_lru_list() in include/trace/events/pagemap.h, and
folio_test_workingset() in fs/btrfs and fs/erofs after patch 16. So
maybe keep a small public header for those, and move the rest to
mm/vmscan.h, or to a separate mm/mglru.h if it gets too large, as
David mentioned.
I can help with the mm/vmscan.h part if that works for you.
Good idea! Maybe you can send a series to do that which I'll rebase on
top of. Feel free to take the first renaming patch too since they
should all be zero-feature-change :-D
But please help keep some helpers in a public helper so when we are
able to get rid of folio_*_referenced and folio_*_workingset, there
wron't be some strange header inclusion issues. FS users quite often
need to call them, especially the folio refs related ones.
(Considering MGLRU even used to try to completely ignore anon reclaim
at swappiness 200 about a year ago, maybe that isn't too much of a
problem, but it's still a problem).
Sorry my mistake, I meant file reclaim, got it wrong in the opposite way :P
Thinking about it more, the header move is not urgent, while this
series has been iterated for a long time and fixes real problems, e.g.
the swappiness 200 regression you mentioned. Making it depend on a
code shuffle would only delay it.
So if David doesn't object, I would suggest landing MGLRU-FG first,
and doing the mm_inline.h split as a follow-up on top of it. That also
avoids rebasing this large series onto a moving header. I am happy to
work on the follow-up then, keeping the folio refs helpers in a public
header for the fs users as you said.
David, would that work for you?
--
Best regards
Ridong