Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp674969rwe; Thu, 25 Aug 2022 07:22:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR6NirPpmRF1aje4At8xFTckT03vSSWQaIokIAL9kzGpj1f/J26PrOLbNu5zNwfN0ED2B1Tg X-Received: by 2002:a17:906:1841:b0:73d:af70:7bfa with SMTP id w1-20020a170906184100b0073daf707bfamr2645299eje.49.1661437363254; Thu, 25 Aug 2022 07:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661437363; cv=none; d=google.com; s=arc-20160816; b=mas/+0C5A26/0rUIevtXDWbI5QUvO9MjZu4GSL+SbECtEv4a9Vz8N1USOY7MVlftYX 2NrXcX6g+u6MQ54YyJtydPK2YOI9XLoR5yuyZs+Vuz1Pi4NJFJ/ftaWbLZiWTbxSZLbq 8O051Ugp04z6QpNFrKzci9bTkVkNWkcQF8gKreZSR3pYoXJJbUWDqrhSGGcizHInBmQy YLU7B4JJoLMUNvWVgObjEe/35YFdQYX5VrXFH98huClaHG/EVtqXdPvQQxXPaYgODH0M swLNIow4wy2iDhZUMNCJPJ8leYOAn84OuXChySMdO5Qyv7OSuSmJ3CJkHdo+tli1IURY dXfA== 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=nHUgsbYVQciulnA2hG/gGNPYPEUnF0Fd4tDNduUb9JuFXIPnocnatNzuYybxXk5nTA At7AAs2MAw/7yMO5IseRHRx0ngDA1/fDyXa3WTpbQpPxak7AA1PUH7eNd9535XCfYtOk jDTiT6wMJWL5BmLHgf+Cf3O7l5oi9WPxam/cpobWHoiqS2VobgVRGsGm2WjWj7iFzv/V CCnhOyg0ZkjOxuMxs+md/tXUh4MS1bmJIByf//Y7jeuoNdwHqFBoSQEymNzvltc11m3z ZsEwTWnKt1NiKvpjMG/VepGp+3HTgow0jkRzPTsSarbAZBSEfkgedwJ/mSW4xzd1aRNo fK0w== 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 v18-20020a1709061dd200b0072f0a99a62bsi3475375ejh.143.2022.08.25.07.22.17; Thu, 25 Aug 2022 07:22:43 -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 S242646AbiHYNqM (ORCPT + 99 others); Thu, 25 Aug 2022 09:46:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240614AbiHYNqD (ORCPT ); Thu, 25 Aug 2022 09:46:03 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 263F02CDC6 for ; Thu, 25 Aug 2022 06:46:00 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MD40L2lhxzlWTx; Thu, 25 Aug 2022 21:42:42 +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, 25 Aug 2022 21:45:58 +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, 25 Aug 2022 21:45:57 +0800 From: Liu Shixin To: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton CC: , , Liu Shixin Subject: [PATCH -next 1/3] mm/zswap: replace zswap_init_{started/failed} with zswap_init_state Date: Thu, 25 Aug 2022 22:20:35 +0800 Message-ID: <20220825142037.3214152-2-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220825142037.3214152-1-liushixin2@huawei.com> References: <20220825142037.3214152-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: dggems703-chm.china.huawei.com (10.3.19.180) 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