Re: [PATCH v4 5/8] mm: zswap: Store the folio's node id in the zswap_entry.

From: Kanchana P. Sridhar

Date: Fri Nov 20 2026 - 18:02:10 EST


On Fri, Nov 20, 2026 at 2:46 PM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
>
> On Thu, Nov 19, 2026 at 8:19 PM Kanchana P. Sridhar
> <kanchanapsridhar2026@xxxxxxxxx> wrote:
> >
> > When storing a folio in zswap, save the folio's node id in the zswap
> > entry instead of relying on the zswap_entry being allocated on the same
> > node. This enables optimizations such as batch allocation of zswap
> > entries for large folios using kmem_cache_alloc_bulk() that does not
> > support specifying a node id.
> >
> > Accordingly, replace the SLUB allocation in zswap_entry_cache_alloc() to
> > be node-agnostic.
> >
> > The size of the zswap_entry remains unchanged as 'referenced' is lumped
> > in with the 'length' (as it doesn't need a full unsigned int anyway).
> > A build time assertion checks for the zswap_entry's 'length' bitfield
> > being large enough to represent PAGE_SIZE, which can be 256KB on some
> > architectures.
> >
> > Suggested-by: Nhat Pham <nphamcs@xxxxxxxxx>
> > Suggested-by: Yosry Ahmed <yosry.ahmed@xxxxxxxxx>
> > Signed-off-by: Kanchana P Sridhar <kanchana.p.sridhar@xxxxxxxxx>
> > Signed-off-by: Kanchana P. Sridhar <kanchanapsridhar2026@xxxxxxxxx>
>
> LGTM for the most part:
>
> Acked-by: Nhat Pham <nphamcs@xxxxxxxxx>

Many thanks, Nhat :) !!

>
> > ---
> > + * nid - NUMA node id of the page for which this is the zswap entry.
>
> Maybe "NUMA node id of the original page of this zswap entry"?

Sure. Will make this change in my next rev/patchlet.

>
> > * handle - zsmalloc allocation handle that stores the compressed page data
> > * objcg - the obj_cgroup that the compressed memory is charged to
> > * lru - handle to the pool's lru used to evict pages.
> > */
> > struct zswap_entry {
> > swp_entry_t swpentry;
> > - unsigned int length;
> > - bool referenced;
> > - u8 pool_idx;
> > + struct {
> > + unsigned int length:ZSWAP_MAX_COMPR_LENGTH_SHIFT;
>
> I could have sworn we agreed to just inline this macro.

True, however, per Yosry's earlier suggestion, I added a build time
assertion for whether ZSWAP_MAX_COMPR_LENGTH_SHIFT has enough bits to
represent the architecture's PAGE_SIZE, and could not determine a
sizeof/other API that returns a bitfield's size in bits. Hence I
resorted to the macro.

>
> (btw how many bits do we still have here? )

We now have 4 bits after "referenced":

struct zswap_entry {
swp_entry_t swpentry; /* 0 8 */
struct {
unsigned int length:19; /* 8: 0 4 */

/* Bitfield combined with next fields */

bool referenced:1; /* 10: 3 1 */

/* XXX 4 bits hole, try to pack */

u8 pool_idx; /* 11 1 */
}; /* 8 4 */
int nid; /* 12 4 */
struct zs_handle handle; /* 16 8 */
struct obj_cgroup * objcg; /* 24 8 */
struct list_head lru; /* 32 16 */

/* size: 48, cachelines: 1, members: 6 */
/* last cacheline: 48 bytes */
};