From patchwork Thu Aug 25 14:20:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 12954732 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 2EA09C28D13 for ; Thu, 25 Aug 2022 13:46:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D014F6B0073; Thu, 25 Aug 2022 09:46:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB08C940008; Thu, 25 Aug 2022 09:46:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9F3B6B0074; Thu, 25 Aug 2022 09:46:02 -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 99786940008 for ; Thu, 25 Aug 2022 09:46:02 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6AC7DC0556 for ; Thu, 25 Aug 2022 13:46:02 +0000 (UTC) X-FDA: 79838238564.14.03B1ED7 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf31.hostedemail.com (Postfix) with ESMTP id 83BB720002 for ; Thu, 25 Aug 2022 13:46:01 +0000 (UTC) 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 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 ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=none; spf=pass (imf31.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661435162; a=rsa-sha256; cv=none; b=WSI+PXMlLOF45Yk70riBIedrrl345WuzRFUZA7/7AD9ibdPo1R6c2x/tD8llLHDbnqPuzd w3DbW02Ds3yICtqDympAI67iQ09RGsRlFXVkKvtdK/1040e4Xl76J0O6IHq43s8y0k8dCt SnFBPgbsqzz0oCmCVN5n99Z+AKpitcg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661435162; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+HmHSV2NYV3DgK5b2IIHOduZfAPoEHHLMKXhxHU3EVA=; b=sZScSfwiOA/hjD0fGsxJuS6S3iYTJMPky5wMgzeyRvOoQ3jO/YWrJZV3clImDH2DUg8CQf AW3mRaWyODuGjJq5QCDazwU2v2wnhvZ9EE4djpwuXHQxGqrAb3xsshbbgY7aih8f599IjP 3tvovKXYe4K3fiF3UYItimS2LgBZ0K4= X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 83BB720002 X-Rspam-User: X-Stat-Signature: 1ig7aux36wze6gkww46k856efgmrk7rm Authentication-Results: imf31.hostedemail.com; dkim=none; spf=pass (imf31.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-HE-Tag: 1661435161-630491 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: 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; }