From: Yosry Ahmed <yosry.ahmed@linux.dev>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Nhat Pham <nphamcs@gmail.com>,
Chengming Zhou <zhouchengming@bytedance.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] mm: zswap: interact directly with zsmalloc
Date: Thu, 11 Sep 2025 14:30:31 +0000 [thread overview]
Message-ID: <f5hn4awbmkelckl6khlaosw3tbfrwzvf5l7kn6mnqpbastsdnh@77mqvfjzyfys> (raw)
In-Reply-To: <20250910134240.GA1111@cmpxchg.org>
On Wed, Sep 10, 2025 at 09:42:40AM -0400, Johannes Weiner wrote:
> On Tue, Sep 09, 2025 at 08:10:43PM +0000, Yosry Ahmed wrote:
> > On Tue, Sep 09, 2025 at 04:01:56PM +0100, Johannes Weiner wrote:
> > > On Fri, Sep 05, 2025 at 06:53:15PM +0000, Yosry Ahmed wrote:
> > > > On Fri, Aug 29, 2025 at 05:15:26PM +0100, Johannes Weiner wrote:
> > > > > zswap goes through the zpool layer to enable runtime-switching of
> > > > > allocator backends for compressed data. However, since zbud and z3fold
> > > > > were removed in 6.15, zsmalloc has been the only option available.
> > > > >
> > > > > As such, the zpool indirection is unnecessary. Make zswap deal with
> > > > > zsmalloc directly. This is comparable to zram, which also directly
> > > > > interacts with zsmalloc and has never supported a different backend.
> > > > >
> > > > > Note that this does not preclude future improvements and experiments
> > > > > with different allocation strategies. Should it become necessary, it's
> > > > > possible to provide an alternate implementation for the zsmalloc API,
> > > > > selectable at compile time. However, zsmalloc is also rather mature
> > > > > and feature rich, with years of widespread production exposure; it's
> > > > > encouraged to make incremental improvements rather than fork it.
> > > > >
> > > > > In any case, the complexity of runtime pluggability seems excessive
> > > > > and unjustified at this time. Switch zswap to zsmalloc to remove the
> > > > > last user of the zpool API.
> > > > >
> > > > > Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
> > > > > ---
> > > > [..]
> > > > > @@ -315,52 +292,29 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
> > > > > error:
> > > > > if (pool->acomp_ctx)
> > > > > free_percpu(pool->acomp_ctx);
> > > > > - if (pool->zpool)
> > > > > - zpool_destroy_pool(pool->zpool);
> > > > > + if (pool->zs_pool)
> > > > > + zs_destroy_pool(pool->zs_pool);
> > > > > kfree(pool);
> > > > > return NULL;
> > > > > }
> > > > >
> > > > > static struct zswap_pool *__zswap_pool_create_fallback(void)
> > > > > {
> > > > > - bool has_comp, has_zpool;
> > > > > -
> > > > > - has_comp = crypto_has_acomp(zswap_compressor, 0, 0);
> > > > > - if (!has_comp && strcmp(zswap_compressor,
> > > > > - CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) {
> > > > > + if (!crypto_has_acomp(zswap_compressor, 0, 0) &&
> > > > > + strcmp(zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) {
> > > > > pr_err("compressor %s not available, using default %s\n",
> > > > > zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT);
> > > > > param_free_charp(&zswap_compressor);
> > > > > zswap_compressor = CONFIG_ZSWAP_COMPRESSOR_DEFAULT;
> > > > > - has_comp = crypto_has_acomp(zswap_compressor, 0, 0);
> > > > > - }
> > > > > - if (!has_comp) {
> > > > > - pr_err("default compressor %s not available\n",
> > > > > - zswap_compressor);
> > > > > - param_free_charp(&zswap_compressor);
> > > > > - zswap_compressor = ZSWAP_PARAM_UNSET;
> > > > > - }
> > > > > -
> > > > > - has_zpool = zpool_has_pool(zswap_zpool_type);
> > > > > - if (!has_zpool && strcmp(zswap_zpool_type,
> > > > > - CONFIG_ZSWAP_ZPOOL_DEFAULT)) {
> > > > > - pr_err("zpool %s not available, using default %s\n",
> > > > > - zswap_zpool_type, CONFIG_ZSWAP_ZPOOL_DEFAULT);
> > > > > - param_free_charp(&zswap_zpool_type);
> > > > > - zswap_zpool_type = CONFIG_ZSWAP_ZPOOL_DEFAULT;
> > > > > - has_zpool = zpool_has_pool(zswap_zpool_type);
> > > > > - }
> > > > > - if (!has_zpool) {
> > > > > - pr_err("default zpool %s not available\n",
> > > > > - zswap_zpool_type);
> > > > > - param_free_charp(&zswap_zpool_type);
> > > > > - zswap_zpool_type = ZSWAP_PARAM_UNSET;
> > > > > + if (!crypto_has_acomp(zswap_compressor, 0, 0)) {
> > > > > + pr_err("default compressor %s not available\n",
> > > > > + zswap_compressor);
> > > > > + zswap_compressor = ZSWAP_PARAM_UNSET;
> > > > > + return NULL;
> > > > > + }
> > > >
> > > > Hmm it seems like there may be a change of behavior here. If
> > > > zswap_compressor == CONFIG_ZSWAP_COMPRESSOR_DEFAULT at the beginning and
> > > > crypto_has_acomp() returns false, the old code will go into the second
> > > > if (!has_comp) block, printing an error, freeing the string, and setting
> > > > zswap_compressor to ZSWAP_PARAM_UNSET, then we eventually return NULL.
> > > >
> > > > It seems like the new code will just call zswap_pool_create() anyway.
> > > >
> > > > Am I missing something here?
> > >
> > > I don't think that scenario is possible, due to the way the Kconfig
> > > works. Whatever backend I select for CONFIG_ZSWAP_COMPRESSOR_DEFAULT
> > > pulls in the crypto module as built-in/=y. It should always be there.
> >
> > What if none of the CONFIG_ZSWAP_COMPRESSOR_DEFAULT_* options are
> > selected (i.e. empty string)? Also, can CONFIG_ZSWAP_COMPRESSOR_DEFAULT
> > be set directly to an arbitrary string?
>
> No, that isn't possible. It's a multiple choice symbol that forces one
> of the options and has a valid default value. I tried to made it an
> empty string in .config by hand, but oldconfig restored it; if I
> remove the DEFAULT_* line entirely, oldconfig reprompts.
Good to know, I honestly never really know how kconfig handles these
things.
>
> > I would prefer if the code behavior did not change to rely on the config
> > possibilities.
>
> How about this on top?
>
> From f842e1338594c4b78456f878731a261a074d5277 Mon Sep 17 00:00:00 2001
> From: Johannes Weiner <hannes@cmpxchg.org>
> Date: Wed, 10 Sep 2025 09:00:01 -0400
> Subject: [PATCH] yosry
>
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
> ---
> mm/zswap.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/mm/zswap.c b/mm/zswap.c
> index c88ad61b232c..991fe380c61e 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -314,6 +314,10 @@ static struct zswap_pool *__zswap_pool_create_fallback(void)
> }
> }
>
> + /* Kconfig bug? */
> + if (WARN_ON(!crypto_has_acomp(zswap_compressor, 0, 0)))
> + return NULL;
> +
> return zswap_pool_create(zswap_compressor);
> }
Sure, looks good, although I think it's clearer (and smaller diff) to
preserve the old structure instead, up to you:
diff --git a/mm/zswap.c b/mm/zswap.c
index c88ad61b232cf..bbfc087792648 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -300,18 +300,21 @@ static struct zswap_pool *zswap_pool_create(char *compressor)
static struct zswap_pool *__zswap_pool_create_fallback(void)
{
- if (!crypto_has_acomp(zswap_compressor, 0, 0) &&
+ bool has_comp = crypto_has_acomp(zswap_compressor, 0, 0);
+
+ if (!has_comp &&
strcmp(zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) {
pr_err("compressor %s not available, using default %s\n",
zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT);
param_free_charp(&zswap_compressor);
zswap_compressor = CONFIG_ZSWAP_COMPRESSOR_DEFAULT;
- if (!crypto_has_acomp(zswap_compressor, 0, 0)) {
- pr_err("default compressor %s not available\n",
- zswap_compressor);
- zswap_compressor = ZSWAP_PARAM_UNSET;
- return NULL;
- }
+ has_comp = crypto_has_acomp(zswap_compressor, 0, 0);
+ }
+ if (!has_comp) {
+ pr_err("default compressor %s not available\n",
+ zswap_compressor);
+ zswap_compressor = ZSWAP_PARAM_UNSET;
+ return NULL;
}
return zswap_pool_create(zswap_compressor);
>
> --
> 2.51.0
>
next prev parent reply other threads:[~2025-09-11 14:30 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 16:15 [PATCH 0/3] mm: remove zpool Johannes Weiner
2025-08-29 16:15 ` [PATCH 1/3] mm: zswap: interact directly with zsmalloc Johannes Weiner
2025-09-05 18:53 ` Yosry Ahmed
2025-09-09 15:01 ` Johannes Weiner
2025-09-09 20:10 ` Yosry Ahmed
2025-09-10 13:42 ` Johannes Weiner
2025-09-11 14:30 ` Yosry Ahmed [this message]
2025-09-15 15:36 ` Johannes Weiner
2025-09-15 19:33 ` Yosry Ahmed
2025-08-29 16:15 ` [PATCH 2/3] mm: remove unused zpool layer Johannes Weiner
2025-08-29 19:07 ` SeongJae Park
2025-09-09 15:13 ` Johannes Weiner
2025-09-10 3:14 ` SeongJae Park
2025-09-05 18:58 ` Yosry Ahmed
2025-09-09 15:16 ` Johannes Weiner
2025-09-09 20:08 ` Yosry Ahmed
2025-09-09 20:09 ` Yosry Ahmed
2025-09-10 13:46 ` Johannes Weiner
2025-08-29 16:15 ` [PATCH 3/3] mm: zpdesc: minor naming and comment corrections Johannes Weiner
2025-09-05 19:05 ` Yosry Ahmed
2025-09-09 15:11 ` Johannes Weiner
2025-09-09 20:08 ` Yosry Ahmed
2025-09-04 9:33 ` [PATCH 0/3] mm: remove zpool Vitaly Wool
2025-09-04 10:13 ` Vlastimil Babka
2025-09-04 11:26 ` David Hildenbrand
2025-09-05 5:36 ` Vitaly Wool
2025-09-04 14:11 ` Vitaly Wool
2025-09-05 7:03 ` Vlastimil Babka
2025-09-05 18:02 ` Nhat Pham
2025-09-05 22:42 ` Vitaly Wool
2025-09-05 19:57 ` Yosry Ahmed
2025-09-06 5:25 ` Sergey Senozhatsky
2025-09-08 12:18 ` Sergey Senozhatsky
2025-09-09 20:12 ` Yosry Ahmed
2025-09-13 13:55 ` Vitaly Wool
2025-09-15 19:37 ` Yosry Ahmed
2025-09-16 11:16 ` Vitaly Wool
2025-09-16 3:29 ` Sergey Senozhatsky
2025-09-04 23:47 ` Andrew Morton
2025-09-05 5:42 ` Vitaly Wool
2025-09-05 18:30 ` Andrew Morton
2025-09-05 22:20 ` Vitaly Wool
2025-09-04 9:51 ` Vitaly Wool
2025-09-05 17:52 ` Nhat Pham
2025-09-05 19:45 ` Yosry Ahmed
2025-09-05 21:35 ` Nhat Pham
2025-09-09 15:03 ` Johannes Weiner
2025-09-09 20:11 ` Yosry Ahmed
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=f5hn4awbmkelckl6khlaosw3tbfrwzvf5l7kn6mnqpbastsdnh@77mqvfjzyfys \
--to=yosry.ahmed@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=zhouchengming@bytedance.com \
/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