[PATCH v6 0/2] rust: zpool: add API for C and Rust

Vitaly Wool
2025-09-23T10:26:27Z

zpool used to be a common frontend for memory storage pool
implementations. With its removal the opportunity to select an
allocation backend for zswap has been completely lost. However, with
the recent advancements in the vmap/vmalloc field that allow for fast
and simple allocation backends, and the initiative to implement one in
Rust, the zpool API is still necessary, though it's enough to have it
as a thin API for compile time backend selection.

This patchset provides such API and implements the interface to use
it in Rust kernel code, thus enabling both C and Rust implementations
of zpool allocators. zsmalloc and documentation are updated
accordingly.

Co-developed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se>
---
Changelog:
v1 -> v2:
* reworked to stick to the existing Rust driver infrastructure
* removed raw pointers from the Rust API
v2 -> v3:
* detailed safety requirements for unsafe API functions
* removed unwrap()
* some typo corrections
v3 -> v4:
* added a working example of zpool Rust API usage in the
documentation part
* change to Flags arranged as a separate patch
* improved safety requirements for ZpoolDriver trait
v4 -> v5:
* created a new type ZpoolHandle for handle representation on the
Rust side
* improved description of Flags::from_raw()
* pool is no more borrowed as mutable for ZpoolDriver::malloc()
* ZpoolDriver::destroy() removed
* improved ZpoolDriver implementation example
* typos/markup corrections
v5 -> v6:
* removed zpool API is partially restored (to the minimal required
extent)
* no Adapter based runtime registration is necessary
* a Rust macro for compile time registration is introduced instead
---
Documentation/admin-guide/mm/zswap.rst | 14 +-
MAINTAINERS | 1
include/linux/zpool.h | 62 ++++++++
mm/Kconfig | 22 ++-
mm/zsmalloc.c | 3
mm/zswap.c | 30 ++--
rust/bindings/bindings_helper.h | 1
rust/kernel/lib.rs | 2
rust/kernel/zpool.rs | 366 +++++++++++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 479 insertions(+), 22 deletions(-)