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

From: Kairui Song
Date: Tue Sep 16 2025 - 23:53:15 EST


On Wed, Sep 17, 2025 at 6:31 AM Barry Song <21cnbao@xxxxxxxxx> wrote:
>
> On Wed, Sep 17, 2025 at 12:02 AM Kairui Song <ryncsn@xxxxxxxxx> wrote:
> >
> > From: Kairui Song <kasong@xxxxxxxxxxx>
> >
> > We have a cluster size of 512 slots. Each slot consumes 8 bytes in swap
> > table so the swap table size of each cluster is exactly one page (4K).
> >
> > If that condition is true, allocate one page direct and disable the slab
> > cache to reduce the memory usage of swap table and avoid fragmentation.
> >
> > Co-developed-by: Chris Li <chrisl@xxxxxxxxxx>
> > Signed-off-by: Chris Li <chrisl@xxxxxxxxxx>
> > Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
> > Acked-by: Chris Li <chrisl@xxxxxxxxxx>
>
> looks good to me, with just a minor nit noted below.
>
> Reviewed-by: Barry Song <baohua@xxxxxxxxxx>

Thanks

>
> > ---
> > +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?

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

> Thanks
> Barry