Re: [PATCH v2 08/11] zsmalloc: encode 1-based obj_idx so valid obj is never 0

From: Nhat Pham

Date: Tue Nov 10 2026 - 13:03:14 EST


On Mon, Nov 9, 2026 at 10:49 PM Sergey Senozhatsky
<senozhatsky@xxxxxxxxxxxx> wrote:
>
> The next patch embeds struct zs_handle into zram and zswap entries,
> and a handle is considered allocated when its obj is not 0. But obj
> can be 0: object 0 of a zspage whose first page is PFN 0 encodes to
> 0, and some platforms do give PFN 0 to the page allocator.
>
> Store obj_idx + 1 in obj, so that a valid obj is never 0, and adjust
> ZS_MIN_ALLOC_SIZE so that the largest index still fits. Unlike a
> separate tag bit, this doesn't take any bits from obj. zsmalloc did
> the same before handles moved to handle_cachep, see
> commit 67296874eb1c ("staging: zsmalloc: Ensure handle is never 0 on
> success").
>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>

Bit convoluted, I assume the this is so that we can use obj's 0 value
to mark unallocated state?

Reviewed-by: Nhat Pham <nphamcs@xxxxxxxxx>