Re: [PATCH v4 2/4] mm/zsmalloc: drop pool->lock from zs_free on 64-bit systems

From: Nhat Pham

Date: Tue Jun 09 2026 - 14:08:16 EST


On Tue, Jun 9, 2026 at 4:36 AM Wenchao Hao <haowenchao22@xxxxxxxxx> wrote:
>
> From: Wenchao Hao <haowenchao@xxxxxxxxxx>
>
> With class_idx encoded in obj, zs_free() can locate the size_class
> without holding pool->lock on 64-bit systems. Page migration also
> takes class->lock and only rewrites the PFN field of obj, so:
>
> 1. read obj locklessly,
> 2. lock the size_class derived from obj's class_idx,
> 3. re-read obj under class->lock to get a stable PFN.
>
> This eliminates the rwlock read-side cacheline bouncing between
> zs_free() and migration/compaction on multi-core systems.
>
> Annotate handle_to_obj()/record_obj() with READ_ONCE()/WRITE_ONCE() to
> prevent load/store tearing on the lockless read path and silence KCSAN
> data race reports.
>
> When ZS_OBJ_CLASS_BITS == 0 (32-bit, or 64-bit with obj too narrow to
> hold class_idx), zs_free() keeps pool->lock.
>
> Signed-off-by: Wenchao Hao <haowenchao@xxxxxxxxxx>

LGTM.
Reviewed-by: Nhat Pham <nphamcs@xxxxxxxxx>