Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Yosry Ahmed <yosry@kernel.org>
To: Nhat Pham <nphamcs@gmail.com>
Cc: "Kanchana P. Sridhar" <kanchanapsridhar2026@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: Tue, 24 Nov 2026 20:29:33 +0000	[thread overview]
Message-ID: <awXr6iHBR54wBB05@google.com> (raw)
In-Reply-To: <CAKEwX=MLrDn55wmVKKba5=PcU+qFpkEbMmN2SjGTfTBiFKX8cw@mail.gmail.com>

On Fri, Nov 20, 2026 at 03:16:32PM -0800, Nhat Pham wrote:
> On Thu, Nov 19, 2026 at 8:19 PM Kanchana P. Sridhar
> <kanchanapsridhar2026@gmail.com> wrote:
> >
> >
> > v4: Batched zswap_store() framework with compression batching
> > =============================================================
> >
> > This series is a spin-off of "v14: zswap compression batching with optimized
> > iaa_crypto driver" [1], and focuses on the generic crypto_acomp and zswap
> > compression batching enablers. Resuming work on this series following a gap
> > since v14 (January 2026). Please note that my email address and affiliation have
> > changed from kanchana.p.sridhar@intel.com to kanchanapsridhar2026@gmail.com. I
> > have retained the original Intel sign-offs on prior patches for historical
> > attribution while signing off v4 of this series with my current address.
> >
> > The main focus of v4 was to establish a performance measurement methodology to
> > quantify the benefits to high level metrics by using zswap compression
> > batching. This was done using an Intel Sapphire Rapids bare-metal instance with
> > 48 physical cores and by running "usemem30", i.e., 30 concurrent usemem
> > processes, each of which allocates 10G, in a 150G memory.high contrained cgroup,
> > for 10 iterations. The environment was set up to minimize performance jitter so
> > we can understand the system-level/workload-level advantages of zswap
> > compression batching when running workloads at scale.
> >
> > To summarize the main contribution of this patch series: Batching is introduced
> > in zswap_store() of large folios: we carve out a large folio into batches of
> > ZSWAP_MAX_BATCH_SIZE (4 pages) for software compressors, and store each
> > batch. Moving the fundamental operations that need to be happen to store a page
> > to now work at the granularity of a batch offers opportunities to optimize them
> > from these perspectives:
> >
> > 1) Utilize existing kernel API that minimize obtaining locks for bulk
> >    operations, e.g. kmem_cache_alloc_bulk()/kmem_cache_free_bulk().
> >
> > 2) We keep the working set for each of the core store functionalities
> >    (alloc/initialize zswap entries, compress pages, store pages in zsmalloc,
> >    pool/objcg reference increments, objcg charging) to be focused on a
> >    batch, thereby minimizing cache evictions and benefiting from cache
> >    locality.
> >
> > 3) Along the lines of (1), the main zswap_compress() batching routine obtains
> >    the comp_ctx mutex lock once per batch, and releases it after it has
> >    processed all pages in that batch.
> >
> > 4) Any zswap store functionality that works on a batch can potentially be
> >    optimized via bulk-processing/parallelized as a next step, to further improve
> >    performance.
> >
> > Performance testing: usemem30 with 100% over-commit:
> > =====================================================
> > Validation was done with mm-unstable as of 11-17-2026 (Baseline: commit
> > 866f761fd414) and with this patch series.
> >
> > v4 was validated on an Intel Xeon Sapphire Rapids bare-metal instance with
> > 48 cores.
> >
> >  Bare-metal instance specs:
> >  --------------------------
> >  - 48 physical cores
> >  - 190G RAM
> >  - 200G SWAP disk partition
> >
> >  Workload: 30 concurrent usemem processes, each allocates 10G:
> >  -------------------------------------------------------------
> >  The vm-scalability "usemem" test (unmodified version) was run in a
> >  cgroup with memory.high fixed at 150G. There is no swap limit set for the
> >  cgroup.
> >
> >  To quantify the performance benefit of zswap compress batching at scale,
> >  30 usemem processes were run ("usemem30"), each allocating and writing 10G of
> >  memory, and sleeping for 10 sec before exiting.
> >
> >   usemem -w -O -b 5 -s 10 -n 30 10g
> >   echo 0 > /sys/module/zswap/parameters/shrinker_enabled
> >
> >  Performance validation methodology:
> >  -----------------------------------
> >  These settings were used to minimize variation:
> >
> >  - All cores were fixed to run at 2.4GHz with "performance" scaling governor.
> >  - Turbo boost was disabled.
> >  - CPU power-saving C-states restricted with:
> >
> >      GRUB_CMDLINE_LINUX_DEFAULT="intel_idle.max_cstate=1 processor.max_cstate=1"
> >
> >  The usemem30 experiments were run with the baseline mm-unstable as of
> >  11-17-2026 (commit 866f761fd414) and with this patch-series.
> >
> >  After booting into each kernel:
> >
> >   1) Constrain the cgroup's memory.high to 150G.
> >
> >   2) Run 2 warm-up iterations of usemem30. Don't use this data for benchmarking
> >      since sys time typically skews higher for initial runs.
> >
> >   3) Next, run 10 benchmarking iterations of usemem30:
> >      - Log these high-level metrics: Sys time and individual usemem throughput.
> >
> >   4) Sys time and Throughput metrics were gathered for three mTHP settings:
> >
> >      - 2048kB
> >      - 1024kB
> >      - 64kB
> >
> >   5) Benchmark summary data includes Sys time and Throughput components from the
> >      10 iterations of usemem30:
> >
> >      - Total Samples
> >      - Mean Value
> >      - Std Deviation
> >      - CoV (Variance): Coefficient of variation (relative standard deviation)
> >        measures spread relative to the mean rather than statistical variance.
> >
> >  An LLM was used to help generate the benchmarking and data processing scripts.
> >
> > usemem30 Benchmarking Summary:
> > ==============================
> >
> >  ---------------------------------------------------
> >     Improvement with v4 zswap compress batching
> >  ---------------------------------------------------
> >   mTHP enabled:       2048kB     1024kB       64kB
> >  ---------------------------------------------------
> >       Sys time:      -13.87%     -2.64%     -1.72%
> >     Throughput:       +3.85%     +0.42%     +1.31%
> >  ---------------------------------------------------
> 
> 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.

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

      parent reply	other threads:[~2026-11-24 20:29 UTC|newest]

Thread overview: 29+ 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 [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=awXr6iHBR54wBB05@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