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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DA6BC6FD1F for ; Wed, 22 Mar 2023 17:17:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 829A76B0071; Wed, 22 Mar 2023 13:17:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D90E6B0072; Wed, 22 Mar 2023 13:17:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 653276B0075; Wed, 22 Mar 2023 13:17:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 504116B0071 for ; Wed, 22 Mar 2023 13:17:27 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2059CAB003 for ; Wed, 22 Mar 2023 17:17:27 +0000 (UTC) X-FDA: 80597190534.05.DCA4C46 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf07.hostedemail.com (Postfix) with ESMTP id 2B2B240020 for ; Wed, 22 Mar 2023 17:17:24 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=konsulko.com header.s=google header.b=CQ2n4+5T; dmarc=pass (policy=none) header.from=konsulko.com; spf=pass (imf07.hostedemail.com: domain of vitaly.wool@konsulko.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=vitaly.wool@konsulko.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679505445; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UittgdXM3g+Qbt7hZmz9fDwi45VTM0z8aAr7Vg+o+os=; b=RgMCC+7dqUDzx67J0WY+75KMuaCvjNKSJ8DzOKfktE+tIkdYMgSl35mO8l1IafSXq4h8tb 3azbjht3UjN3bRq/XTuU+rTE7r30SZbKpXVZf9WQlSpr//JNcrnqzs1N8r/x9ri6Mq9M+T cZbkIKGZYOIObcOma5Jo90JAke/xWP4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=konsulko.com header.s=google header.b=CQ2n4+5T; dmarc=pass (policy=none) header.from=konsulko.com; spf=pass (imf07.hostedemail.com: domain of vitaly.wool@konsulko.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=vitaly.wool@konsulko.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679505445; a=rsa-sha256; cv=none; b=Ok1FRg8N6loaDwPpf+HzOz026zqN3ZhebjRkKR8k1/xys0asxSMQ5GQoaxhVy3SfDM3BTp z/l4tD76MCo8bJCsbDDU++HlaEobkplmRXwvqrAcKwA/PkLJTWuGRGuoE/Xw+I4/hev+Hj Uk8yLtLIGJU1d/ZwZlzz9fHNThM4Z8E= Received: by mail-pl1-f175.google.com with SMTP id iw3so19912774plb.6 for ; Wed, 22 Mar 2023 10:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1679505444; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UittgdXM3g+Qbt7hZmz9fDwi45VTM0z8aAr7Vg+o+os=; b=CQ2n4+5TduAQlvRuSopwcvMBwx1aMvm0NwYexjQsp/nXY2wMaefj0B1ffmN8DwAkv2 IKNoqVGc8o5V77z7pxmAKfmYrJk3fkC+m/B6vR+qyAkOjXZRI91G2B2UQ/ohroF2PhVD HP64OD7bXnzRISmJ9dvNmQj/AjwSSW3Pqvi9s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679505444; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UittgdXM3g+Qbt7hZmz9fDwi45VTM0z8aAr7Vg+o+os=; b=H/uLhxr9tkdIssNjpZRqh/rLO2KLfn+SC6DZY9aLkm4EXYZ62ryqpF23UIJ7+cVWrZ x4oGvh31IhjyhxatF7gKQXuRldy79ppS5mmZViNRZwXFOpiCUIIovjDKD/qHc3gScNvd KxWEI/YWGg+X6wgEPcBm7ff2PHsjIImo93+3byOdSjXUAAD2XzKBNlUz9YELahjEW1zq 0uAV4RjPG7H6v9Ms2D7YYqdQ2ga1ql0OuDxmf5g4AX+IM3LQ2+OC3hpMVVYJ+0T+mfjF TanGBUwXaveVQQNzMuNKIJfH5YxZCvwdCOAxLPGHDsw5ruB1wQ3dfthgvSuEDrRfA76o bN5Q== X-Gm-Message-State: AO0yUKU2Nkl8Baq0M4aCHKF2Hp4v4RN3c6YTTObINlTZVZFLvNPcIXC9 4T8ntTwt9oVzDrBuWw9iJ2+Azs4yqtAMS5RbzQBPGw== X-Google-Smtp-Source: AK7set/gRfEg9ZkMBG8RvdC24JfXTCE8uD3xzdGBfjruc84EYtVudASDkkG+lq/J5/fnXnQhZxyJt4P4RbTPQS/9SeY= X-Received: by 2002:a17:902:6a84:b0:19f:2aa4:b1e5 with SMTP id n4-20020a1709026a8400b0019f2aa4b1e5mr1495889plk.2.1679505443863; Wed, 22 Mar 2023 10:17:23 -0700 (PDT) MIME-Version: 1.0 References: <20230322102006.780624-1-liushixin2@huawei.com> <20230322102006.780624-3-liushixin2@huawei.com> In-Reply-To: <20230322102006.780624-3-liushixin2@huawei.com> From: Vitaly Wool Date: Wed, 22 Mar 2023 18:17:12 +0100 Message-ID: Subject: Re: [PATCH -next v6 2/2] mm/zswap: delay the initializaton of zswap To: Liu Shixin Cc: Seth Jennings , Dan Streetman , Andrew Morton , Nathan Chancellor , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 2B2B240020 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 85d41rrf338bm3cdwx6auoffq8qymjmo X-HE-Tag: 1679505444-351674 X-HE-Meta: U2FsdGVkX1/xpTWlImQM/c/ubVifZrbzMeJUgjKVaQO49Uq7ygClncudEyIZN4WgfiFhsxIk+DfW0VqJqwRfnNKjpTD796hfUmo/YqX+oS1Jem2aOxR3wNZgSu7O40zPF5dbP+j3E3Xj9cYyIDQDGDG/aRZBk+Uc5GkBLprXMaL9UssO6c4vhbA1fhPFR+ojYqhKY4oy4qAtUGuDMcAbwbtG03G90F1pqvqEyKxi9NETW4sL0G/TCVMIka/laWw3SHO73NcaQmyJQDdZ/Z3OYwCH6z6TeXVK6sP0QiiXeH60UVV4bJ9MbaoOpFrUq3G9kaQvBpPxcYIpdEyEhlD0FcvD/MUaMS/mdArGwEoAfCv7AsPtghPC7M/QpNhEBRs8zG/dhPxDkxymXG7eywPUwGU67G9IdtLWGNpLV1IiOrYj0CNw0dL7SEaOIDruQEYgyzWt3sqiJlesX2a/Znolc0AVysOX9Wi4+hOEmAIDg1SceWw6M00m4T4sRyvX2JJEPz2awpkLGWx8VryT14eYsSZ2jskhPIxERykGTxwh6KliRzXxgHuYZHseWx9/H32Y1rdhfXVC6nEWRActiOsiCQze+zpE7YGF4SqhEZ/S+qvL3to0AohYYeJaeZTLq092KOTnOoZuX+ckeenbvwvvpBSlGZqpdftqwMmMf8DabT9iG13WGIjoVeHWg0TnembFVwEMK2Io7hvQtdnXQMI2Tn5vp2EQuHza3kLANLEMFZDERSbg1HS+yAXBcH/x9pMkwVN6dRBiybONHt2mnIocwsxJOtNvB7aSAxTkKjmZYT45Mm5aS0R6mHVJ2wapAzJBoeghCqau//gA1w69bfF+o+QRzYytqeC3XHwucUNFeFDGNogjuttxVrb78ZHXnEPvmIgUcVKUfgWW+LpTeGNlHie20fpH37eCwVFTYQP4Tj5kqo8VcIPtwhUuqUpVjZw/uGKiBJAJTTiLFmef0FT 5ouaWKWt +a+D5CbISC5uIJehIO1GgQy4S45Iy/A4sSCO7bnOG8cnFmOubrfpzVfgsGW1gq+3J7Bm2hsrrRp/xC3KRg1dk5dPVj2jhFo+e3UYFirJ8WFVc++okQUS6MvPrVmnElaYtu21gqcX7K6eIm/7naFElYB2lnInTDRzipxujkvpfz2/jVhHnySCAM3dEdvtQBoMT/+0kwjwlgwSObTw6dfcWqH6KfJEMpLi/eEkNTZjOsb8XuiUo4TtEeSRJefPoFOzbR00zWB09pQ8YlFtNHRMpxBJEZb9nI9+ab8k4/YcrO/r3irjsvBau9IUtf44YZfjzKHgWZDWBxyhIKys= 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: On Wed, Mar 22, 2023 at 10:30=E2=80=AFAM Liu Shixin = wrote: > > Since some users may not use zswap, the zswap_pool is wasted. Save memory > by delaying the initialization of zswap until enabled. To be honest, I'm not a huge fan of this. Would enabling zswap module build instead solve your problem? ~Vitaly > Signed-off-by: Liu Shixin > --- > mm/zswap.c | 51 +++++++++++++++++++++++++++++++++++++++++---------- > 1 file changed, 41 insertions(+), 10 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 09fa956920fa..3aed3b26524a 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -81,6 +81,8 @@ static bool zswap_pool_reached_full; > > #define ZSWAP_PARAM_UNSET "" > > +static int zswap_setup(void); > + > /* Enable/disable zswap */ > static bool zswap_enabled =3D IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON); > static int zswap_enabled_param_set(const char *, > @@ -220,6 +222,9 @@ static bool zswap_init_started; > /* fatal error during init */ > static bool zswap_init_failed; > > +/* used to ensure the integrity of initialization */ > +static DEFINE_MUTEX(zswap_init_lock); > + > /* init completed, but couldn't create the initial pool */ > static bool zswap_has_pool; > > @@ -272,13 +277,13 @@ static void zswap_update_total_size(void) > **********************************/ > static struct kmem_cache *zswap_entry_cache; > > -static int __init zswap_entry_cache_create(void) > +static int zswap_entry_cache_create(void) > { > zswap_entry_cache =3D KMEM_CACHE(zswap_entry, 0); > return zswap_entry_cache =3D=3D NULL; > } > > -static void __init zswap_entry_cache_destroy(void) > +static void zswap_entry_cache_destroy(void) > { > kmem_cache_destroy(zswap_entry_cache); > } > @@ -663,7 +668,7 @@ static struct zswap_pool *zswap_pool_create(char *typ= e, char *compressor) > return NULL; > } > > -static __init struct zswap_pool *__zswap_pool_create_fallback(void) > +static struct zswap_pool *__zswap_pool_create_fallback(void) > { > bool has_comp, has_zpool; > > @@ -784,8 +789,15 @@ static int __zswap_param_set(const char *val, const = struct kernel_param *kp, > /* if this is load-time (pre-init) param setting, > * don't create a pool; that's done during init. > */ > - if (!zswap_init_started) > - return param_set_charp(s, kp); > + if (!zswap_init_started) { > + mutex_lock(&zswap_init_lock); > + if (!zswap_init_started) { > + ret =3D param_set_charp(s, kp); > + mutex_unlock(&zswap_init_lock); > + return ret; > + } > + mutex_unlock(&zswap_init_lock); > + } > > if (!type) { > if (!zpool_has_pool(s)) { > @@ -884,6 +896,15 @@ static int zswap_enabled_param_set(const char *val, > if (res =3D=3D *(bool *)kp->arg) > return 0; > > + if (!zswap_init_started && (system_state =3D=3D SYSTEM_RUNNING)) = { > + mutex_lock(&zswap_init_lock); > + if (zswap_setup()) { > + mutex_unlock(&zswap_init_lock); > + return -ENODEV; > + } > + mutex_unlock(&zswap_init_lock); > + } > + > if (zswap_init_failed) { > pr_err("can't enable, initialization failed\n"); > return -ENODEV; > @@ -1451,7 +1472,7 @@ static const struct frontswap_ops zswap_frontswap_o= ps =3D { > > static struct dentry *zswap_debugfs_root; > > -static int __init zswap_debugfs_init(void) > +static int zswap_debugfs_init(void) > { > if (!debugfs_initialized()) > return -ENODEV; > @@ -1482,7 +1503,7 @@ static int __init zswap_debugfs_init(void) > return 0; > } > #else > -static int __init zswap_debugfs_init(void) > +static int zswap_debugfs_init(void) > { > return 0; > } > @@ -1491,12 +1512,13 @@ static int __init zswap_debugfs_init(void) > /********************************* > * module init and exit > **********************************/ > -static int __init init_zswap(void) > +static int zswap_setup(void) > { > struct zswap_pool *pool; > int ret; > > - zswap_init_started =3D true; > + if (zswap_init_started) > + return 0; > > if (zswap_entry_cache_create()) { > pr_err("entry cache creation failed\n"); > @@ -1537,6 +1559,7 @@ static int __init init_zswap(void) > goto destroy_wq; > if (zswap_debugfs_init()) > pr_warn("debugfs initialization failed\n"); > + zswap_init_started =3D true; > return 0; > > destroy_wq: > @@ -1551,11 +1574,19 @@ static int __init init_zswap(void) > cache_fail: > /* if built-in, we aren't unloaded on failure; don't allow use */ > zswap_init_failed =3D true; > + zswap_init_started =3D true; > zswap_enabled =3D false; > return -ENOMEM; > } > + > +static int __init zswap_init(void) > +{ > + if (!zswap_enabled) > + return 0; > + return zswap_setup(); > +} > /* must be late so crypto has time to come up */ > -late_initcall(init_zswap); > +late_initcall(zswap_init); > > MODULE_LICENSE("GPL"); > MODULE_AUTHOR("Seth Jennings "); > -- > 2.25.1 >