Re: [PATCH v6 3/3] mm/zswap: reference the pool by id to shrink struct zswap_entry
From: Yosry Ahmed
Date: Sun Sep 06 2026 - 05:34:10 EST
On Sun, Sep 6, 2026 at 12:47 AM Jianyue Wu <wujianyue000@xxxxxxxxx> wrote:
>
> struct zswap_entry is one allocation per stored page, so its size is
> pure overhead. It currently embeds an 8-byte pool pointer, even though
> the live pools now sit in an allocating xarray keyed by a small integer
> id that fits in a u8.
>
> Replace the per-entry pool pointer with that u8 id and resolve it
> through the xarray with xa_load(). xa_load() does its own RCU-protected
> lookup, so the caller needs no rcu_read_lock() section of its own. The
> resolved pool stays valid because a live entry pins it via percpu_ref
> (taken in zswap_store_page()), so its id cannot be reused. A live entry
> never uses the reserved id 0, so a zeroed id resolves to NULL and trips
> a WARN rather than aliasing a live pool.
>
> The u8 fits in the padding after the bool referenced field, shrinking
> the entry from 56 to 48 bytes on 64-bit. This raises objs_per_slab from
> 73 to 85 and saves about 2MiB of metadata per 1GiB of data held in
> zswap.
>
> Suggested-by: Chris Li <chrisl@xxxxxxxxxx>
> Signed-off-by: Jianyue Wu <wujianyue000@xxxxxxxxx>
Acked-by: Yosry Ahmed <yosry@xxxxxxxxxx>