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

From: Barry Song
Date: Tue Sep 16 2025 - 18:31:44 EST


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>

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

Thanks
Barry