RE: [PATCH v12 22/23] mm: zswap: zswap_store() will process a large folio in batches.
From: Sridhar, Kanchana P
Date: Fri Oct 31 2025 - 18:15:15 EST
> -----Original Message-----
> From: Sridhar, Kanchana P <kanchana.p.sridhar@xxxxxxxxx>
> Sent: Wednesday, October 15, 2025 5:57 PM
> To: Nhat Pham <nphamcs@xxxxxxxxx>; Yosry Ahmed
> <yosry.ahmed@xxxxxxxxx>
> Cc: linux-kernel@xxxxxxxxxxxxxxx; linux-mm@xxxxxxxxx;
> hannes@xxxxxxxxxxx; chengming.zhou@xxxxxxxxx;
> usamaarif642@xxxxxxxxx; ryan.roberts@xxxxxxx; 21cnbao@xxxxxxxxx;
> ying.huang@xxxxxxxxxxxxxxxxx; akpm@xxxxxxxxxxxxxxxxxxxx;
> senozhatsky@xxxxxxxxxxxx; sj@xxxxxxxxxx; kasong@xxxxxxxxxxx; linux-
> crypto@xxxxxxxxxxxxxxx; herbert@xxxxxxxxxxxxxxxxxxx;
> davem@xxxxxxxxxxxxx; clabbe@xxxxxxxxxxxx; ardb@xxxxxxxxxx;
> ebiggers@xxxxxxxxxx; surenb@xxxxxxxxxx; Accardi, Kristen C
> <kristen.c.accardi@xxxxxxxxx>; Gomes, Vinicius <vinicius.gomes@xxxxxxxxx>;
> Feghali, Wajdi K <wajdi.k.feghali@xxxxxxxxx>; Gopal, Vinodh
> <vinodh.gopal@xxxxxxxxx>; Sridhar, Kanchana P
> <kanchana.p.sridhar@xxxxxxxxx>
> Subject: RE: [PATCH v12 22/23] mm: zswap: zswap_store() will process a
> large folio in batches.
>
>
> > -----Original Message-----
> > From: Nhat Pham <nphamcs@xxxxxxxxx>
> > Sent: Wednesday, October 15, 2025 3:36 PM
> > To: Yosry Ahmed <yosry.ahmed@xxxxxxxxx>
> > Cc: Sridhar, Kanchana P <kanchana.p.sridhar@xxxxxxxxx>; linux-
> > kernel@xxxxxxxxxxxxxxx; linux-mm@xxxxxxxxx; hannes@xxxxxxxxxxx;
> > chengming.zhou@xxxxxxxxx; usamaarif642@xxxxxxxxx;
> > ryan.roberts@xxxxxxx; 21cnbao@xxxxxxxxx;
> > ying.huang@xxxxxxxxxxxxxxxxx; akpm@xxxxxxxxxxxxxxxxxxxx;
> > senozhatsky@xxxxxxxxxxxx; sj@xxxxxxxxxx; kasong@xxxxxxxxxxx; linux-
> > crypto@xxxxxxxxxxxxxxx; herbert@xxxxxxxxxxxxxxxxxxx;
> > davem@xxxxxxxxxxxxx; clabbe@xxxxxxxxxxxx; ardb@xxxxxxxxxx;
> > ebiggers@xxxxxxxxxx; surenb@xxxxxxxxxx; Accardi, Kristen C
> > <kristen.c.accardi@xxxxxxxxx>; Gomes, Vinicius
> <vinicius.gomes@xxxxxxxxx>;
> > Feghali, Wajdi K <wajdi.k.feghali@xxxxxxxxx>; Gopal, Vinodh
> > <vinodh.gopal@xxxxxxxxx>
> > Subject: Re: [PATCH v12 22/23] mm: zswap: zswap_store() will process a
> > large folio in batches.
> >
> > On Wed, Oct 15, 2025 at 3:24 PM Yosry Ahmed <yosry.ahmed@xxxxxxxxx>
> > wrote:
> > >
> > > On Wed, Oct 15, 2025 at 10:15:12PM +0000, Sridhar, Kanchana P wrote:
> > >
> > > I am against increasing the size of struct zswap_entry. On x86_64, there
> > > is a 3 byte hole after 'referenced'. We can technically use that,
> > > although the node id is usually an int, which is 4 bytes on x86_64.
> > >
> > > In practice, I think 2 bytes (i.e. short) should be enough, but it will
> > > be ugly to cast the node id to a short. We should at least WARN on
> > > overflow.
> >
> > Can we pack length and referenced using bit fields? I assume
> > compressed length cannot exceed 2^31 - 1? :)
> >
> > So, something along the line of:
> >
> > struct {
> > unsigned int length:31;
> > bool referenced:1;
> > }
> >
> > That way, we save up another 4 bytes hole, which can be repurposed for
> > the node's id.
> >
> > Does that work? I'm not very experienced with this magickery - please
> > fact check me :)
> >
> >
> > >
> > > Or we can take the simple route and drop the bulk allocation.
> >
> > Or this :)
>
> Thanks Nhat and Yosry, for sharing these constraints and ideas.
> Sure, I will see if I can use the bit fields approach and will make sure
> to not increase the size of struct zswap_entry. If this doesn't work
> for some reason, we have the simple route.
Hi Nhat and Yosry,
I have been able to get the bit fields approach working, as you suggested.
The size of "struct zswap_entry" is unchanged at 56 bytes with this change
and the addition of the "int nid" field.
zswap_lru_add()/del() use the entry->nid.
I am able to continue using kmem_cache_alloc_bulk() to benefit batching
performance.
I will include this in v13 that I expect to post within a couple of days.
Thanks!
Kanchana
>
> Best regards,
> Kanchana