From: Yosry Ahmed <yosry@kernel.org>
To: "Kanchana P. Sridhar" <kanchanapsridhar2026@gmail.com>
Cc: Nhat Pham <nphamcs@gmail.com>,
hannes@cmpxchg.org, chengming.zhou@linux.dev,
akpm@linux-foundation.org, linux-mm@kvack.org,
herbert@gondor.apana.org.au, davem@davemloft.net,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
rientjes@google.com, willy@infradead.org,
senozhatsky@chromium.org
Subject: Re: [PATCH v4 0/8] Batched zswap_store() framework with compression batching
Date: Wed, 25 Nov 2026 00:58:58 +0000 [thread overview]
Message-ID: <awYsDfYqrS2ldOTw@google.com> (raw)
In-Reply-To: <CACpmpodH3UUDLEze8=5v8LWgKnZWQVrQBhzSGJFY-PwEYmHEzQ@mail.gmail.com>
On Tue, Nov 24, 2026 at 03:45:52PM -0800, Kanchana P. Sridhar wrote:
> On Tue, Nov 24, 2026 at 12:29 PM Yosry Ahmed <yosry@kernel.org> wrote:
> >
> > On Fri, Nov 20, 2026 at 03:16:32PM -0800, Nhat Pham wrote:
> [...]
> > > Have you tried perf-ing the store path to see what was the overhead
> > > source (before and after this optimization)? I'm curious.
> >
> > So I was able to reproduce the usemem30 sys/wall time improvements here
> > on a Sapphire Rapids machine (both in a VM and on baremetal), and I
> > threw my LLM at perf-ing to figure out what the overhead was. It's
> > important to note that the sys/wall time improvement I observed was on
> > the free phase, the write phase / throughput (which involves zswap
> > store) didn't show much of a change.
> >
> > Batching made more consecutive pages that compress to the same zsmalloc
> > class more likely to land in the same zspage, so the freeing path gets
> > faster as the zspage and metadata are hot in the cache, which alleviates
> > contention on the class lock.
>
> This is a real performance gain with batching, correct?
Yes, but I don't think batching stores is the right way to get it, see below.
> > I think the memory allocated by usemem all compresses to the same class
> > size, which makes holding the class lock in the freeing path a
> > bottleneck. I confirmed this by a hacky patch to shard the class lock
> > into 32 locks, which caused the same usemem improvements and the series
> > doesn't improve performance anymore on top of that change.
>
> I think we all agree that vm-scalability/usemem is a
> microbenchmark/standard. I am not sure I understand the value of these
> "hacks", when my patch-series posts data with the standard mm-unstable
> and my patch series with a standard usemem microbenchmark.
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.
>
> >
> > I also tried usemem with Silesia to get realistic compression data
> > (similar to Kanchana's testing on previous versions), and didn't see
> > similar improvements (because the compressed pages get distributed
> > across multiple classes). I also tried a kernel build and the munmap
> > microbenchmark in [1] (which Sergey quoted in [2]), which also didn't
> > show improvements.
> >
> > That got me curious tho, and I had my LLM explore other optimizations to
> > the freeing path. I think we can get similar improvements in usemem
> > as well as the munmap microbenchmark [1] by batching zswap entries
> > freeing. We can batch both the zsmalloc object freeing as well as the
> > LRU deletion. I am still looking into it and I might send out patches.
> >
> > But I think this series doesn't really move the needle on realistic
> > workloads, as I previously mentioned.
>
> Your statements and hypothesis based on the kernel hacks don't explain
> why I see 6.56% additional Sys time savings with compress batching
> over the gains observed with store batching alone. I am not sure how
> to interpret your statement above without your posting any data.
>
> Did you get a chance to see the usemem/ZSTD data with/without compress
> batching that I posted in [1], and my analysis of the breakdown
> between performance gains from store batching vs. compress batching in
> [2]?
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%).
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
---------------------------------------------------------------------
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.
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)
> As per the data I posted, compress batching of PMD THP with ZSTD
> yields an additional 6.56% Sys time savings and additional 1.12%
> Throughput improvement over zswap store batching. Combined zswap store
> + compress batching yields 13.87% Sys time reduction and 3.85%
> Throughput increase over mm-unstable. I think this clearly
> demonstrates performance benefits to a well established
> microbenchmark, run at scale, using upstream kernel git trees and my
> patch series.
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. If we want to
address lock contention in zsmalloc freeing we should address it as
such, not by batching compression.
>
> I would appreciate comments from Nhat, Johannes and Andrew on these
> posted gains/analysis:
>
> [1]: https://lore.kernel.org/all/20261120041906.5785-2-kanchanapsridhar2026@gmail.com/T/#m33e586ec89ed46790da284e7a2f6d99b50c9f935
> [2]: https://lore.kernel.org/all/20261120041906.5785-2-kanchanapsridhar2026@gmail.com/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@xiaomi.com/
> > [2] https://lore.kernel.org/linux-mm/20261123054746.2579253-1-senozhatsky@chromium.org/
prev parent reply other threads:[~2026-11-25 0:59 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 4:18 [PATCH v4 0/8] Batched zswap_store() framework with compression batching Kanchana P. Sridhar
2026-11-20 4:18 ` [PATCH v4 1/8] crypto: acomp - Define a unit_size in struct acomp_req to enable batching. mm: zswap: Set the unit size for zswap to PAGE_SIZE Kanchana P. Sridhar
2026-11-20 4:19 ` [PATCH v4 2/8] crypto: acomp - Add bit to indicate segmentation support Kanchana P. Sridhar
2026-11-20 4:19 ` [PATCH v4 3/8] crypto: acomp - Add trivial segmentation wrapper Kanchana P. Sridhar
2026-11-20 4:19 ` [PATCH v4 4/8] crypto: acomp - Add API to get a compression algorithm's batch-size Kanchana P. Sridhar
2026-11-21 4:20 ` sashiko-bot
2026-11-21 21:22 ` Kanchana P. Sridhar
2026-11-20 4:19 ` [PATCH v4 5/8] mm: zswap: Store the folio's node id in the zswap_entry Kanchana P. Sridhar
2026-11-20 22:46 ` Nhat Pham
2026-11-20 23:01 ` Kanchana P. Sridhar
2026-11-21 4:20 ` sashiko-bot
2026-11-21 21:22 ` Kanchana P. Sridhar
2026-11-20 4:19 ` [PATCH v4 6/8] mm: zswap: Store large folios in batches Kanchana P. Sridhar
2026-11-20 23:08 ` Nhat Pham
2026-11-20 23:40 ` Kanchana P. Sridhar
2026-11-20 23:25 ` Nhat Pham
2026-11-20 23:51 ` Kanchana P. Sridhar
2026-11-20 4:19 ` [PATCH v4 7/8] mm: zswap: Refactor and optimize zswap_store_pages() batch operations Kanchana P. Sridhar
2026-11-20 23:45 ` Nhat Pham
2026-11-21 1:36 ` Kanchana P. Sridhar
2026-11-20 4:19 ` [PATCH v4 8/8] mm: zswap: Batched zswap_compress() for storing large folios in batches Kanchana P. Sridhar
2026-11-20 23:55 ` Nhat Pham
2026-11-21 1:17 ` Kanchana P. Sridhar
2026-11-21 3:24 ` Kanchana P. Sridhar
2026-11-21 4:20 ` sashiko-bot
2026-11-21 21:22 ` Kanchana P. Sridhar
2026-11-20 23:16 ` [PATCH v4 0/8] Batched zswap_store() framework with compression batching Nhat Pham
2026-11-21 1:04 ` Kanchana P. Sridhar
2026-11-24 20:29 ` Yosry Ahmed
2026-11-24 23:45 ` Kanchana P. Sridhar
2026-11-25 0:58 ` Yosry Ahmed [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awYsDfYqrS2ldOTw@google.com \
--to=yosry@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=davem@davemloft.net \
--cc=hannes@cmpxchg.org \
--cc=herbert@gondor.apana.org.au \
--cc=kanchanapsridhar2026@gmail.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=rientjes@google.com \
--cc=senozhatsky@chromium.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox