From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E672C432C0 for ; Thu, 21 Nov 2019 23:41:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 92280206B6 for ; Thu, 21 Nov 2019 23:41:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C6S5SD1+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92280206B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F0B2A6B03B5; Thu, 21 Nov 2019 18:41:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EE15C6B03BD; Thu, 21 Nov 2019 18:41:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF7376B03C1; Thu, 21 Nov 2019 18:41:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id BF1F86B03B5 for ; Thu, 21 Nov 2019 18:41:04 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 6BD06181AEF23 for ; Thu, 21 Nov 2019 23:41:04 +0000 (UTC) X-FDA: 76181907648.06.quilt53_6085676a1d54d X-HE-Tag: quilt53_6085676a1d54d X-Filterd-Recvd-Size: 35196 Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Nov 2019 23:41:03 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id b20so4049683lfp.4 for ; Thu, 21 Nov 2019 15:41:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ht/MwUtzSODhDB0zui6SkS/7D8eYlQo5eVPbZFC88FQ=; b=C6S5SD1+AT0OlY22lTxtrRCQTztIVCka+unQreCQ4Mz2BuoXg+1Fp1Ct8+iqbQO+z8 FAem7JKJabzBW8tMpreigBSAtC4xa+RnvW9If/8o2iBihtIfXa28VHj2iMMm78onjAzs LjdQEJByqJ/GTY7BvykMyK95PTgUeMVoSM8mF4ZMBYvqSkMZLcoArVfLZ6uaFtSnhJBX U86rsUdCiEV+474uu44dnaY9FXTCVRUkprkYV/JlgaFIiHNeihTeRFvGtjAHkhZG5DS8 8llYJj4cCFJqpMH15aH1RVq57dtDw1dpPACz1Ne3a+xSb1iEk5MpQ9S7IhFbdJh/0ftT bkww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ht/MwUtzSODhDB0zui6SkS/7D8eYlQo5eVPbZFC88FQ=; b=bFVK9QZQVQO57PGb4gzzwp0tMgNX1I6GCrED/W5616Q94S3sqTaYAd+kQf4hgkIkat 1hECc3BNMAI3uL+W+vpWIK2CABE6LJ18Dxx6AunIzwV0AmIYma2nTLE/SCC5l8PzsioV cO0sAT5iCugPt/HySlfVULz7uJpnUOPpWixp3YyYshKxX5kt3cIArhqJpJSI1Voq9KUW ke34ZRIkVPFtFBiFqVKddhQEO6A8wSjxMBMkUY5koySTz7j5rGB/CGJeTiBWlffi23vS FBGFuZFBr0yUKS9s1RuN0xndTkRfuRahKeEGtq0pADX3yU0+4UGAUp8R1y8FXUclJk3e 8D+w== X-Gm-Message-State: APjAAAVTiNyev2yVjeyljpKLjXgF8sDFyQgQPbh1sHV+aKLWwHh29zjV utMQvHscw05GRfuBuIE/kPLxO1D17J4IKbgkmNU= X-Google-Smtp-Source: APXvYqwRE+JJthC6dkS6GXZOIGG9TFsDLCw4MWuxiW3d5sQGgzM06hk8sTt4N96HBBdlccj/QOPpsKX9YeDAOSx1/A4= X-Received: by 2002:ac2:5464:: with SMTP id e4mr9810585lfn.47.1574379661432; Thu, 21 Nov 2019 15:41:01 -0800 (PST) MIME-Version: 1.0 References: <20191118230119.1496378-1-mail@maciej.szmigiero.name> In-Reply-To: <20191118230119.1496378-1-mail@maciej.szmigiero.name> From: Vitaly Wool Date: Fri, 22 Nov 2019 00:40:49 +0100 Message-ID: Subject: Re: [PATCH v5] zswap: allow setting default status, compressor and allocator in Kconfig To: "Maciej S. Szmigiero" Cc: Seth Jennings , Dan Streetman , Vlastimil Babka , Linux-MM , LKML Content-Type: multipart/alternative; boundary="000000000000761db40597e3d471" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --000000000000761db40597e3d471 Content-Type: text/plain; charset="UTF-8" On Tue, Nov 19, 2019 at 12:01 AM Maciej S. Szmigiero < mail@maciej.szmigiero.name> wrote: > The compressed cache for swap pages (zswap) currently needs from 1 to 3 > extra kernel command line parameters in order to make it work: it has to be > enabled by adding a "zswap.enabled=1" command line parameter and if one > wants a different compressor or pool allocator than the default lzo / zbud > combination then these choices also need to be specified on the kernel > command line in additional parameters. > > Using a different compressor and allocator for zswap is actually pretty > common as guides often recommend using the lz4 / z3fold pair instead of > the default one. > In such case it is also necessary to remember to enable the appropriate > compression algorithm and pool allocator in the kernel config manually. > > Let's avoid the need for adding these kernel command line parameters and > automatically pull in the dependencies for the selected compressor > algorithm and pool allocator by adding an appropriate default switches to > Kconfig. > > The default values for these options match what the code was using > previously as its defaults. > > Signed-off-by: Maciej S. Szmigiero > Reviewed-by: Vitaly Wool > --- > Changes from v1: > Rename CONFIG_ZSWAP_DEFAULT_COMP_* to CONFIG_ZSWAP_COMPRESSOR_DEFAULT_* > and CONFIG_ZSWAP_DEFAULT_ZPOOL_* to CONFIG_ZSWAP_ZPOOL_DEFAULT_* while > dropping the "_NAME" suffix from the final string option in both cases. > > Changes from v2: > Add zsmalloc as a pool allocator choice, add a link to a page with > benchmarks of various compression algorithms to the compression > algorithm prompt option. > > Changes from v3: > Update the zswap doc in Documentation, too. > > Changes from v4: > Use IS_ENABLED() macro to initialize the zswap_enabled variable, > make CONFIG_ZSWAP_COMPRESSOR_DEFAULT and CONFIG_ZSWAP_ZPOOL_DEFAULT > depend on CONFIG_ZSWAP so they don't show in .config when zswap is > deselected in Kconfig. > > Documentation/vm/zswap.rst | 20 ++++--- > mm/Kconfig | 118 ++++++++++++++++++++++++++++++++++++- > mm/zswap.c | 24 ++++---- > 3 files changed, 141 insertions(+), 21 deletions(-) > > diff --git a/Documentation/vm/zswap.rst b/Documentation/vm/zswap.rst > index 1444ecd40911..2df6ee6b7a1d 100644 > --- a/Documentation/vm/zswap.rst > +++ b/Documentation/vm/zswap.rst > @@ -35,9 +35,11 @@ Zswap evicts pages from compressed cache on an LRU > basis to the backing swap > device when the compressed pool reaches its size limit. This requirement > had > been identified in prior community discussions. > > -Zswap is disabled by default but can be enabled at boot time by setting > -the ``enabled`` attribute to 1 at boot time. ie: ``zswap.enabled=1``. > Zswap > -can also be enabled and disabled at runtime using the sysfs interface. > +Whether Zswap is enabled at the boot time depends on whether > +the ``CONFIG_ZSWAP_DEFAULT_ON`` Kconfig option is enabled or not. > +This setting can then be overridden by providing the kernel command line > +``zswap.enabled=`` option, for example ``zswap.enabled=0``. > +Zswap can also be enabled and disabled at runtime using the sysfs > interface. > An example command to enable zswap at runtime, assuming sysfs is mounted > at ``/sys``, is:: > > @@ -64,9 +66,10 @@ allocation in zpool is not directly accessible by > address. Rather, a handle is > returned by the allocation routine and that handle must be mapped before > being > accessed. The compressed memory pool grows on demand and shrinks as > compressed > pages are freed. The pool is not preallocated. By default, a zpool > -of type zbud is created, but it can be selected at boot time by > -setting the ``zpool`` attribute, e.g. ``zswap.zpool=zbud``. It can > -also be changed at runtime using the sysfs ``zpool`` attribute, e.g.:: > +of type selected in ``CONFIG_ZSWAP_ZPOOL_DEFAULT`` Kconfig option is > created, > +but it can be overridden at boot time by setting the ``zpool`` attribute, > +e.g. ``zswap.zpool=zbud``. It can also be changed at runtime using the > sysfs > +``zpool`` attribute, e.g.:: > > echo zbud > /sys/module/zswap/parameters/zpool > > @@ -97,8 +100,9 @@ controlled policy: > * max_pool_percent - The maximum percentage of memory that the compressed > pool can occupy. > > -The default compressor is lzo, but it can be selected at boot time by > -setting the ``compressor`` attribute, e.g. ``zswap.compressor=lzo``. > +The default compressor is selected in ``CONFIG_ZSWAP_COMPRESSOR_DEFAULT`` > +Kconfig option, but it can be overridden at boot time by setting the > +``compressor`` attribute, e.g. ``zswap.compressor=lzo``. > It can also be changed at runtime using the sysfs "compressor" > attribute, e.g.:: > > diff --git a/mm/Kconfig b/mm/Kconfig > index a5dae9a7eb51..ca71c4c2b048 100644 > --- a/mm/Kconfig > +++ b/mm/Kconfig > @@ -525,7 +525,6 @@ config MEM_SOFT_DIRTY > config ZSWAP > bool "Compressed cache for swap pages (EXPERIMENTAL)" > depends on FRONTSWAP && CRYPTO=y > - select CRYPTO_LZO > select ZPOOL > help > A lightweight compressed cache for swap pages. It takes > @@ -541,6 +540,123 @@ config ZSWAP > they have not be fully explored on the large set of potential > configurations and workloads that exist. > > +choice > + prompt "Compressed cache for swap pages default compressor" > + depends on ZSWAP > + default ZSWAP_COMPRESSOR_DEFAULT_LZO > + help > + Selects the default compression algorithm for the compressed > cache > + for swap pages. > + > + For an overview what kind of performance can be expected from > + a particular compression algorithm please refer to the benchmarks > + available at the following LWN page: > + https://lwn.net/Articles/751795/ > + > + If in doubt, select 'LZO'. > + > + The selection made here can be overridden by using the kernel > + command line 'zswap.compressor=' option. > + > +config ZSWAP_COMPRESSOR_DEFAULT_DEFLATE > + bool "Deflate" > + select CRYPTO_DEFLATE > + help > + Use the Deflate algorithm as the default compression algorithm. > + > +config ZSWAP_COMPRESSOR_DEFAULT_LZO > + bool "LZO" > + select CRYPTO_LZO > + help > + Use the LZO algorithm as the default compression algorithm. > + > +config ZSWAP_COMPRESSOR_DEFAULT_842 > + bool "842" > + select CRYPTO_842 > + help > + Use the 842 algorithm as the default compression algorithm. > + > +config ZSWAP_COMPRESSOR_DEFAULT_LZ4 > + bool "LZ4" > + select CRYPTO_LZ4 > + help > + Use the LZ4 algorithm as the default compression algorithm. > + > +config ZSWAP_COMPRESSOR_DEFAULT_LZ4HC > + bool "LZ4HC" > + select CRYPTO_LZ4HC > + help > + Use the LZ4HC algorithm as the default compression algorithm. > + > +config ZSWAP_COMPRESSOR_DEFAULT_ZSTD > + bool "zstd" > + select CRYPTO_ZSTD > + help > + Use the zstd algorithm as the default compression algorithm. > +endchoice > + > +config ZSWAP_COMPRESSOR_DEFAULT > + string > + depends on ZSWAP > + default "deflate" if ZSWAP_COMPRESSOR_DEFAULT_DEFLATE > + default "lzo" if ZSWAP_COMPRESSOR_DEFAULT_LZO > + default "842" if ZSWAP_COMPRESSOR_DEFAULT_842 > + default "lz4" if ZSWAP_COMPRESSOR_DEFAULT_LZ4 > + default "lz4hc" if ZSWAP_COMPRESSOR_DEFAULT_LZ4HC > + default "zstd" if ZSWAP_COMPRESSOR_DEFAULT_ZSTD > + default "" > + > +choice > + prompt "Compressed cache for swap pages default allocator" > + depends on ZSWAP > + default ZSWAP_ZPOOL_DEFAULT_ZBUD > + help > + Selects the default allocator for the compressed cache for > + swap pages. > + The default is 'zbud' for compatibility, however please do > + read the description of each of the allocators below before > + making a right choice. > + > + The selection made here can be overridden by using the kernel > + command line 'zswap.zpool=' option. > + > +config ZSWAP_ZPOOL_DEFAULT_ZBUD > + bool "zbud" > + select ZBUD > + help > + Use the zbud allocator as the default allocator. > + > +config ZSWAP_ZPOOL_DEFAULT_Z3FOLD > + bool "z3fold" > + select Z3FOLD > + help > + Use the z3fold allocator as the default allocator. > + > +config ZSWAP_ZPOOL_DEFAULT_ZSMALLOC > + bool "zsmalloc" > + select ZSMALLOC > + help > + Use the zsmalloc allocator as the default allocator. > +endchoice > + > +config ZSWAP_ZPOOL_DEFAULT > + string > + depends on ZSWAP > + default "zbud" if ZSWAP_ZPOOL_DEFAULT_ZBUD > + default "z3fold" if ZSWAP_ZPOOL_DEFAULT_Z3FOLD > + default "zsmalloc" if ZSWAP_ZPOOL_DEFAULT_ZSMALLOC > + default "" > + > +config ZSWAP_DEFAULT_ON > + bool "Enable the compressed cache for swap pages by default" > + depends on ZSWAP > + help > + If selected, the compressed cache for swap pages will be enabled > + at boot, otherwise it will be disabled. > + > + The selection made here can be overridden by using the kernel > + command line 'zswap.enabled=' option. > + > config ZPOOL > tristate "Common API for compressed memory storage" > help > diff --git a/mm/zswap.c b/mm/zswap.c > index 46a322316e52..1af303e88008 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -71,8 +71,8 @@ static u64 zswap_duplicate_entry; > > #define ZSWAP_PARAM_UNSET "" > > -/* Enable/disable zswap (disabled by default) */ > -static bool zswap_enabled; > +/* Enable/disable zswap */ > +static bool zswap_enabled = IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON); > static int zswap_enabled_param_set(const char *, > const struct kernel_param *); > static struct kernel_param_ops zswap_enabled_param_ops = { > @@ -82,8 +82,7 @@ static struct kernel_param_ops zswap_enabled_param_ops = > { > module_param_cb(enabled, &zswap_enabled_param_ops, &zswap_enabled, 0644); > > /* Crypto compressor to use */ > -#define ZSWAP_COMPRESSOR_DEFAULT "lzo" > -static char *zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT; > +static char *zswap_compressor = CONFIG_ZSWAP_COMPRESSOR_DEFAULT; > static int zswap_compressor_param_set(const char *, > const struct kernel_param *); > static struct kernel_param_ops zswap_compressor_param_ops = { > @@ -95,8 +94,7 @@ module_param_cb(compressor, &zswap_compressor_param_ops, > &zswap_compressor, 0644); > > /* Compressed storage zpool to use */ > -#define ZSWAP_ZPOOL_DEFAULT "zbud" > -static char *zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT; > +static char *zswap_zpool_type = CONFIG_ZSWAP_ZPOOL_DEFAULT; > static int zswap_zpool_param_set(const char *, const struct kernel_param > *); > static struct kernel_param_ops zswap_zpool_param_ops = { > .set = zswap_zpool_param_set, > @@ -569,11 +567,12 @@ static __init struct zswap_pool > *__zswap_pool_create_fallback(void) > bool has_comp, has_zpool; > > has_comp = crypto_has_comp(zswap_compressor, 0, 0); > - if (!has_comp && strcmp(zswap_compressor, > ZSWAP_COMPRESSOR_DEFAULT)) { > + if (!has_comp && strcmp(zswap_compressor, > + CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) { > pr_err("compressor %s not available, using default %s\n", > - zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT); > + zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT); > param_free_charp(&zswap_compressor); > - zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT; > + zswap_compressor = CONFIG_ZSWAP_COMPRESSOR_DEFAULT; > has_comp = crypto_has_comp(zswap_compressor, 0, 0); > } > if (!has_comp) { > @@ -584,11 +583,12 @@ static __init struct zswap_pool > *__zswap_pool_create_fallback(void) > } > > has_zpool = zpool_has_pool(zswap_zpool_type); > - if (!has_zpool && strcmp(zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT)) { > + if (!has_zpool && strcmp(zswap_zpool_type, > + CONFIG_ZSWAP_ZPOOL_DEFAULT)) { > pr_err("zpool %s not available, using default %s\n", > - zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT); > + zswap_zpool_type, CONFIG_ZSWAP_ZPOOL_DEFAULT); > param_free_charp(&zswap_zpool_type); > - zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT; > + zswap_zpool_type = CONFIG_ZSWAP_ZPOOL_DEFAULT; > has_zpool = zpool_has_pool(zswap_zpool_type); > } > if (!has_zpool) { > --000000000000761db40597e3d471 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Tue, Nov 19, 2019 at 12:01 AM Maci= ej S. Szmigiero <mail@maci= ej.szmigiero.name> wrote:
The compressed cache for swap pages (zswap) currently need= s from 1 to 3
extra kernel command line parameters in order to make it work: it has to be=
enabled by adding a "zswap.enabled=3D1" command line parameter an= d if one
wants a different compressor or pool allocator than the default lzo / zbud<= br> combination then these choices also need to be specified on the kernel
command line in additional parameters.

Using a different compressor and allocator for zswap is actually pretty
common as guides often recommend using the lz4 / z3fold pair instead of
the default one.
In such case it is also necessary to remember to enable the appropriate
compression algorithm and pool allocator in the kernel config manually.

Let's avoid the need for adding these kernel command line parameters an= d
automatically pull in the dependencies for the selected compressor
algorithm and pool allocator by adding an appropriate default switches to Kconfig.

The default values for these options match what the code was using
previously as its defaults.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
Reviewed-by: Vitaly Wool <vitaly.wool@konsulko.com>
---
Changes from v1:
Rename CONFIG_ZSWAP_DEFAULT_COMP_* to CONFIG_ZSWAP_COMPRESSOR_DEFAULT_*
and CONFIG_ZSWAP_DEFAULT_ZPOOL_* to CONFIG_ZSWAP_ZPOOL_DEFAULT_* while
dropping the "_NAME" suffix from the final string option in both = cases.

Changes from v2:
Add zsmalloc as a pool allocator choice, add a link to a page with
benchmarks of various compression algorithms to the compression
algorithm prompt option.

Changes from v3:
Update the zswap doc in Documentation, too.

Changes from v4:
Use IS_ENABLED() macro to initialize the zswap_enabled variable,
make CONFIG_ZSWAP_COMPRESSOR_DEFAULT and CONFIG_ZSWAP_ZPOOL_DEFAULT
depend on CONFIG_ZSWAP so they don't show in .config when zswap is
deselected in Kconfig.

=C2=A0Documentation/vm/zswap.rst |=C2=A0 20 ++++---
=C2=A0mm/Kconfig=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0| 118 ++++++++++++++++++++++++++++++++++++-
=C2=A0mm/zswap.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0|=C2=A0 24 ++++----
=C2=A03 files changed, 141 insertions(+), 21 deletions(-)

diff --git a/Documentation/vm/zswap.rst b/Documentation/vm/zswap.rst
index 1444ecd40911..2df6ee6b7a1d 100644
--- a/Documentation/vm/zswap.rst
+++ b/Documentation/vm/zswap.rst
@@ -35,9 +35,11 @@ Zswap evicts pages from compressed cache on an LRU basis= to the backing swap
=C2=A0device when the compressed pool reaches its size limit.=C2=A0 This re= quirement had
=C2=A0been identified in prior community discussions.

-Zswap is disabled by default but can be enabled at boot time by setting -the ``enabled`` attribute to 1 at boot time. ie: ``zswap.enabled=3D1``.=C2= =A0 Zswap
-can also be enabled and disabled at runtime using the sysfs interface.
+Whether Zswap is enabled at the boot time depends on whether
+the ``CONFIG_ZSWAP_DEFAULT_ON`` Kconfig option is enabled or not.
+This setting can then be overridden by providing the kernel command line +``zswap.enabled=3D`` option, for example ``zswap.enabled=3D0``.
+Zswap can also be enabled and disabled at runtime using the sysfs interfac= e.
=C2=A0An example command to enable zswap at runtime, assuming sysfs is moun= ted
=C2=A0at ``/sys``, is::

@@ -64,9 +66,10 @@ allocation in zpool is not directly accessible by addres= s.=C2=A0 Rather, a handle is
=C2=A0returned by the allocation routine and that handle must be mapped bef= ore being
=C2=A0accessed.=C2=A0 The compressed memory pool grows on demand and shrink= s as compressed
=C2=A0pages are freed.=C2=A0 The pool is not preallocated.=C2=A0 By default= , a zpool
-of type zbud is created, but it can be selected at boot time by
-setting the ``zpool`` attribute, e.g. ``zswap.zpool=3Dzbud``. It can
-also be changed at runtime using the sysfs ``zpool`` attribute, e.g.::
+of type selected in ``CONFIG_ZSWAP_ZPOOL_DEFAULT`` Kconfig option is creat= ed,
+but it can be overridden at boot time by setting the ``zpool`` attribute,<= br> +e.g. ``zswap.zpool=3Dzbud``. It can also be changed at runtime using the s= ysfs
+``zpool`` attribute, e.g.::

=C2=A0 =C2=A0 =C2=A0 =C2=A0 echo zbud > /sys/module/zswap/parameters/zpo= ol

@@ -97,8 +100,9 @@ controlled policy:
=C2=A0* max_pool_percent - The maximum percentage of memory that the compre= ssed
=C2=A0 =C2=A0pool can occupy.

-The default compressor is lzo, but it can be selected at boot time by
-setting the ``compressor`` attribute, e.g. ``zswap.compressor=3Dlzo``.
+The default compressor is selected in ``CONFIG_ZSWAP_COMPRESSOR_DEFAULT``<= br> +Kconfig option, but it can be overridden at boot time by setting the
+``compressor`` attribute, e.g. ``zswap.compressor=3Dlzo``.
=C2=A0It can also be changed at runtime using the sysfs "compressor&qu= ot;
=C2=A0attribute, e.g.::

diff --git a/mm/Kconfig b/mm/Kconfig
index a5dae9a7eb51..ca71c4c2b048 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -525,7 +525,6 @@ config MEM_SOFT_DIRTY
=C2=A0config ZSWAP
=C2=A0 =C2=A0 =C2=A0 =C2=A0 bool "Compressed cache for swap pages (EXP= ERIMENTAL)"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 depends on FRONTSWAP && CRYPTO=3Dy
-=C2=A0 =C2=A0 =C2=A0 =C2=A0select CRYPTO_LZO
=C2=A0 =C2=A0 =C2=A0 =C2=A0 select ZPOOL
=C2=A0 =C2=A0 =C2=A0 =C2=A0 help
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 A lightweight compressed cache for swap = pages.=C2=A0 It takes
@@ -541,6 +540,123 @@ config ZSWAP
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 they have not be fully explored on the l= arge set of potential
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 configurations and workloads that exist.=

+choice
+=C2=A0 =C2=A0 =C2=A0 =C2=A0prompt "Compressed cache for swap pages de= fault compressor"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0depends on ZSWAP
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default ZSWAP_COMPRESSOR_DEFAULT_LZO
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Selects the default compression algorith= m for the compressed cache
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for swap pages.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0For an overview what kind of performance= can be expected from
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0a particular compression algorithm pleas= e refer to the benchmarks
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0available at the following LWN page:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0https://lwn.net/Articles/751795/<= /a>
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0If in doubt, select 'LZO'.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0The selection made here can be overridde= n by using the kernel
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0command line 'zswap.compressor=3D= 9; option.
+
+config ZSWAP_COMPRESSOR_DEFAULT_DEFLATE
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "Deflate"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select CRYPTO_DEFLATE
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use the Deflate algorithm as the default= compression algorithm.
+
+config ZSWAP_COMPRESSOR_DEFAULT_LZO
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "LZO"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select CRYPTO_LZO
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use the LZO algorithm as the default com= pression algorithm.
+
+config ZSWAP_COMPRESSOR_DEFAULT_842
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "842"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select CRYPTO_842
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use the 842 algorithm as the default com= pression algorithm.
+
+config ZSWAP_COMPRESSOR_DEFAULT_LZ4
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "LZ4"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select CRYPTO_LZ4
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use the LZ4 algorithm as the default com= pression algorithm.
+
+config ZSWAP_COMPRESSOR_DEFAULT_LZ4HC
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "LZ4HC"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select CRYPTO_LZ4HC
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use the LZ4HC algorithm as the default c= ompression algorithm.
+
+config ZSWAP_COMPRESSOR_DEFAULT_ZSTD
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "zstd"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select CRYPTO_ZSTD
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use the zstd algorithm as the default co= mpression algorithm.
+endchoice
+
+config ZSWAP_COMPRESSOR_DEFAULT
+=C2=A0 =C2=A0 =C2=A0 =C2=A0string
+=C2=A0 =C2=A0 =C2=A0 =C2=A0depends on ZSWAP
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default "deflate" if ZSWAP_COMPRESSOR= _DEFAULT_DEFLATE
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default "lzo" if ZSWAP_COMPRESSOR_DEF= AULT_LZO
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default "842" if ZSWAP_COMPRESSOR_DEF= AULT_842
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default "lz4" if ZSWAP_COMPRESSOR_DEF= AULT_LZ4
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default "lz4hc" if ZSWAP_COMPRESSOR_D= EFAULT_LZ4HC
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default "zstd" if ZSWAP_COMPRESSOR_DE= FAULT_ZSTD
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default ""
+
+choice
+=C2=A0 =C2=A0 =C2=A0 =C2=A0prompt "Compressed cache for swap pages de= fault allocator"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0depends on ZSWAP
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default ZSWAP_ZPOOL_DEFAULT_ZBUD
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Selects the default allocator for the co= mpressed cache for
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0swap pages.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0The default is 'zbud' for compat= ibility, however please do
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0read the description of each of the allo= cators below before
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0making a right choice.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0The selection made here can be overridde= n by using the kernel
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0command line 'zswap.zpool=3D' op= tion.
+
+config ZSWAP_ZPOOL_DEFAULT_ZBUD
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "zbud"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select ZBUD
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use the zbud allocator as the default al= locator.
+
+config ZSWAP_ZPOOL_DEFAULT_Z3FOLD
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "z3fold"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select Z3FOLD
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use the z3fold allocator as the default = allocator.
+
+config ZSWAP_ZPOOL_DEFAULT_ZSMALLOC
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "zsmalloc"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select ZSMALLOC
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use the zsmalloc allocator as the defaul= t allocator.
+endchoice
+
+config ZSWAP_ZPOOL_DEFAULT
+=C2=A0 =C2=A0 =C2=A0 =C2=A0string
+=C2=A0 =C2=A0 =C2=A0 =C2=A0depends on ZSWAP
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default "zbud" if ZSWAP_ZPOOL_DEFAULT= _ZBUD
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default "z3fold" if ZSWAP_ZPOOL_DEFAU= LT_Z3FOLD
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default "zsmalloc" if ZSWAP_ZPOOL_DEF= AULT_ZSMALLOC
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default ""
+
+config ZSWAP_DEFAULT_ON
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "Enable the compressed cache for swap= pages by default"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0depends on ZSWAP
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0If selected, the compressed cache for sw= ap pages will be enabled
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0at boot, otherwise it will be disabled.<= br> +
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0The selection made here can be overridde= n by using the kernel
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0command line 'zswap.enabled=3D' = option.
+
=C2=A0config ZPOOL
=C2=A0 =C2=A0 =C2=A0 =C2=A0 tristate "Common API for compressed memory= storage"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 help
diff --git a/mm/zswap.c b/mm/zswap.c
index 46a322316e52..1af303e88008 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -71,8 +71,8 @@ static u64 zswap_duplicate_entry;

=C2=A0#define ZSWAP_PARAM_UNSET ""

-/* Enable/disable zswap (disabled by default) */
-static bool zswap_enabled;
+/* Enable/disable zswap */
+static bool zswap_enabled =3D IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON);
=C2=A0static int zswap_enabled_param_set(const char *,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0const struct kernel_par= am *);
=C2=A0static struct kernel_param_ops zswap_enabled_param_ops =3D {
@@ -82,8 +82,7 @@ static struct kernel_param_ops zswap_enabled_param_ops = =3D {
=C2=A0module_param_cb(enabled, &zswap_enabled_param_ops, &zswap_ena= bled, 0644);

=C2=A0/* Crypto compressor to use */
-#define ZSWAP_COMPRESSOR_DEFAULT "lzo"
-static char *zswap_compressor =3D ZSWAP_COMPRESSOR_DEFAULT;
+static char *zswap_compressor =3D CONFIG_ZSWAP_COMPRESSOR_DEFAULT;
=C2=A0static int zswap_compressor_param_set(const char *,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 const struct ke= rnel_param *);
=C2=A0static struct kernel_param_ops zswap_compressor_param_ops =3D {
@@ -95,8 +94,7 @@ module_param_cb(compressor, &zswap_compressor_param_o= ps,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &zswap_compress= or, 0644);

=C2=A0/* Compressed storage zpool to use */
-#define ZSWAP_ZPOOL_DEFAULT "zbud"
-static char *zswap_zpool_type =3D ZSWAP_ZPOOL_DEFAULT;
+static char *zswap_zpool_type =3D CONFIG_ZSWAP_ZPOOL_DEFAULT;
=C2=A0static int zswap_zpool_param_set(const char *, const struct kernel_pa= ram *);
=C2=A0static struct kernel_param_ops zswap_zpool_param_ops =3D {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 .set =3D=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 zswa= p_zpool_param_set,
@@ -569,11 +567,12 @@ static __init struct zswap_pool *__zswap_pool_create_= fallback(void)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 bool has_comp, has_zpool;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 has_comp =3D crypto_has_comp(zswap_compressor, = 0, 0);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!has_comp && strcmp(zswap_compresso= r, ZSWAP_COMPRESSOR_DEFAULT)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!has_comp && strcmp(zswap_compresso= r,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) { =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pr_err("compre= ssor %s not available, using default %s\n",
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 param_free_charp(&a= mp;zswap_compressor);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0zswap_compressor = =3D ZSWAP_COMPRESSOR_DEFAULT;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0zswap_compressor = =3D CONFIG_ZSWAP_COMPRESSOR_DEFAULT;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 has_comp =3D crypto= _has_comp(zswap_compressor, 0, 0);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!has_comp) {
@@ -584,11 +583,12 @@ static __init struct zswap_pool *__zswap_pool_create_= fallback(void)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0 =C2=A0 has_zpool =3D zpool_has_pool(zswap_zpool_type);=
-=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!has_zpool && strcmp(zswap_zpool_ty= pe, ZSWAP_ZPOOL_DEFAULT)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!has_zpool && strcmp(zswap_zpool_ty= pe,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 CONFIG_ZSWAP_ZPOOL_DEFAULT)) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pr_err("zpool = %s not available, using default %s\n",
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 zswap_zpool_type, CONFIG_ZSWAP_ZPOOL_DEFAULT);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 param_free_charp(&a= mp;zswap_zpool_type);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0zswap_zpool_type = =3D ZSWAP_ZPOOL_DEFAULT;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0zswap_zpool_type = =3D CONFIG_ZSWAP_ZPOOL_DEFAULT;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 has_zpool =3D zpool= _has_pool(zswap_zpool_type);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!has_zpool) {
--000000000000761db40597e3d471--