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 E4C62ECAAD5 for ; Sun, 28 Aug 2022 20:45:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D60E940008; Sun, 28 Aug 2022 16:45:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45ED0940007; Sun, 28 Aug 2022 16:45:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D8F4940008; Sun, 28 Aug 2022 16:45:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 18D8F940007 for ; Sun, 28 Aug 2022 16:45:36 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D4DE3A08EC for ; Sun, 28 Aug 2022 20:45:35 +0000 (UTC) X-FDA: 79850182230.24.ACB1048 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) by imf08.hostedemail.com (Postfix) with ESMTP id 9393F16004E for ; Sun, 28 Aug 2022 20:45:34 +0000 (UTC) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-33dce2d4bc8so153741877b3.4 for ; Sun, 28 Aug 2022 13:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=lTbQlx4PkxNAh0QSudwPBNTkD42cR5tC/Ap2lDc3w6Y=; b=KhlOQIOAeTpdnM+sF8snTdaCrhKCwi76ieHPVn3D/E7D/fYvKtYTy3zJmfp0fOeCkG 4zikwDxVGfZh5DgI/6iyd2GC7tTih9smKiLO7R5l7aYxeXNbDzyPckUEYLzdAFoazV3j Da5nPikOGeazQBY8c0cAg3EiJU7IdbO4jKwqo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=lTbQlx4PkxNAh0QSudwPBNTkD42cR5tC/Ap2lDc3w6Y=; b=6TdP8BjFnSrJM0z6936dMFVN8Kw0jM2KMuK6kIO3HexWSA4y2v2AHGmaggxGc2UGiI vUm5Z48sEve8LAF0EAVg2wvUOenmGnxvc9Y6MNZz7MPe1D5fOvmJzJFkUWesZ7s1Bn0v mQjQGJ2cy3coaFY6n1wt8wInmwXhcAuhUuCe8G1P8s5R+fL5+CtHh6EhRzbR0uGQN77R tK4u45It8LZHThMmmSyMpNuLp8LQ4oQDyupjR1aVaE73i4hAMNdaAPYlKGZzkFK88WOH JkudBuMjMbjuGXHL10BqPooi41TMNmJI6u6BbgE1sLVCVqtvEJJSL5eX9bGRg45LlsPW ju0A== X-Gm-Message-State: ACgBeo1SEYnpP5NU0OUyjMmIXP6zPYFl7dM6Cr3LPXjMlHdb4TCmzN3p 40BrAsP01MtaXM1R90/fDi3MZkF/XAGEXlZKksLmtQ== X-Google-Smtp-Source: AA6agR6KtLzg40ma1/vaSZ9K4goGn5yX893iWBPL7fGmJbAiLLyjq9anzIP7IbhHDLl0h2FZl1fGW2/WtxDW+ehuaTg= X-Received: by 2002:a0d:cb55:0:b0:340:b1ef:6dae with SMTP id n82-20020a0dcb55000000b00340b1ef6daemr6250015ywd.287.1661719533782; Sun, 28 Aug 2022 13:45:33 -0700 (PDT) MIME-Version: 1.0 References: <20220827104600.1813214-1-liushixin2@huawei.com> <20220827104600.1813214-5-liushixin2@huawei.com> In-Reply-To: <20220827104600.1813214-5-liushixin2@huawei.com> From: Vitaly Wool Date: Sun, 28 Aug 2022 22:45:22 +0200 Message-ID: Subject: Re: [PATCH -next v3 4/5] mm/zswap: delay the initializaton of zswap until the first enablement To: Liu Shixin Cc: Seth Jennings , Dan Streetman , Andrew Morton , Nathan Chancellor , Christoph Hellwig , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kefeng Wang Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661719534; a=rsa-sha256; cv=none; b=BXM+ELnavqaxGXWVIE2BXXr4zHeEz9//cFjOAFI4NMogs6ZembYQt5WGH5azGHzbSz8K34 cLikMbBu+fusw6LBE8kSVGVKqi03I5ajbNRruOULEU2Ta/27UmM4xwDHh5RRambzCVNkIV p06zyqXX59FkCb1CYjIwIDer3m9rBo0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=konsulko.com header.s=google header.b=KhlOQIOA; spf=pass (imf08.hostedemail.com: domain of vitaly.wool@konsulko.com designates 209.85.128.176 as permitted sender) smtp.mailfrom=vitaly.wool@konsulko.com; dmarc=pass (policy=none) header.from=konsulko.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661719534; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lTbQlx4PkxNAh0QSudwPBNTkD42cR5tC/Ap2lDc3w6Y=; b=SQBBKu/hnG01psDWjyexmMvDGPYrT2bETFOlu66SlD7ibJLm+X68FGyf4kj22tZdGG3imd Iet7+ceOn4KMPu93cKA83DstL3bvPSsD8dWjegiJ1AOzxJmGBWcIyBur8WIU4fiIzQftRs XHnOMOXQd5CqDomKunWVtbip2HOpeZc= X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=konsulko.com header.s=google header.b=KhlOQIOA; spf=pass (imf08.hostedemail.com: domain of vitaly.wool@konsulko.com designates 209.85.128.176 as permitted sender) smtp.mailfrom=vitaly.wool@konsulko.com; dmarc=pass (policy=none) header.from=konsulko.com X-Rspamd-Server: rspam10 X-Stat-Signature: j4wu44debdj4ap6z1ehu4tk4mniampx8 X-Rspamd-Queue-Id: 9393F16004E X-HE-Tag: 1661719534-947807 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 Sat, Aug 27, 2022 at 12:12 PM Liu Shixin wrote: > > In the initialization of zswap, about 18MB memory will be allocated for > zswap_pool in my machine. Since not all users use zswap, the memory may be > wasted. Save the memory for these users by delaying the initialization of > zswap to first enablement. > > Signed-off-by: Liu Shixin Reviewed-by: Vitaly Wool > --- > mm/zswap.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- > 1 file changed, 40 insertions(+), 10 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 84e38300f571..4c476c463035 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 = IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON); > static int zswap_enabled_param_set(const char *, > @@ -220,6 +222,8 @@ static atomic_t zswap_pools_count = ATOMIC_INIT(0); > > /* init state */ > static int zswap_init_state; > +/* 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; > @@ -273,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 = KMEM_CACHE(zswap_entry, 0); > return zswap_entry_cache == NULL; > } > > -static void __init zswap_entry_cache_destroy(void) > +static void zswap_entry_cache_destroy(void) > { > kmem_cache_destroy(zswap_entry_cache); > } > @@ -664,7 +668,7 @@ static struct zswap_pool *zswap_pool_create(char *type, 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; > > @@ -782,11 +786,17 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, > if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) > return 0; > > - /* if this is load-time (pre-init) param setting, > + /* > + * if zswap has not been initialized, > * don't create a pool; that's done during init. > */ > - if (zswap_init_state == ZSWAP_UNINIT) > - return param_set_charp(s, kp); > + mutex_lock(&zswap_init_lock); > + if (zswap_init_state == ZSWAP_UNINIT) { > + ret = param_set_charp(s, kp); > + mutex_unlock(&zswap_init_lock); > + return ret; > + } > + mutex_unlock(&zswap_init_lock); > > if (!type) { > if (!zpool_has_pool(s)) { > @@ -876,6 +886,14 @@ static int zswap_zpool_param_set(const char *val, > static int zswap_enabled_param_set(const char *val, > const struct kernel_param *kp) > { > + if (system_state == 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_state == ZSWAP_INIT_FAILED) { > pr_err("can't enable, initialization failed\n"); > return -ENODEV; > @@ -1432,7 +1450,7 @@ static const struct frontswap_ops zswap_frontswap_ops = { > > static struct dentry *zswap_debugfs_root; > > -static int __init zswap_debugfs_init(void) > +static int zswap_debugfs_init(void) > { > if (!debugfs_initialized()) > return -ENODEV; > @@ -1463,7 +1481,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; > } > @@ -1472,11 +1490,14 @@ 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; > > + if (zswap_init_state != ZSWAP_UNINIT) > + return 0; > + > if (zswap_entry_cache_create()) { > pr_err("entry cache creation failed\n"); > goto cache_fail; > @@ -1534,8 +1555,17 @@ static int __init init_zswap(void) > zswap_enabled = false; > return -ENOMEM; > } > + > +static int __init zswap_init(void) > +{ > + /* skip init if zswap is disabled when system startup */ > + 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 >