Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp279612rwn; Wed, 14 Sep 2022 20:55:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5v6ploj8xPnhle6OECt4fo7PD8dp/rZR7f8L3BsRpMndiHpLepFBUzVWWHrkWKygqsVd/5 X-Received: by 2002:a05:6402:1cc1:b0:453:1517:94e4 with SMTP id ds1-20020a0564021cc100b00453151794e4mr594148edb.399.1663214129862; Wed, 14 Sep 2022 20:55:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663214129; cv=none; d=google.com; s=arc-20160816; b=Q/4zeyI834SE72NcJFvMkq+b3yGTJgVJZfsRh/aLLSagOD3bRatLiA8ubgefjJAIJF qPNzARbI+qA1mU0YZ/sWGo3+STS1ys0k6SAEwa/U3LfYkda/CJpU403uIhjCRyxToZBr KXHzT3FjpCKNJ6TLV1SNeeusqwYqrOkRph1cGEQM9R7dsROjkxNQ9SD/njdVtnGn7xVO fSnqSXmCRdmCUzY1TFAtG8xbS/3xCrEYED5z1Bb7O5f5xqcBE3x0QOjIeiwqTdrsxtgx kRO9VplTMm7vqaTKKlKMnZ8tab6y2ydw14QU/HvhT+2fqCQuB7wEQW83irmOqOrSwL4x Ab6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+HmHSV2NYV3DgK5b2IIHOduZfAPoEHHLMKXhxHU3EVA=; b=nnJybL+JkWMR1EQSkd5lD5hcxTdVpd5phjNzbfNSPj2mRqi0s2BSA25+KOLeGmEPx8 T3mZeEldUAavMXqJAa/WL/3X6GpUqBiAAGAp/5SsOV45zF0ay3TcjL998JhQP6M+5RlO hqmcOScw+ZfaQoXzWddyz4ZIwJ3wvqzKCCqiI+3FxRXXXl84lqQk+QapCij6i2CXc92A VHsntJ8DKymPDm1jcsO6GMhU98VxZZrDp15DZGSzZDASeY4Ks/XhJKdhsFtcxrNWvkEM 01tJAUdSXQpPJGWTL3ChGyw+URd5zv8QgtOVkCvXszmiYIA5GhFA6+UjBL07Zh7Uj76t E2FQ== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp15-20020a1709073e0f00b0077f009c0f04si8130391ejc.94.2022.09.14.20.55.04; Wed, 14 Sep 2022 20:55:29 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230225AbiIODQe (ORCPT + 99 others); Wed, 14 Sep 2022 23:16:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230188AbiIODQS (ORCPT ); Wed, 14 Sep 2022 23:16:18 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D1FE915F2 for ; Wed, 14 Sep 2022 20:16:16 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MSj0V18yTzNmJw; Thu, 15 Sep 2022 11:11:38 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 15 Sep 2022 11:16:07 +0800 Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 15 Sep 2022 11:16:07 +0800 From: Liu Shixin To: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Nathan Chancellor , "Christoph Hellwig" CC: , , Liu Shixin , Kefeng Wang Subject: [PATCH v5 3/5] mm/zswap: replace zswap_init_{started/failed} with zswap_init_state Date: Thu, 15 Sep 2022 11:50:01 +0800 Message-ID: <20220915035003.3347466-4-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220915035003.3347466-1-liushixin2@huawei.com> References: <20220915035003.3347466-1-liushixin2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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 --- 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