diff options
| author | Jianyue Wu <wujianyue000@gmail.com> | 2026-09-06 15:47:18 +0800 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2026-10-08 22:55:03 -0700 |
| commit | 6ff57b96ab6b471011a6dee5878e4741b70a156f (patch) | |
| tree | 1519846c9577f35b323cb466a251807e41c89f81 /include/linux | |
| parent | b2fb109cb027425b76609a55501ec28f4a791ffc (diff) | |
mm/zswap: replace the zswap_pools list with an allocating xarray
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.
Link: https://lore.kernel.org/20260906-shrink_zswap_entry_v6-v6-2-ac4cf61565fb@gmail.com
Signed-off-by: Jianyue Wu <wujianyue000@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Nhat Pham <nphamcs@gmail.com>
Suggested-by: Yosry Ahmed <yosry@kernel.org>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Yosry Ahmed <yosry@kernel.org>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Chris Li <chrisl@kernel.org>
Diffstat (limited to 'include/linux')
0 files changed, 0 insertions, 0 deletions
