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

From: Kanchana P. Sridhar

Date: Tue Nov 24 2026 - 21:10:42 EST


On Tue, Nov 24, 2026 at 4:59 PM Yosry Ahmed <yosry@xxxxxxxxxx> wrote:
[...]
>
> I think the real gain comes from making the freeing path faster. What I
> am saying is that we should optimize the freeing path rather than
> batching stores to get better locality in zsmalloc pages, as this only
> speeds up the freeing path when most data in a batch falls into the same
> size class in zsmalloc, which isn't the case for real data (e.g.
> Silesia).
>
> I am not arguing that usemem results are not valuable, I am arguing that
> there's more to the data than just usemem latency/throughput being
> better with the patches.
>
> The hacks were just a way to test the theory by eliminating zsmalloc
> class contention. I am looking into proper optimizations for this path,
> the goal was just to see if optimizing the class lock contention in the
> freeing path would achieve the desired result.
>
[...]
> Yes. I tried rerunning usemem on a similar setup to yours, and
> aggregating throughput, total sys/wall time, as well as write/free times
> over 10 runs (write comes from throughput lines, free comes from freeing
> lines). I did this at the baseline, with patches 1-7, and with patch 8
> on top.
>
> usemem30 (usemem -w -O -b 5 -s 10 -n 30 10g):
> kernel sys_s (mean +- sd) wall_s write_s free_s tput (KB/s)
> base 2355.6 +- 25.3 94.24 55.62 26.82 212,239
> p1-7 2366.7 +- 22.9 94.65 55.91 26.90 211,108
> p1-8 2197.0 +- 37.9 89.65 55.48 21.66 212,853
> (-6.73% vs base,
> -7.17% vs p1-7)
>
> AFAICT the speed up happens on the freeing side, not the writing side,
> so it's not really zswap stores getting faster. In the freeing phase
> (66%-100% of the run), ~90-92% of cycles are spinning in zs_free(), and
> total cycles drop from ~1.64T to ~1.30T (-21%).

Can you please clarify what "write_s" and "free_s" refer to, and how
are they measured? If you are referring to the gettimeofday() reported
timing done in user-space by usemem, these times measure child
processes' fork, do_unit, join, etc. : IOW, not a reliable indicator
of zswap_store() performance.

Also, there are no calls to zs_free() from zswap_compress() and
zswap_update_entries(), so, it is not clear why "free_s" reduces from
patch 7 (26.90s) to patch 8 (21.66s), if what you are saying (as I
understand it), is zs_free() results in the gains.

>
> Running perf on the baseline:
> ---------------------------------------------------------------------
> # Total Lost Samples: 0
> #
> # Samples: 465K of event 'cpu/cycles/P' (time slices: 66%-100%)
> # Event count (approx.): 1636895619486
> #
> # Overhead Symbol
> # ........ ............................................
> #
> 92.29% [k] queued_spin_lock_slowpath
> |
> --92.26%--queued_spin_lock_slowpath
> |
> --92.17%--zs_free
> zswap_entry_free
> zswap_invalidate
> __swap_cluster_free_entries
> swap_put_entries_cluster
> swap_put_entries_direct
> __zap_vma_range
> unmap_vmas
> unmap_region
> vms_complete_munmap_vmas
> do_vmi_align_munmap
> do_vmi_munmap
> __vm_munmap
> __x64_sys_munmap
> do_syscall_64
> entry_SYSCALL_64_after_hwframe
> 0x430ef7
> ---------------------------------------------------------------------
>
> With your patches:
> ---------------------------------------------------------------------
> # Total Lost Samples: 0
> #
> # Samples: 372K of event 'cpu/cycles/P' (time slices: 66%-100%)
> # Event count (approx.): 1295809013413
> #
> # Overhead Symbol
> # ........ ..................................................
> #
> 90.75% [k] queued_spin_lock_slowpath
> |
> --90.72%--queued_spin_lock_slowpath
> |
> --90.03%--zs_free
> zswap_entry_free
> zswap_invalidate
> __swap_cluster_free_entries
> swap_put_entries_cluster
> swap_put_entries_direct
> __zap_vma_range
> unmap_vmas
> unmap_region
> vms_complete_munmap_vmas
> do_vmi_align_munmap
> do_vmi_munmap
> __vm_munmap
> __x64_sys_munmap
> do_syscall_64
> entry_SYSCALL_64_after_hwframe
> 0x430ef7
> ---------------------------------------------------------------------
>

Is this perf run at the workload level? Can you also share the
zswap_store() perf breakdown? I don't see any zswap_store() callees
here..

> Adding some instrumentation I figured out that ~all memory from usemem
> ends up in the same size class, hence the better zspage locality from
> the batching in patch 8.

What does this have to do with batching? All usemem memory compresses
to the same zsmalloc size class in the baseline too. Can you elaborate
what you mean by "better zspage locality from the batching in patch
8"?

>
> Here's the bpftrace data I collected, I don't see a material change when
> probing zswap_store():
>
> zswap_store() (2048kB PMD folios, 178.9k calls):
> metric base p1-8 delta
> p50 10.76 ms 10.85 ms +0.87%
> p95 11.34 ms 11.40 ms +0.59%
> p99 12.15 ms 12.05 ms -0.82%
> avg 10.80 ms 10.84 ms +0.40%
>
>
> Also if I run your modified usemem with Silesia like your previous
> versions, the improvement goes away (because data no longer all goes in
> the same zsmalloc class):
>
> usemem30 + Silesia (usemem -w --read-silesia -O -b 5 -s 10 -n 30 2560m,
> memory.high=38G):
> kernel sys_s (mean +- sd) wall_s write_s free_s tput (KB/s)
> base 1779.0 +- 8.5 72.84 55.34 6.92 53,290
> p1-7 1775.7 +- 7.3 72.81 55.29 6.86 53,337
> p1-8 1771.8 +- 7.8 72.58 55.19 6.83 53,435
> (-0.40% vs base,
> -0.22% vs p1-7)

Is this with PMD mTHP? Also, we would get a better idea of concurrency
by increasing the memory allocation duration by allocating 10g per
process, for 30 processes under memory.high=150G. 2g gives much fewer
samples to be helpful, imo.

[...]
> I am not saying there is no performance improvement, I am saying the
> performance improvement is a side effect of locality in zsmalloc, not
> faster stores, and that it doesn't reproduce on real data.

I don't see the connection between batching and "locality in
zspage/zsmalloc" since compressed size is a net wash between baseline
and my patch series. Are we drawing the right conclusions?

> 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].

[2]: https://lore.kernel.org/all/20261120041906.5785-2-kanchanapsridhar2026@xxxxxxxxx/T/#m51d7d13809d508a9116904c01bf3c94fdf2981dc

>
> >
> > I would appreciate comments from Nhat, Johannes and Andrew on these
> > posted gains/analysis:
> >
> > [1]: https://lore.kernel.org/all/20261120041906.5785-2-kanchanapsridhar2026@xxxxxxxxx/T/#m33e586ec89ed46790da284e7a2f6d99b50c9f935
> > [2]: https://lore.kernel.org/all/20261120041906.5785-2-kanchanapsridhar2026@xxxxxxxxx/T/#m51d7d13809d508a9116904c01bf3c94fdf2981dc
> >
> > An independent replication of the gains posted by me in this
> > patch-series, using standard mm-unstable and vm-scalability/usemem
> > would also be very useful.
> >
> > Thanks,
> > Kanchana
> >
> > > Regarding the bpftrace
> > > measurements, I couldn't reproduce them. I think one factor is that
> > > probing both zswap_store() and zswap_compress() makes the zswap_store()
> > > numbers different based on how many zswap_compress() calls we make
> > > (which are less with batching) due to the overhead of the probe itself.
> > > When I trace zswap_store() without zswap_compress(), I don't see
> > > meaningful changes in latency.
> > >
> > > [1] https://lore.kernel.org/linux-mm/20261016120927.3191690-1-hongfengchen@xxxxxxxxxx/
> > > [2] https://lore.kernel.org/linux-mm/20261123054746.2579253-1-senozhatsky@xxxxxxxxxxxx/