Re: [PATCH 3/8] mm/zsmalloc: Introduce objcgs pointer in struct zpdesc

From: Joshua Hahn

Date: Wed Mar 04 2026 - 13:19:06 EST


On Wed, 4 Mar 2026 08:58:44 -0800 Yosry Ahmed <yosry@xxxxxxxxxx> wrote:

> > static struct zspage *find_get_zspage(struct size_class *class)
> > @@ -1289,13 +1336,14 @@ static unsigned long obj_malloc(struct zs_pool *pool,
> > * @size: size of block to allocate
> > * @gfp: gfp flags when allocating object
> > * @nid: The preferred node id to allocate new zspage (if needed)
> > + * @objcg: Whether the zspage should track per-object memory charging.
> > *
> > * On success, handle to the allocated object is returned,
> > * otherwise an ERR_PTR().
> > * Allocation requests with size > ZS_MAX_ALLOC_SIZE will fail.
> > */
> > unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp,
> > - const int nid)
> > + const int nid, bool objcg)
>
> Instead of passing in a boolean here, what if we make it a pool
> parameter at creation time? I don't foresee I use case where some
> objects are charged and some aren't. This avoids needing to always
> pass objcg=true (for zswap) or objcg=false (for zram), and reduces
> churn. Also, it allows us to add assertions to zs_obj_write() (and
> elsewhere if needed) that an objcg is passed in when the pool should
> be charged.

Hi Yosry,

Thank you for another great idea! Makes sense to me, then I can leave most
of the existing ABI signatures alone and just make the zpool changes.

Thanks a lot again : -)
Joshua

> We can even add a zs_obj_write_objcg() variant that takes in an objcg,
> and keep the current one as-is. Both would internally call a helper
> that takes in an objcg, but that would further minimize churn to zram.
> Not sure if that's worth it though. Sergey, WDYT?