Re: [PATCH 1/3] mm: zswap: interact directly with zsmalloc

From: Johannes Weiner

Date: Tue Sep 09 2025 - 11:02:54 EST


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