Re: [PATCH 05/11] mm/zsmalloc: Store obj_cgroup pointer in zspage

From: Yosry Ahmed

Date: Wed Mar 11 2026 - 16:18:14 EST


[..]
> @@ -1216,6 +1216,11 @@ void zs_obj_write(struct zs_pool *pool, unsigned long handle,
> class = zspage_class(pool, zspage);
> off = offset_in_page(class->size * obj_idx);
>
> + if (objcg) {
> + WARN_ON_ONCE(!pool->memcg_aware);
> + zspage->objcgs[obj_idx] = objcg;
> + }

If pool->memcg_aware is not set the warning will fire, but the
following line will write to uninitialized memory and probably crash.
We should avoid the write if the warning fires.

Maybe:

if (objcg && !WARN_ON_ONCE(!pool->memcg_aware))
zspage->objcgs[obj_idx] = objcg;

Not pretty, but the same pattern is followed in many places in the kernel.

> +
> if (!ZsHugePage(zspage))
> off += ZS_HANDLE_SIZE;
>