[PATCH v2 00/11] zsmalloc: redesign object alloc API

From: Sergey Senozhatsky

Date: Tue Nov 10 2026 - 00:49:07 EST


Both zram and zswap already have per-entry structures that store zsmalloc
handles, so allocating a separate handle_cachep object per stored page is
redundant. This series embeds struct zs_handle directly into zram and
zswap entries and drops handle_cachep, saving 8 bytes and a slab
alloc/free per stored object (2MB per 1GB of swapped out 4K pages).

It also folds zs_malloc() and zs_obj_write() into zs_store() so we don't
take pool->lock and look up object location again right after allocation.

A simple zram test on a 24-vCPU VM
==================================
165 fewer kernel instructions and 0.7-1.8% fewer kernel cycles per write;
lz4 single writer +2.3% IOPS / -2.6% average latency;
24 writers +0.9-+1.0% IOPS; no regressions.
Memory: 8 bytes less per stored page.

v1 -> v2:
-- addressed Yosry's v1 feedback (too lengthy to mention here, Yosry
posted over a million comments, or something very close to that):
split-ed some patches, squashed the other ones, added handle
alignment run-time check, added 0 PFN defense, etc.

Sergey Senozhatsky (11):
zram: drop stale comment in write_incompressible_page()
zram: drop get_slot_handle() and set_slot_handle()
zsmalloc: return handle from obj_allocated()
zsmalloc: switch handle type to struct zs_handle
zram: check mem_limit before allocating zsmalloc object
zram: allocate zsmalloc object under slot lock
zswap: do not free the entry if its pool is NULL
zsmalloc: encode 1-based obj_idx so valid obj is never 0
zsmalloc: embed struct zs_handle into zram and zswap entries
zsmalloc: fold zs_obj_write() into zs_store()
zsmalloc: populate new zspage outside class->lock in zs_store()

Documentation/admin-guide/blockdev/zram.rst | 4 +-
Documentation/admin-guide/mm/slab.rst | 2 +-
Documentation/core-api/memory-allocation.rst | 2 +-
Documentation/mm/zsmalloc.rst | 22 +-
drivers/block/zram/zram_drv.c | 146 ++++------
drivers/block/zram/zram_drv.h | 10 +-
include/linux/zsmalloc.h | 36 ++-
mm/zsmalloc.c | 285 +++++++++++--------
mm/zswap.c | 28 +-
9 files changed, 293 insertions(+), 242 deletions(-)

--
2.56.0.506.g506a7eabc5-goog