Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2264324rwl; Thu, 6 Apr 2023 08:00:23 -0700 (PDT) X-Google-Smtp-Source: AKy350ZSUksQYJfX/lkwO2kAJwV+AQ0x3OGQwUmycyeT3bwutLBWnvnOqx4GJle2pWjCwRzcz+pS X-Received: by 2002:a17:902:e549:b0:1a1:c6a7:44f5 with SMTP id n9-20020a170902e54900b001a1c6a744f5mr13034221plf.52.1680793223604; Thu, 06 Apr 2023 08:00:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680793223; cv=none; d=google.com; s=arc-20160816; b=R7RSK2R/ppDK3SOSsTNF7chJtqWsVybdGAYDZ7gI6Jmt+SrlqGav/KiqX/FGKA61dt teL9fIMASaVx5QEqFtzzP28M+7oKNh7mqPx4C/8MZAhnNLf8nBf4jzp8dYBWSrzFvJat lLVXXpfH8z9iicpE/3DWdP5U9kjeQkpVGy6CHOVLYc6c33iRGS1POnLtO26mv0IENVfN h52kU0UtbCnEcl9LrfVykn5qMVEdmdMHV5uh5wrcWEWemgUUvcowNzoK7M76FFAoMOJc Od6fouXIjnmlxieENoVaS7VdT3OcjB6gGb/p+In7sX6OmkAML/16wl7h3qK8ft7kNeBp LQUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ssQN+dBZoakVC4TPQlTiHUnLUWWrhVH3l7VrAjYLSMc=; b=y2qMGtX9tuW2sRhUytgL5YDiMY/mLxhoxfuugmlDeuIZkYymiqFJbkNv1/mDeM8Xa8 cf149W7VqaHwErsqVMeLFLpkWo5M4tXR4A3nAmtrPPntqzvT3br4iRjPw3mHpW/iYMSc En9LArBPL55fg3+uS50K+PJJmhmkThLUvJHoZDLLvyJfDKJ0iABjN4hKe402iD7J3jkN N97eQA8D4NAW2u5aPDo0yGFjIFUjp84iB+72fk8f9og695PQFmAQI8jFoiP8QE2zuL3R lOQluWglTTbjJnCWvnXJ+WCHNKqkHKsCLUF35VuwH6wXdlUK02b+CBTWQ3OzusEUzFPy xfAg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a170902daca00b0019e87f429d7si1983488plx.376.2023.04.06.08.00.09; Thu, 06 Apr 2023 08:00:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239242AbjDFOyl (ORCPT + 99 others); Thu, 6 Apr 2023 10:54:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239389AbjDFOy1 (ORCPT ); Thu, 6 Apr 2023 10:54:27 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 328728A66 for ; Thu, 6 Apr 2023 07:53:51 -0700 (PDT) Received: by verein.lst.de (Postfix, from userid 2407) id 547E367373; Thu, 6 Apr 2023 16:53:47 +0200 (CEST) Date: Thu, 6 Apr 2023 16:53:47 +0200 From: Christoph Hellwig To: Liu Shixin Cc: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Nathan Chancellor , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH -next v8 3/3] mm/zswap: delay the initialization of zswap Message-ID: <20230406145347.GB11839@lst.de> References: <20230403121318.1876082-1-liushixin2@huawei.com> <20230403121318.1876082-4-liushixin2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230403121318.1876082-4-liushixin2@huawei.com> User-Agent: Mutt/1.5.17 (2007-11-01) X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_NONE,SPF_NONE 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 Mon, Apr 03, 2023 at 08:13:18PM +0800, 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. > > Signed-off-by: Liu Shixin > --- > mm/zswap.c | 56 +++++++++++++++++++++++++++++++++++++++++------------- > 1 file changed, 43 insertions(+), 13 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 9169c2baee87..14db57450bfd 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 *, > @@ -222,6 +224,9 @@ enum zswap_init_type { > > static enum zswap_init_type 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; > > @@ -654,7 +659,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; > > @@ -763,21 +768,28 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, > char *s = strstrip((char *)val); > int ret; > > + mutex_lock(&zswap_init_lock); > switch (zswap_init_state) { > case ZSWAP_UNINIT: > /* if this is load-time (pre-init) param setting, > * don't create a pool; that's done during init. > */ > - return param_set_charp(s, kp); > + ret = param_set_charp(s, kp); > + mutex_unlock(&zswap_init_lock); > + return ret; > case ZSWAP_INIT_SUCCEED: > /* no change required */ > - if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) > + if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) { > + mutex_unlock(&zswap_init_lock); > return 0; > + } > break; > case ZSWAP_INIT_FAILED: > pr_err("can't set param, initialization failed\n"); > + mutex_unlock(&zswap_init_lock); > return -ENODEV; > } > + mutex_unlock(&zswap_init_lock); The pattern here looks a bit odd. Can you split the code that the ZSWAP_INIT_SUCCEED case falls through into a helper, then just assign ret inside the switch statement, break out and do a single unlock and return? > + /*if this is load-time (pre-init) param setting, only set param.*/ missing space after the initial and before the last * here. But except for these nitpicks this version looks good to me now.