Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6420226rwl; Wed, 22 Mar 2023 10:20:10 -0700 (PDT) X-Google-Smtp-Source: AK7set8dPSmpPrci5w6LKwiNDEViVZFr+BfZCmA8UeZLW29aMZdMRaJRkvrClXijBhJBtHC9HZA+ X-Received: by 2002:a17:906:8470:b0:87b:e105:5d9a with SMTP id hx16-20020a170906847000b0087be1055d9amr7003886ejc.67.1679505610410; Wed, 22 Mar 2023 10:20:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679505610; cv=none; d=google.com; s=arc-20160816; b=SX+mfIYxuUAp2N9hxLv8kdMIV5C9nHnbD4Q5rfG+bGq8ScBr1k1HArBjoHLbOg6k4E ST+JfwPrGx24ktFsE4kk1zqUVkBhwoOGwnDI9Ig+31pPPfANpR7l2p/x/f7zFwEMA6Ez bWZc9js/ha1vDX8cCVukRVRzk3PL9VzXQisPHt1yBvTRSPHB7+qqO9YXf7nt4ObYRWt6 JzThL8M/ekIUu1nYVHOYk6uEsvPK11NlYrByCSRjwO3Bb/BaOnmQvSCYt+7WOPuzsyIp qJn11rr/q9zKjZ6F4BWFtRgMRe0UarLOA+FNp0voM8hRlTnv7G/ZDUQA3QPlIfmrB2iO KLgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=UittgdXM3g+Qbt7hZmz9fDwi45VTM0z8aAr7Vg+o+os=; b=IQvVd9URK5dqVZIX6ibiSQrn4uS7/tBzCxTt20XMs8KT5VytlHfAagDAaVG69iv5x1 iUV5Vy2q63poP/WY5BxIjqkRWNsNjSsmx4nt5KKGwTSoUI+9kL/nE1PuyVfON8Se61s7 rqGh4gsPOYwPw3V1EctbNsuYHNSYiz0fahqNufhkdc430OB98dHKTkS2GL7GzmhIEoCM xYDS7XFJ3G2D1/EZHBq1aGB3BedZz/4+4Ozn0qxbxZbDvsEPNXsIbE9zMbv8k/SWWMqa Z6KgHIXVEi4zxjGTDF4pWhpYumycizp4Et6i7sB6eOc/Q9Qcq9HMprN2Nq1xQJYK8gx3 RpOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@konsulko.com header.s=google header.b=CQ2n4+5T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=konsulko.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q19-20020a170906b29300b0092bf128c4e5si16213046ejz.192.2023.03.22.10.19.44; Wed, 22 Mar 2023 10:20:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@konsulko.com header.s=google header.b=CQ2n4+5T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=konsulko.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229645AbjCVRSJ (ORCPT + 99 others); Wed, 22 Mar 2023 13:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229836AbjCVRSF (ORCPT ); Wed, 22 Mar 2023 13:18:05 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5D4F66D15 for ; Wed, 22 Mar 2023 10:17:35 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id fy10-20020a17090b020a00b0023b4bcf0727so19854645pjb.0 for ; Wed, 22 Mar 2023 10:17:35 -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=6M9/KVZlyHJC0S8xN5HT+v1dwVLNnOFkr8aN4CroaqBn9nC3Sw4MIZ8g8TRdIPXOzG YEj0M+qsGemc6Is074oIk7s9mDM4EGcx5EZgXNObwVY+XT5Wfkl7zQUo7fh4IpgxTfLE C0+VO/hH4p+4llahCWMK+JFgcRpfEAQCSEk0yvn3HE6bL/Kx52OnnXkkWc0+4YX7RSXB nEeLQl/kvzC3yrVBVdT5b4HYCp2AcmtN45vpoXx+yX7oYIAHjZu7mqjHo5FlYyrnt9MS /9+YvR9zJynoNN90Dmc0vL9cojYy9WSVCMsBIR6+9Uvetfo6hj41NQnLwon+lArUJDUy DKDA== X-Gm-Message-State: AO0yUKUhJyDn/p1Bk0FpYYfIiNsbgUrSU4LoBuMnuyaAfCmKKW+6w9t4 bidC1kgONZWEqX/D/Q89s8dMerYdBpWmPzjfPXiHKQ== 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-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >