From patchwork Sat Mar 25 07:14:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13187623 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 4E4CFC6FD20 for ; Sat, 25 Mar 2023 06:24:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B83B6B007E; Sat, 25 Mar 2023 02:24:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 46949900003; Sat, 25 Mar 2023 02:24:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3303A6B0089; Sat, 25 Mar 2023 02:24:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 042256B0087 for ; Sat, 25 Mar 2023 02:24:31 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CFD7380109 for ; Sat, 25 Mar 2023 06:24:30 +0000 (UTC) X-FDA: 80606431500.12.7FC59FB Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf25.hostedemail.com (Postfix) with ESMTP id DAE2EA000E for ; Sat, 25 Mar 2023 06:24:27 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679725468; 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=U7CqCTNQHay2aKHt+sTOdDg19RKnNNYVYFzk04pG8XQ=; b=I4/lz49AsCzz/q7FTY85wUoahekoq3jXDY4j+CdIv95eBi0SSg0ENAmrBDQgBKEMxcsKne 8Cm6DwVa9l6PAQhuKmo+Yj4Cw748R7OQTgzl+Js31B523K90oVgi2DIGx2NRkS6pTb8eat 21tao5ayW1aVcqSvAIzo8IuVDnB0/yw= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679725468; a=rsa-sha256; cv=none; b=Le2RIq1PAXusHjDBp9g5zP7KAVZBQTyZ1DAMyb8TI/0zAMGuSl5YYhjDuFaFTgWIceoJQa LU28e5tYmhGTuMKZvvVFslW3m7BxcD6eH6igJBJqzdnNlJnWyWhOe6jt8Kl4pBkWWP8QDU fGIT8NtpFbKAgQG0weNb+i8Ga8kUgj4= Received: from dggpemm100009.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pk8CW3lQwzrVts; Sat, 25 Mar 2023 14:23:19 +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.21; Sat, 25 Mar 2023 14:24:23 +0800 From: Liu Shixin To: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Nathan Chancellor , Christoph Hellwig CC: , , Liu Shixin Subject: [PATCH -next v7 3/4] mm/zswap: replace zswap_init_{started/failed} with zswap_init_state Date: Sat, 25 Mar 2023 15:14:19 +0800 Message-ID: <20230325071420.2246461-4-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230325071420.2246461-1-liushixin2@huawei.com> References: <20230325071420.2246461-1-liushixin2@huawei.com> MIME-Version: 1.0 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-Rspamd-Queue-Id: DAE2EA000E X-Stat-Signature: 6iab6nwn57xnrcszx6c38tb16wgioy5f X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1679725467-304530 X-HE-Meta: U2FsdGVkX19grZhdhAnj0pR1eFSSovFJEEnU8ww56GF9gqhB5gwydiGwEkLvMGCCbnHubus/8efjbAwXp8fMwPpF0ycuFns2Hi6RUhh+3KIa5ctuUzNQd69lT53dgiw7Ie1NsJRMKn1acgTaTz8Wxvd7+Rs1vj018udtUCkBBfnUknFANV4s1C1kZNKDHZSv7L/Ivk1wtBIhjLB++w0YcuryOnmRSXObhWygJgfUz5iDzwoAz5U3nNcQLLqK4Ckb7Lf7V9w3GlPlcjDAsk2UQC4KUgPcLdTx6lxs//sdohA7ov5aQ8xp0KhVmgjMLILdxMK/SoielzQ3VdPmCZwQocGG6Mus4U/H2FNpfQ3uyJQBDkkUD9aEnyZ11Stg+t4deB7F6Xna9Et0YGumKFWYPrixZotX4L9l289rMe0MdEg+CJBNd9R7v/95WWcngGRo+AEw7opwGhC9vsQzTqsYTQyV2ZjzK51JlgC7GxLlzsi7J965r5S73wAPabKstxrvWqZqKmHTipWsTOwKIBlNGFUx+FUteAogdLV1d+KYTigZEt9l5R/0N2OG2nMXqQMb6ENvfz7butBc4ma8WYUCmO9xAR164LQlzCgJxsXZjHRu6gGMiBp8hod2QSKS+kR9bfGdaXqToDfG1K+IMYre8exaXcT64eBDFQ+JybuAD38AQWrU2WBhDD4hJ/sg/FRoaRoDQ57y2U9+otIMnOqJNe5FzvSIWZV80DrVh77ZvlKO9Zw1U8jkMN92+hVt8qkyJ5uXKaAEMfe1Jla7DZBCI4Y9jB/iOhn6byFmmVoq8N7kWpdnsZL92vX80wJUONzIJVITUh8m92agFF+VmlVrwIL+OuSdCqzcyeg2AYmK+2jdswFvYto4oj0AAIiZ+0K2C/XnPiObYGu8FEH/yyeRfPoC2fK+J6R+MJGEq1AuQPsT3rIbpnR3WWUzK4YifQVvycI68NISw/Fw+SbdXOc iwtHTf1j H3y8P/W+JEiwj/otZPX3wY9Qm9RXmWuF5a6Kc3PhFy9THpBRBGdvUkuPVhG9lN5+tx2RJ0jnVCb1+E/tQDoAccNpjc8HcNBy6T5Q0MbIdrfVd20KDa48NAEaNYTvuUxFLn+V/SmBolEwDJqxil8i+fyyfK1jdl3vEOmGJK9WU3/LdbQG37evHBH69HvZZ08EumZGoZ4+phYxv7Za9cgJOarD00A== 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 --- mm/zswap.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index d2adc1ffe47d..9eda48c8b8dc 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -214,11 +214,11 @@ 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 0x0 +#define ZSWAP_INIT_SUCCEED 0x1 +#define ZSWAP_INIT_FAILED 0x2 -/* fatal error during init */ -static bool zswap_init_failed; +static int zswap_init_state; /* init completed, but couldn't create the initial pool */ static bool zswap_has_pool; @@ -765,7 +765,7 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) return 0; - if (zswap_init_failed) { + if (zswap_init_state == ZSWAP_INIT_FAILED) { pr_err("can't set param, initialization failed\n"); return -ENODEV; } @@ -773,7 +773,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) { @@ -873,11 +873,11 @@ static int zswap_enabled_param_set(const char *val, if (res == *(bool *)kp->arg) return 0; - 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; } @@ -1485,8 +1485,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"); @@ -1527,6 +1525,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: @@ -1540,7 +1539,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; }