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 6B7BAECAAA2 for ; Sun, 28 Aug 2022 20:46:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F353E940008; Sun, 28 Aug 2022 16:46:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBF34940007; Sun, 28 Aug 2022 16:46:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3903940008; Sun, 28 Aug 2022 16:46:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BF8A5940007 for ; Sun, 28 Aug 2022 16:46:14 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8A1AD1C31CF for ; Sun, 28 Aug 2022 20:46:14 +0000 (UTC) X-FDA: 79850183868.01.6AF7624 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) by imf08.hostedemail.com (Postfix) with ESMTP id 2FDBA160051 for ; Sun, 28 Aug 2022 20:46:14 +0000 (UTC) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-33dc345ad78so153898287b3.3 for ; Sun, 28 Aug 2022 13:46:13 -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=rcuj4eqor/tMUl+92xtJXWtyAbmWdiW/DNBcK8L1A4E=; b=EpmLESfRnDAlQrkQMdkOozd2wC8lw1XI3R60wjUECEIDUttx3DpMndFz4YUg799pwr F31NQI3MX9bRqm4k5D3/Kec4ytw5SfSlAr538JlBYj+EVTAIH+TcyrtOGQLcdLGWNqvR 6X9P//9c7xliyx0z0QLk9SSfsXwME9+rv3KQA= 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=rcuj4eqor/tMUl+92xtJXWtyAbmWdiW/DNBcK8L1A4E=; b=fmy8oDI/lvz7Rh8CBWRf+qD4+wWbbdW/5Kiq5NhtmqEbeBOHHnyeNvkn9fji1AaYqP vESYu/wjad7l3rTykFN5PcsyzzwFxW/ZTSVOCXi0RgIrjoz6ZxD5e10Hlh4kXF5AAv4S 7chH8PIz3cdDft5pVyvR1AEgzmhPE1PKLtaJ1JIfFVOQG93mpgIT+l/n+A8TW6OKP3Fn yuu1IcycWntI4EVNwNnudcraIDPz7HkEHRhF2TUY3qxQ3vNGm4Jnr6GYHMwJ7lSytnIV bGyO0HNWPwShrV4gA8g6Bi/oMa7kGVyiJgiSo4gJsMkD/U92nab5cJ6ssI1EdXePWKqC F4UA== X-Gm-Message-State: ACgBeo2gqQ9WWMHv3jbSH6AAu942Fs6mcWQD0QJfJmHOvz/6qLMGGS3L xkCYX40FvMaLaFq1Xgx2C6kComOf9rfYu1OiIojQeg== X-Google-Smtp-Source: AA6agR45VAs8kV8OLlYZ9u1maUeGSQDPBTo+38GVMViWyD2hj4wlTTyvZmd53uf4bM3EluQs9NIBZlu6noIjC13N12k= X-Received: by 2002:a05:690c:806:b0:340:a4c7:60fb with SMTP id bx6-20020a05690c080600b00340a4c760fbmr7562350ywb.355.1661719573357; Sun, 28 Aug 2022 13:46:13 -0700 (PDT) MIME-Version: 1.0 References: <20220827104600.1813214-1-liushixin2@huawei.com> <20220827104600.1813214-4-liushixin2@huawei.com> In-Reply-To: <20220827104600.1813214-4-liushixin2@huawei.com> From: Vitaly Wool Date: Sun, 28 Aug 2022 22:46:02 +0200 Message-ID: Subject: Re: [PATCH -next v3 3/5] mm/zswap: replace zswap_init_{started/failed} with zswap_init_state 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=1661719574; a=rsa-sha256; cv=none; b=qCEB+fu6yeO+DnjJX6luvCGn6TIktmJQUBycsZw+1h843VB5DIj9VLn14uPeP/02gsao5E nJbC7zj7c09u11YNQ9FtUOlNAyEx/1TcRrhjMxCdBYlfiuCSh2yPtz/5QKhy1kg42gkmkB uH8skzYCiPEXmd2jhND4ug6v2Z6Uy34= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=konsulko.com header.s=google header.b=EpmLESfR; dmarc=pass (policy=none) header.from=konsulko.com; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661719574; 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=rcuj4eqor/tMUl+92xtJXWtyAbmWdiW/DNBcK8L1A4E=; b=TxSgfwPJrIXSeHCn4xpaAhAUAQkTDEjrwr91ywqPTZt21wzQ9PRCb0tReyTfr83goAv0x7 16OU+2vSk8rYwhd9f3MJxoB7yPtBOURmzYc8efbLmpzdN2WtUn/s+XDiFs7NRd7eDo53qa 3chYJOseQnvVG7HBJWDcJg+dYa0lgek= X-Rspamd-Server: rspam11 X-Rspam-User: X-Rspamd-Queue-Id: 2FDBA160051 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=konsulko.com header.s=google header.b=EpmLESfR; dmarc=pass (policy=none) header.from=konsulko.com; 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 X-Stat-Signature: ocadercr86ardhrwag3g1z418ute9tg9 X-HE-Tag: 1661719574-457375 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: > > zswap_init_started indicates that the initialization is started. And > zswap_init_failed indicates that the initialization is failed. As we will > support to init zswap after system startup, it's necessary to add a state > to indicate the initialization is complete and succeed to avoid > concurrency issues. Since we don't care about the difference between > init started with init completion. We only need three states: > uninitialized, initial failed, initial succeed. > > Signed-off-by: Liu Shixin Reviewed-by: Vitaly Wool > --- > mm/zswap.c | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 2d48fd59cc7a..84e38300f571 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -214,11 +214,12 @@ static DEFINE_SPINLOCK(zswap_pools_lock); > /* pool counter to provide unique names to zpool */ > static atomic_t zswap_pools_count = ATOMIC_INIT(0); > > -/* used by param callback function */ > -static bool zswap_init_started; > +#define ZSWAP_UNINIT 0 > +#define ZSWAP_INIT_SUCCEED 1 > +#define ZSWAP_INIT_FAILED 2 > > -/* fatal error during init */ > -static bool zswap_init_failed; > +/* init state */ > +static int zswap_init_state; > > /* init completed, but couldn't create the initial pool */ > static bool zswap_has_pool; > @@ -772,7 +773,7 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, > char *s = strstrip((char *)val); > int ret; > > - if (zswap_init_failed) { > + if (zswap_init_state == ZSWAP_INIT_FAILED) { > pr_err("can't set param, initialization failed\n"); > return -ENODEV; > } > @@ -784,7 +785,7 @@ 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) > + if (zswap_init_state == ZSWAP_UNINIT) > return param_set_charp(s, kp); > > if (!type) { > @@ -875,11 +876,11 @@ static int zswap_zpool_param_set(const char *val, > static int zswap_enabled_param_set(const char *val, > const struct kernel_param *kp) > { > - if (zswap_init_failed) { > + if (zswap_init_state == ZSWAP_INIT_FAILED) { > pr_err("can't enable, initialization failed\n"); > return -ENODEV; > } > - if (!zswap_has_pool && zswap_init_started) { > + if (!zswap_has_pool && zswap_init_state == ZSWAP_INIT_SUCCEED) { > pr_err("can't enable, no pool configured\n"); > return -ENODEV; > } > @@ -1476,8 +1477,6 @@ static int __init init_zswap(void) > struct zswap_pool *pool; > int ret; > > - zswap_init_started = true; > - > if (zswap_entry_cache_create()) { > pr_err("entry cache creation failed\n"); > goto cache_fail; > @@ -1517,6 +1516,7 @@ static int __init init_zswap(void) > goto destroy_wq; > if (zswap_debugfs_init()) > pr_warn("debugfs initialization failed\n"); > + zswap_init_state = ZSWAP_INIT_SUCCEED; > return 0; > > destroy_wq: > @@ -1530,7 +1530,7 @@ static int __init init_zswap(void) > zswap_entry_cache_destroy(); > cache_fail: > /* if built-in, we aren't unloaded on failure; don't allow use */ > - zswap_init_failed = true; > + zswap_init_state = ZSWAP_INIT_FAILED; > zswap_enabled = false; > return -ENOMEM; > } > -- > 2.25.1 >