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=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 519A0C17441 for ; Fri, 8 Nov 2019 23:51:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9907620865 for ; Fri, 8 Nov 2019 23:51:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9907620865 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=maciej.szmigiero.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2A9C56B0003; Fri, 8 Nov 2019 18:51:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 25B856B0006; Fri, 8 Nov 2019 18:51:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1709B6B0007; Fri, 8 Nov 2019 18:51:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id 018866B0003 for ; Fri, 8 Nov 2019 18:51:20 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 876A24DD4 for ; Fri, 8 Nov 2019 23:51:20 +0000 (UTC) X-FDA: 76134759120.11.head86_b97ecc52c821 X-HE-Tag: head86_b97ecc52c821 X-Filterd-Recvd-Size: 9679 Received: from vps-vb.mhejs.net (vps-vb.mhejs.net [37.28.154.113]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Fri, 8 Nov 2019 23:51:19 +0000 (UTC) Received: from MUA by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1iTE25-0005W3-7R; Sat, 09 Nov 2019 00:51:13 +0100 From: "Maciej S. Szmigiero" To: Seth Jennings , Dan Streetman Cc: Vitaly Wool , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] zswap: allow setting default status, compressor and allocator in Kconfig Date: Sat, 9 Nov 2019 00:51:07 +0100 Message-Id: <20191108235107.2837339-1-mail@maciej.szmigiero.name> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: 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=3D1" command line parameter and if one wants a different compressor or pool allocator than the default lzo / zbu= d 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 --- 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. mm/Kconfig | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++- mm/zswap.c | 26 +++++++----- 2 files changed, 130 insertions(+), 12 deletions(-) diff --git a/mm/Kconfig b/mm/Kconfig index a5dae9a7eb51..4a00d9ebf774 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=3Dy - select CRYPTO_LZO select ZPOOL help A lightweight compressed cache for swap pages. It takes @@ -541,6 +540,121 @@ config ZSWAP they have not be fully explored on the large set of potential configurations and workloads that exist. =20 +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=3D' 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 + 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=3D' 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 + 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=3D' option. + config ZPOOL tristate "Common API for compressed memory storage" help diff --git a/mm/zswap.c b/mm/zswap.c index 46a322316e52..71795b6f5b71 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -71,8 +71,12 @@ static u64 zswap_duplicate_entry; =20 #define ZSWAP_PARAM_UNSET "" =20 -/* Enable/disable zswap (disabled by default) */ +/* Enable/disable zswap */ +#ifdef CONFIG_ZSWAP_DEFAULT_ON +static bool zswap_enabled =3D true; +#else static bool zswap_enabled; +#endif static int zswap_enabled_param_set(const char *, const struct kernel_param *); static struct kernel_param_ops zswap_enabled_param_ops =3D { @@ -82,8 +86,7 @@ static struct kernel_param_ops zswap_enabled_param_ops = =3D { module_param_cb(enabled, &zswap_enabled_param_ops, &zswap_enabled, 0644)= ; =20 /* 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; static int zswap_compressor_param_set(const char *, const struct kernel_param *); static struct kernel_param_ops zswap_compressor_param_ops =3D { @@ -95,8 +98,7 @@ module_param_cb(compressor, &zswap_compressor_param_ops= , &zswap_compressor, 0644); =20 /* 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; static int zswap_zpool_param_set(const char *, const struct kernel_param= *); static struct kernel_param_ops zswap_zpool_param_ops =3D { .set =3D zswap_zpool_param_set, @@ -569,11 +571,12 @@ static __init struct zswap_pool *__zswap_pool_creat= e_fallback(void) bool has_comp, has_zpool; =20 has_comp =3D 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 =3D ZSWAP_COMPRESSOR_DEFAULT; + zswap_compressor =3D CONFIG_ZSWAP_COMPRESSOR_DEFAULT; has_comp =3D crypto_has_comp(zswap_compressor, 0, 0); } if (!has_comp) { @@ -584,11 +587,12 @@ static __init struct zswap_pool *__zswap_pool_creat= e_fallback(void) } =20 has_zpool =3D 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 =3D ZSWAP_ZPOOL_DEFAULT; + zswap_zpool_type =3D CONFIG_ZSWAP_ZPOOL_DEFAULT; has_zpool =3D zpool_has_pool(zswap_zpool_type); } if (!has_zpool) {