Re: [PATCH v4 0/8] Batched zswap_store() framework with compression batching

From: Yosry Ahmed

Date: Wed Nov 25 2026 - 11:32:26 EST


[..]
> > write_s would be calculated averaging the time in the ".. bytes / ..
> > usecs" lines, and free_s by averaging the time from the ".. usecs to free
> > memory" lines.
> >
> > In this run:
> > write_s = 37.31 s
> > free_s = 23.39 s
> >
> > With your patches, I got:
> > write_s = 37.03 s
> > free_s = 18.86 s
>
> I am not sure how useful it is to apply user-space gettimeofday()
> results that time many higher level C code API, as an indicator of
> zswap_store() performance.

It is useful to see where the time is being spent, and it is consistent
with the perf profiles.

[..]
> > You can see that the cycles spent on zswap_store() are almost the same,
> > and the cycle reduction happens in zswap_invalidate().
>
> The cycles spent in zswap_store() should be normalized to the # of
> zswpout events that these CPU cycles represent, for this to be a
> reliable measure of latency improvement. There could be an increase in
> reclaimed folios for any number of reasons, all of which are not
> necessarily due to performance-improvement/degradation of
> zswap_store() itself. IOW, more work for less latency per unit of work
> is not always indicative of a performance degradation in this case.
>
> A realistic scenario would be that with zswap_store() becoming more
> efficient, the 30 allocating threads cause more memory.high breaches,
> that causes more zswpout..
> This would cause more CPU cycles in zswap_store(), but the fact
> remains that zswap_store() efficiency has improved due to batching.

The zswpout number is almost identical: 45,796,107 vs 45,796,089.

[..]
> > > > If we want to address lock contention in zsmalloc freeing we should address it as
> > > > such, not by batching compression.
> > >
> > > Lock contention in zsmalloc seems like an independent optimization
> > > that is good to solve. What I don't see is a way of explaining the
> > > gains in this series based on zs_free() lock contention, and hence
> > > drawing a questionable conclusion that this series does not optimize
> > > zswap_store(), and further that batch compression is not attributing
> > > to the gains. I have provided ~10 reasons as to why the combined
> > > zswap_store_pages() batching and zswap_compress() batching improves
> > > zswap_store() performance in [2].
> >
> > See above. I think the performance improvement is a side effect of
> > calling zs_store() in rapid succession for pages in the same folio, and
> > more pages in the same folio ending up in the same zspage. As I
> > previously mentioned, this happens because all pages in usemem end up in
> > the same size class.
> >
> > The right thing to do would be optimize the zs_free() path. I am looking
> > into batching zswap entries freeing, which I believe is the right path
> > to optimize given those results.
>
> If I can restate what you are suggesting, and please correct me if I am wrong:
>
> 1) [Data needed]: Normalized zswap_store() CPU cycles to # of zswpout
> vmstat events in baseline and patched.
>
> 2) [Data needed]: Normalized zs_free() CPU cycles to # of calls to zs_free().
>
> 3) If (2) confirms that zs_free() has become faster, then that is a
> beneficial side effect of batching, per your analysis above.

The number of zswap_store() and zs_free() calls is almost the same. So
storing doesn't get faster, freeing does.

> 4) Why are you suggesting that *instead* of acknowledging the
> beneficial side-effects of zswap store/compress batching, you would
> want to find another way to improve zs_free() latency by batching of
> zswap entries freeing? I would imagine both need to happen. The zspage
> locality side-effect isn't a contra-indicator to zswap compress
> batching.

1. It is unlikely for realistic workloads to have folio where all pages
compress to the same class.

2. Even if it happens in practice, we'd optimizing the wrong thing.
Consecutive calls to zs_store() landing in the same zspage is an
implementation detail of zsmalloc, and if it is something we want to
enforce, we can do so in the correct layer (e.g. by adding per-CPU
partial zspages like SLUB). The gains also depend on how different
threads race, and the effect of cache locality on the specific CPU.

You are basically proposing optimizing zs_free() for this scenario by
batching zs_store() calls in hopes of landing compressed pages from a
folio in the same zspage so that freeing gets faster. That's definitely
not the way to do it.

If the zsmalloc class lock is a bottleneck on the freeing side, we
should address that problem directly.

> I will run some experiments to quantify zswap_store() improvements
> better, with compress batching.

Feel free to, but we have been going back-and-forth on this a lot, and I
am trying to make it clear that your time is better spent elsewhere.