Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3135966rwe; Mon, 29 Aug 2022 06:30:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR5q7/inKd9OAV0BJ4i4C4/EagQxHUpD4gKOp425mxpga7XpkBfEU1bqcwl/X6suALs/u13q X-Received: by 2002:a05:6a00:1ac7:b0:537:4186:c106 with SMTP id f7-20020a056a001ac700b005374186c106mr16535597pfv.76.1661779826060; Mon, 29 Aug 2022 06:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661779826; cv=none; d=google.com; s=arc-20160816; b=XpvSXxDOT9ZWQOOkoo1qk/D8kwjiS4C38oZ7cIh8QjkxLOnzz6hE6Vx4RZHr9QYrD1 Y/Eth/s6F7TKsDp/J8tcKrpKULkcTMN5R7EwyH07yskcfS1UsKX5SALstP1sWW7BFTR6 uy76W9IyqCWot096viNAHsPHZ2NunT8leH5Uoj/WkJkvUwhFlwVWhFk0t11tIdJt9Am4 7r70SKpoX9C2D/WmyDdzstqYoYnta7ycPqJmTezK1qhc95+6eDKWHWNZKYHuWexfE/ZG QNI3ReM+pCl0E6GnWo89FD7Vu4/5seYTsuj3cNrRhjuc9qs4VKbxe5ta1fP/QEqFAThP HrwA== 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=6J8xr6+S07v4FtSVfO5hSiIGi0aTEaTsuQpuD/1p/k0=; b=SQB7BdrvNXGh0UzpVdF5rKLfiUnXXcErOu5bRIULp9wBjvAbRzhGuZnCD/1sIdN7Dx /lD4T8OCcHZc82F9IeVVzhuqMr/kiBjjSJ7be7VGfyYfU5xtdHXRqAZgB7a+F1v7cy/B tfgz1p2T/gToTwN1U2//ofIGURGsMhTLGnAtT05fBp+bgPmj0OVl46u7Cr/xP/3hOVa/ mnTlSjBK+e2Lu+7fqsb5qO0VUM48ZB8+uVazFiDQ7pF6xRWGvt8y5KkM7gQC6SPjEqWx r1/xe+PxvnXqhqYwA2t1cIid6cnPM2rT+aneE8dxouPpYPNdDltvd2QM1PJZMK4O1JxJ 5HPQ== 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 d7-20020a17090abf8700b001fb4c9b9607si8808831pjs.114.2022.08.29.06.30.14; Mon, 29 Aug 2022 06:30:26 -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 S230188AbiH2M6T (ORCPT + 99 others); Mon, 29 Aug 2022 08:58:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229694AbiH2M4i (ORCPT ); Mon, 29 Aug 2022 08:56:38 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0033995A4 for ; Mon, 29 Aug 2022 05:48:38 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MGVYH2XLyznTrw; Mon, 29 Aug 2022 20:46:11 +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; Mon, 29 Aug 2022 20:48:35 +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; Mon, 29 Aug 2022 20:48:35 +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 v4 4/6] mm/zswap: replace zswap_init_{started/failed} with zswap_init_state Date: Mon, 29 Aug 2022 21:23:00 +0800 Message-ID: <20220829132302.3367054-5-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220829132302.3367054-1-liushixin2@huawei.com> References: <20220829132302.3367054-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 c22208df292a..155aee785a16 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; @@ -1515,6 +1514,7 @@ static int __init init_zswap(void) frontswap_register_ops(&zswap_frontswap_ops); if (zswap_debugfs_init()) pr_warn("debugfs initialization failed\n"); + zswap_init_state = ZSWAP_INIT_SUCCEED; return 0; fallback_fail: @@ -1526,7 +1526,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