Re: [PATCH v6 2/3] mm/zswap: replace the zswap_pools list with an allocating xarray

From: Yosry Ahmed

Date: Sun Sep 06 2026 - 05:33:33 EST


On Sun, Sep 6, 2026 at 12:47 AM Jianyue Wu <wujianyue000@xxxxxxxxx> wrote:
>
> Originally zswap kept its pools on an RCU list whose head also served
> as the current pool. Convert the pool table to an allocating xarray
> keyed by a small integer id, and track the current pool with a separate
> RCU-protected pointer.
>
> The xarray gives each pool a stable id for a later zswap_entry shrink.
> XA_FLAGS_ALLOC1 starts ids at 1, so id 0 remains reserved. The id range
> is bounded by ZSWAP_MAX_POOL_ID because the later entry field is a u8.
>
> Keep compressor switching close to the previous flow: look up an
> existing pool with xa_for_each(), resurrect it if reused, or create a
> new one. zswap_pool_create() allocates the pool's id and publishes it
> into the xarray as its final step, so the create call either fully
> publishes or fully unwinds on failure. Publishing makes the pool live,
> so a caller that later fails (e.g. param_set_charp()) must still kill
> the pool to erase it from the xarray.
>
> Compressor switches update zswap_current_pool with rcu_assign_pointer(),
> serialized by the module parameter lock, so no xa_lock is needed for
> that update. The pool walk above is lockless under RCU. xa_lock is taken
> only to allocate (xa_alloc_bh()) and erase (xa_erase_bh()) xarray
> entries.
>
> Suggested-by: Nhat Pham <nphamcs@xxxxxxxxx>
> Suggested-by: Yosry Ahmed <yosry@xxxxxxxxxx>
> Suggested-by: Johannes Weiner <hannes@xxxxxxxxxxx>
> Signed-off-by: Jianyue Wu <wujianyue000@xxxxxxxxx>

Acked-by: Yosry Ahmed <yosry@xxxxxxxxxx>