Re: [PATCH 08/11] mm/memcontrol: Track MEMCG_ZSWAPPED in bytes
From: Joshua Hahn
Date: Tue Mar 17 2026 - 15:14:40 EST
On Wed, 11 Mar 2026 13:33:34 -0700 Nhat Pham <nphamcs@xxxxxxxxx> wrote:
> On Wed, Mar 11, 2026 at 12:52 PM Joshua Hahn <joshua.hahnjy@xxxxxxxxx> wrote:
> >
> > Zswap compresses and uncompresses in PAGE_SIZE units, which simplifies
> > the accounting for how much memory it has compressed. However, when a
> > compressed object is stored at the boundary of two zspages, accounting
> > at a PAGE_SIZE granularity makes it difficult to fractionally charge
> > each backing zspage with the ratio of memory it backs for the
> > compressed object.
> >
> > To make sub-PAGE_SIZE granularity charging possible for MEMCG_ZSWAPPED,
> > track the value in bytes and adjust its accounting accordingly.
> >
> > No functional changes intended.
> >
> > Signed-off-by: Joshua Hahn <joshua.hahnjy@xxxxxxxxx>
>
> LGTM.
> Reviewed-by: Nhat Pham <nphamcs@xxxxxxxxx>
[...snip...]
> > @@ -1066,7 +1066,7 @@ static void zs_uncharge_objcg(struct zs_pool *pool, struct obj_cgroup *objcg,
> > rcu_read_lock();
> > memcg = obj_cgroup_memcg(objcg);
> > mod_memcg_state(memcg, pool->compressed_stat, -size);
> > - mod_memcg_state(memcg, pool->uncompressed_stat, -1);
> > + mod_memcg_state(memcg, pool->uncompressed_stat, -(int)PAGE_SIZE);
>
> nit: seems a bit awkward lol?
Hello Nhat,
I totally just saw the Reviewed-by and moved on and didn't see this nit
here :p sorry!!
But yeah, I agree that it looks very awkward. AFAICT I don't think there's
a signed version of PAGE_SIZE or a negative PAGE_SIZE definition, so
unfortunately this cast is needed : -(
mm/zsmalloc.c: In function ‘zs_uncharge_objcg’:
mm/zsmalloc.c:1068:66: warning: overflow in conversion from ‘long unsigned int’ to ‘int’ changes value from ‘18446744073709547520’ to ‘-4096’ [-Woverflow]
1068 | mod_memcg_state(memcg, pool->memcg_params->uncompressed, -PAGE_SIZE);
| ^~~~~~~~~~
I will note that this is a temporary cast, we immediately remove this line
in the next patch. I did this because I wanted to show a natrual transition
from MEMCG_ZSWAPPED --> MEMCG_ZSWAPPED_B --> NR_ZSWAPPED_B and thought it
would be easier to review, but this does leave some intermediary changes in
this patch that are removed right away. If you would prefer that I squash
this commit and the next into a single patch so that there is less
intermediate code, I would be happy to do that instead!
I hope you have a great day!
Joshua