Re: [PATCH v6 08/18] mm/mglru: make folio lru referenced times count a generic API

From: Kairui Song

Date: Thu Nov 26 2026 - 21:02:19 EST


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:
> >>> From: Kairui Song<kasong@xxxxxxxxxxx>
> >>>
> >>> 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 ++++++++++++++++++++++++-----------------------
> >> I'm starting to feel like all of these mglru/reclaim thingies should go into a
> >> dedicated helper.
> > Hi David
> >
> > 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 with
> >> mm_inline.h in later patches anymore?
> > Perhaps we can instead move the non LRU helpers in it?
> > 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.

Meanwhile I hope we won't take too long to get FG merged because users
with swappiness 200 could experience serious regressions with the
recent swappiness change, and there are already several long standing
/ recent regression that are waiting to be solved by FG :/

(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).