Re: [PATCH v4 15/15] mm, swap: use a single page for swap table when the size fits

From: Barry Song
Date: Wed Sep 17 2025 - 00:51:04 EST


On Wed, Sep 17, 2025 at 12:41 PM Barry Song <21cnbao@xxxxxxxxx> wrote:
>
> > >
> > > > ---
> > > > +static void swap_table_free(struct swap_table *table)
> > > > +{
> > > > + if (!SWP_TABLE_USE_PAGE) {
> > > > + kmem_cache_free(swap_table_cachep, table);
> > > > + return;
> > > > + }
> > > > +
> > > > + call_rcu(&(folio_page(virt_to_folio(table), 0)->rcu_head),
> > > > + swap_table_free_folio_rcu_cb);
> > > > +}
> > >
> > > Can’t it simply be:
> > > virt_to_page(table)->rcu_head ?
> >
> > I'm not sure if we prefer folios when possible?
>
> Not sure either, but even Mathew still sometimes suggests using PAGE:
>
> https://lore.kernel.org/lkml/aLrrQDCBzaMwwmA-@xxxxxxxxxxxxxxxxxxxx/
>
> BTW, "(folio_page(folio), 0)" looks quite strange. I mean, why is it 0
> instead of 1?
> Although we know it’s always one PAGE, 0 still seems strange.

I mean, we should always free an entire folio, right?
It’s impossible to free just one page from a folio unless we split a THP, etc.

So it seems more correct that rcu_head should also be promoted to the folio.

/** @rcu_head: You can use this to free a folio by RCU. */
struct rcu_head rcu_head;

Definitely outside the scope of this patchset, so not a blocker :-)

>
> >
> > Either way is fine, they are identical for this use case.
> >
>

Thanks
Barry