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

Joshua Hahn
2026-03-11T20:24:45Z

On Wed, 11 Mar 2026 13:17:26 -0700 Yosry Ahmed <yosry@kernel.org> wrote:

> [..]
> > @@ -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;
> > + }

Hello Yosry,

I hope you are doing well. Thank you for reviewing this series! : -)

> 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;

Ack.

> Not pretty, but the same pattern is followed in many places in the kernel.
>
> > +
> > if (!ZsHugePage(zspage))
> > off += ZS_HANDLE_SIZE;
> >

Definitely better than writing garbage and crashing : -)
I'll make this change in the next version, I think I should also sprinkle
these WARN_ON_ONCEs in a few other places as well. I'll be more
mindful of this for those cases as well.

Thank you again Yosry, I hope you have a great day!
Joshua