Re: [RFC PATCH v2 1/3] mm/zsmalloc: encode class index in obj value for lockless class lookup
From: Barry Song
Date: Sat May 30 2026 - 22:01:10 EST
On Wed, May 27, 2026 at 8:02 PM Wenchao Hao <haowenchao22@xxxxxxxxx> wrote:
>
> Encode the size_class index (class_idx) into the obj value so that
> zs_free() can determine the correct size_class without dereferencing
> the handle->obj->PFN->zpdesc->zspage->class chain under pool->lock.
> class_idx is invariant across page migration (only PFN is rewritten),
> so a lockless read of obj always yields a valid class_idx.
>
> The space below the PFN field in obj is over-provisioned on 64-bit
> systems, with more bits than obj_idx needs. Split that space into
> class_idx and obj_idx subfields:
>
> |<-- _PFN_BITS -->|<-- ZS_OBJ_CLASS_BITS -->|<-- ZS_OBJ_IDX_BITS -->|
> +-----------------+-------------------------+-----------------------+
> | PFN | class_idx | obj_idx |
> +-----------------+-------------------------+-----------------------+
> MSB ^ LSB
> |
> +-- ZS_OBJ_PFN_SHIFT
>
> The macro layout changes as follows:
>
> Before After Meaning
> ---------------- ------------------ ----------------------------
> OBJ_INDEX_BITS ZS_OBJ_IDX_BITS width of obj_idx subfield
> OBJ_INDEX_MASK ZS_OBJ_IDX_MASK mask of obj_idx subfield
> (n/a) ZS_OBJ_CLASS_BITS width of class_idx subfield
> (n/a) ZS_OBJ_CLASS_MASK mask of class_idx subfield
> (n/a) ZS_OBJ_PFN_SHIFT bit offset of PFN in obj
>
> On 32-bit systems there is no spare room for class_idx, so the
> encoding is disabled (ZS_OBJ_CLASS_BITS = 0) and the obj layout
> remains [PFN | obj_idx].
>
> Signed-off-by: Wenchao Hao <haowenchao@xxxxxxxxxx>
> ---
Much better than v1.
Please make sure that the From: field matches the Signed-off-by: line next time.
Please commit the patch on your machine using:
Wenchao Hao <haowenchao@xxxxxxxxxx>
as the author.
Then git send-email will automatically generate the correct From: line
in the email.