mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 16:31:53 +0000	[thread overview]
Message-ID: <awcK9oNDbc1QFJr6@google.com> (raw)
In-Reply-To: <CACpmpod_87WY_PcOsNmPZvFzmJyBtCpyvvq1a_BqmZgGmO1e5A@mail.gmail.com>

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

      reply	other threads:[~2026-11-25 16:31 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  4:18 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-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-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-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
2026-11-25  2:10         ` Kanchana P. Sridhar
2026-11-25  5:51           ` Yosry Ahmed
2026-11-25  6:56             ` Kanchana P. Sridhar
2026-11-25 16:31               ` 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=awcK9oNDbc1QFJr6@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

all inboxes | Powered by JetHome®