Re: [PATCH v2 10/11] zsmalloc: fold zs_obj_write() into zs_store()
From: Nhat Pham
Date: Tue Nov 10 2026 - 13:09:31 EST
On Mon, Nov 9, 2026 at 10:49 PM Sergey Senozhatsky
<senozhatsky@xxxxxxxxxxxx> wrote:
>
> zram and zswap always call zs_obj_write() right after zs_malloc(), and
> zs_obj_write() has to take pool->lock and look up object location
> again, which zs_malloc() just did.
>
> Replace zs_malloc() and zs_obj_write() with one single zs_store()
> call.
>
> zs_store() takes zspage read lock under class->lock, before it drops
> class->lock to copy the data, while zs_obj_write() used to take it
> under pool->lock. Compaction and page migration already take zspage
> lock under class->lock, so this follows the existing pool->lock ->
> class->lock -> zspage->lock order. We don't need pool->lock there,
> zs_store() doesn't look up the object via the handle, it already has
> the zspage from the allocation.
Oh nice, this looks like it'd save a pool lock acquisition?
That (effectively global) lock can be quite contend-y under memory
fragmentation, etc...
>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>
Reviewed-by: Nhat Pham <nphamcs@xxxxxxxxx>