Re: [PATCH v2 08/11] zsmalloc: encode 1-based obj_idx so valid obj is never 0
From: Sergey Senozhatsky
Date: Tue Nov 10 2026 - 23:49:29 EST
On (26/11/10 10:57), Nhat Pham 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?
Correct, 0 is for zs_handle_is_allocated().