Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1227375rwe; Sat, 27 Aug 2022 03:44:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR4cpn61vgyufK8fiL4dtRKl5XshB/l5uTBfZbGYClRTiBLV5Q3cycrxvbTRvDOsIFV6ILpE X-Received: by 2002:a17:90b:4b81:b0:1fa:ef82:c512 with SMTP id lr1-20020a17090b4b8100b001faef82c512mr8880672pjb.78.1661597069188; Sat, 27 Aug 2022 03:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661597069; cv=none; d=google.com; s=arc-20160816; b=vIR1GVywQZkk0s/nuuQ72srnQpBMfS/KK26XrzCqzA4WofiqAg7b3R+8xksVIjT1C+ +82gUpOrlA3smKd3c4NuPupOQAoOBZU3GWA4f4DTjg8OV9f5HDe1XygQEAh4ZrooEYqD rYfGXDmTsPThrVq+m8ID3FBnl3EvZL4grU1O0DMfQoh9RIK0Lq0jkflBqDlNxYN15QFK 7RC0NaEtTEoLhhjigYhRquILHZcVvz1HCEhK0hnA2e9JEG4OfAL/kClK6xKunj/PLlNY Xv84HrEUNmeTgKKKjFedNkV5Ro6n/R/u516BCB7mL9C2ugN0xDfwis6oxuVzgAOnZvDf tkgw== 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=n5sQ2cRAPazp1xfyAaMAjnqshS58N319wemK4QE0AtCLp5/ez138nVM/nMm2m2dDD5 uoH99nDLmYbmMhAYn33dCIKeBAzaBjcktkxHcSqqAwSwyhToY8q3KKkJispZzzTo5gPs /zU17zzlqi0EG1HuvoPejCCi3a9PZ2nUKH8aU85wb7kbr1i18NJRkElq6Z6bW8OhPg8j C9VFOBZfA93WMCZkSBYYxKIr+oqI3EFpEscS/DGQRocG+hXvuAbgxaaTiuiDvBWsRpez 6bXF2p8SWDmDi8Ajp98ib1t2tWX1O58nbfbV0sfSjuA/q1Nk5+GmW4gyRt+b9Ok3mQqH TW/Q== 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 d15-20020a056a00244f00b00536a53b34a5si3980873pfj.262.2022.08.27.03.44.17; Sat, 27 Aug 2022 03:44: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 S236641AbiH0KL5 (ORCPT + 99 others); Sat, 27 Aug 2022 06:11:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233463AbiH0KLp (ORCPT ); Sat, 27 Aug 2022 06:11:45 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE1A124F01 for ; Sat, 27 Aug 2022 03:11:43 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4MFC9y5qdZzGpGr; Sat, 27 Aug 2022 18:09:58 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 27 Aug 2022 18:11:41 +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; Sat, 27 Aug 2022 18:11:41 +0800 From: Liu Shixin To: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Nathan Chancellor , "Christoph Hellwig" CC: , , Liu Shixin , Kefeng Wang Subject: [PATCH -next v3 3/5] mm/zswap: replace zswap_init_{started/failed} with zswap_init_state Date: Sat, 27 Aug 2022 18:45:58 +0800 Message-ID: <20220827104600.1813214-4-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220827104600.1813214-1-liushixin2@huawei.com> References: <20220827104600.1813214-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: dggems705-chm.china.huawei.com (10.3.19.182) 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