Re: [PATCH] mm: move folio LRU helpers out of swap

From: Jianyue Wu

Date: Wed Apr 08 2026 - 10:51:01 EST


On Wed, Apr 08, 2026 at 10:49:12AM +0800, Baoquan He wrote:
> On 04/08/26 at 10:20am, Barry Song wrote:
> > On Wed, Apr 8, 2026 at 9:39 AM Baoquan He <bhe@xxxxxxxxxx> wrote:
> > >
> > > On 04/07/26 at 10:22am, Johannes Weiner wrote:
> > > > On Tue, Apr 07, 2026 at 07:00:02PM +0800, Jianyue Wu wrote:
> > > > > All allocated folios are added into lru lists for later reclaim whether
> > > > > they are file or anonymous folios. However those folio lru operation codes
> > > > > are put in mm/swap.c which is not so appropriate. Because swap code is
> > > > > only for anonymous folios.
> > > >
> > > > Ironically, the only thing that doesn't fit in this file is the swap
> > > > stuff. The page_cluster & sysctl should be static in swap_state.c.
> > > >
> > > > The rest seems thematically relatively clean - infrastructure for
> > > > managing folio lifetime. swap.c is not the best name for it, but short
> > > > of finding a very clear improvement I'd just leave it alone.
> > >
> > > Can't agree more. We should move page_cluster & sysctl and swap_setup()
> > > to mm/swap_state.c, and rename mm/swap.c to mm/folio_lru.c or something
> > > like that.
> >
> > Another issue is that many MM-internal items are placed in the
> > top-level include/linux/swap.h, which is supposed to be used by
> > code outside the MM subsystem as well.
> >
> > For example, the following are actually MM-internal:
> >
> > extern int vm_swappiness;
> > swap_setup();
> > workingset_*();
> > try_to_free_pages();
> > zone_reclaimable_pages();
> > lruvec_lru_size();
> > try_to_free_mem_cgroup_pages();
> > ...
>
> Ah, indeed. Seems we have been putting generic code related to reclaim into
> swap.h|.c due to historic reason. From discussion, I think the below
> three things are doable.
>
> 1) move page_cluster & sysctl and swap_setup() into mm/swap_state.c
> because page_cluster is only used in mm/swap_state.c as Johannes
> suggestd. And swap_setup() may need be renamed too?
>
> 2) rename mm/swap.c to mm/folio_lru.c or something like that to reflect
> its real content;
>
> 3) Just Barry pointed out, move generic code related to reclaim out of
> include/linux/swap.h e.g move into mm/internal.h if they are only
> called inside mm/ folder,
>
> Thanks
> Baoquan
>

Thank you all for the hint and the summary.

This direction looks reasonable to me. I'll start with moving page_cluster
and the related sysctl into mm/swap_state.c, and see how swap_setup()
should be adjusted accordingly.

For the other parts, especially the header cleanup, I'll take a closer look
and follow up with patches.

Best regards,
Jianyue Wu