From patchwork Tue Apr 11 09:36:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13207217 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 4ABA7C76196 for ; Tue, 11 Apr 2023 08:46:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E104C28005E; Tue, 11 Apr 2023 04:46:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBFD928005D; Tue, 11 Apr 2023 04:46:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C89B828005E; Tue, 11 Apr 2023 04:46:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B456528005D for ; Tue, 11 Apr 2023 04:46:39 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 71E091404FD for ; Tue, 11 Apr 2023 08:46:39 +0000 (UTC) X-FDA: 80668479318.17.0810576 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf27.hostedemail.com (Postfix) with ESMTP id EDFD54000B for ; Tue, 11 Apr 2023 08:46:35 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 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=1681202796; a=rsa-sha256; cv=none; b=TBfjhpAdPlVCvFBnzfVdwVbHjvVLj4YlKsa4lgynUG/wWrrXzxbHBZJWw3JeTZ3DpQWsMT Jq8wJpl7GKgf4/FIPqtSDDFCEaQxPA854RQ55Pcbb6fgY9SR3FMQWWQdtL33cY3I/byics kYF0ui1uNePZ5FaPFQosIiOXU2GU4iE= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681202796; 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=dW5QsfZgibgEa4mVBRGuZ+Qy3jcmV0OGK++hz0f04Qw=; b=wnLSiGbl4ncmidd8i2k6n5ApNMt9MFvbRrjm5AhME1yCBGjZya+4DKrBf6WwwaNO7skBJp C751jJ1s8QQh5cELJnpY7dHfNkRddaQBqc+gO9ccCKY8/DNlcDk35nFveTLUmCQL6Hza3O vfz7iPxpoBZ90ibD31mYyVKsEujX+FE= Received: from dggpemm100009.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PwfYK4hhLznVXT; Tue, 11 Apr 2023 16:45:09 +0800 (CST) 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.2507.23; Tue, 11 Apr 2023 16:46:31 +0800 From: Liu Shixin To: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Nathan Chancellor , Christoph Hellwig CC: , , Liu Shixin Subject: [PATCH -next v9 2/3] mm/zswap: replace zswap_init_{started/failed} with zswap_init_state Date: Tue, 11 Apr 2023 17:36:31 +0800 Message-ID: <20230411093632.822290-3-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411093632.822290-1-liushixin2@huawei.com> References: <20230411093632.822290-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Queue-Id: EDFD54000B X-Rspamd-Server: rspam01 X-Stat-Signature: 1ir8c4qpn7auuywopr4oakzbkomifysj X-HE-Tag: 1681202795-161822 X-HE-Meta: U2FsdGVkX1+OcaczEEojXLOiPolUf4MmFsPLe68+gOviUytUrcLQkrxcsvrDHRQb3Fg8L0H1logEZH+38Rgd+WMf726up7RZWYFL7xIzZmUfZ0CPuPv3CIiwcKCCgnVjaJ6SOXtaX2LHnq0C4aRxJNWKuNRGpSoelwtzt2csL847Aas/fT6sQE2/yg8maZqnQqXKth/yvpbWGIumqIcD1ygqOCyFOZgE7LDWe7z2vfytFbUpAWQutMI5jKqkfRLI2Xa87/8Doubr0mc7GJ6570FD16yMbpl6AeXwc5fcmMq+XEZWQgOBAMEmM5gJMgTCkH9Ql2OIEaNSsAZUv1oRy92bRkg25lrY2KLRLcVhDlkHhyXeQaeJJACfwlpRXxExhqjDf6fTLGr9tpId1paTo5ggGs8SBxRqMW03+p9G+fr6n6/MPqLMQmQJ/eiiNiHdvxvtVyl7aaRaumk1eP6yMzo3VUkdzgL3q03z0ANdKb2Zmzu3A8kFuc2reMt7etVRuzky5IVdpC2llLS6HY2k29tmzMwzwsMMlwKMPRqVoJZJ4iPB7VB95M2bX+J3y2bc8GNJXz9qXq0pETb51yESO/1wjfLtULymh90kJlftILUfTcEMTN4ajOrjgfZcex0ALIEdNiNalnCvnpDV1OtJkXl8FC6DEsNuTkSyalNDuWyTmDbzTipKE1q8OhcVu6EFAHUFa8+f9YNwsAwjZWFUQhUZ7T1MzwxgV2o0TSL+0YKGGwzHhj307rVurPI7CSHmUdaYtbsbHdVAb+uOWLzaL5RUPFmwhsAuYLWzC331JDietlWiLbiUtTYHJi1TXdxxYMYnYK55gv2wFhbJ8/t+Cf5MOsknG7LCJHAHTuaP9GZn55X5pKixst8Z794ftsC7bxaccOTCCb8VjJxO4mkaMXrT20HyNtbAvIsF/RFXgBy78ksDxN2aRv0pYpTTOe+7ZVlbuc7uM5CAxVk6m4G Rl5BDm+0 tBI+/uLz3XJ3mK6xUItjXxrD4UD0dXbAdY3Wk9tXsv0cDCj7tuJbsb1Pl4sT5kh4HxZOHmrsnp8CQ0kCMHegm8GxTSmi00pSwHVx5az6msEFMqa0+wJ9CwPZfIDwAKB4zIvNk4YyhJ/7X+daOdx/N6JIMKZ+BkjOIF66TVp8GMwcoTs5qUYxOLsDqJJDCPwD0FwP+0dchteyjREuCizmtILUCIg== 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: The zswap_init_started variable name has a bit confusing. Actually, there are three state: uninitialized, initial failed and initial succeed. Add a new variable zswap_init_state to replace zswap_init_{started/failed}. Signed-off-by: Liu Shixin Reviewed-by: Christoph Hellwig --- mm/zswap.c | 55 +++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 6d2b879f091e..9169c2baee87 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -214,11 +214,13 @@ 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; +enum zswap_init_type { + ZSWAP_UNINIT, + ZSWAP_INIT_SUCCEED, + ZSWAP_INIT_FAILED +}; -/* fatal error during init */ -static bool zswap_init_failed; +static enum zswap_init_type zswap_init_state; /* init completed, but couldn't create the initial pool */ static bool zswap_has_pool; @@ -761,21 +763,22 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, char *s = strstrip((char *)val); int ret; - if (zswap_init_failed) { + switch (zswap_init_state) { + case ZSWAP_UNINIT: + /* if this is load-time (pre-init) param setting, + * don't create a pool; that's done during init. + */ + return param_set_charp(s, kp); + case ZSWAP_INIT_SUCCEED: + /* no change required */ + if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) + return 0; + break; + case ZSWAP_INIT_FAILED: pr_err("can't set param, initialization failed\n"); return -ENODEV; } - /* no change required */ - if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) - return 0; - - /* if this is load-time (pre-init) param setting, - * don't create a pool; that's done during init. - */ - if (!zswap_init_started) - return param_set_charp(s, kp); - if (!type) { if (!zpool_has_pool(s)) { pr_err("zpool %s not available\n", s); @@ -864,16 +867,19 @@ 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) { + switch (zswap_init_state) { + case ZSWAP_UNINIT: + return param_set_bool(val, kp); + case ZSWAP_INIT_SUCCEED: + if (!zswap_has_pool) { + pr_err("can't enable, no pool configured\n"); + return -ENODEV; + } else + return param_set_bool(val, kp); + case ZSWAP_INIT_FAILED: pr_err("can't enable, initialization failed\n"); return -ENODEV; } - if (!zswap_has_pool && zswap_init_started) { - pr_err("can't enable, no pool configured\n"); - return -ENODEV; - } - - return param_set_bool(val, kp); } /********************************* @@ -1476,8 +1482,6 @@ static int __init init_zswap(void) struct zswap_pool *pool; int ret; - zswap_init_started = true; - zswap_entry_cache = KMEM_CACHE(zswap_entry, 0); if (!zswap_entry_cache) { pr_err("entry cache creation failed\n"); @@ -1518,6 +1522,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: @@ -1531,7 +1536,7 @@ static int __init init_zswap(void) kmem_cache_destroy(zswap_entry_cache); 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; }