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

From: Sergey Senozhatsky

Date: Wed Nov 11 2026 - 01:52:14 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.

v2 -> v3:
- addressed Sashiko review: alignment and READ/WRITE_ONCE mem_limit
- picked up review tags from Yosry and Nhat
- added handle validation helper
- change definition of ZS_HANDLE_SIZE

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 | 148 ++++------
drivers/block/zram/zram_drv.h | 10 +-
include/linux/zsmalloc.h | 36 ++-
mm/zsmalloc.c | 288 +++++++++++--------
mm/zswap.c | 28 +-
9 files changed, 297 insertions(+), 243 deletions(-)

--
2.56.0.542.g3ef89b7020-goog