From patchwork Sat Mar 25 07:14:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13187622 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 9195CC6FD1C for ; Sat, 25 Mar 2023 06:24:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0774C6B0075; Sat, 25 Mar 2023 02:24:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F3FC56B007E; Sat, 25 Mar 2023 02:24:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2CFB6B0087; Sat, 25 Mar 2023 02:24:30 -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 CFAEE6B0075 for ; Sat, 25 Mar 2023 02:24:30 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9E00D1A00E0 for ; Sat, 25 Mar 2023 06:24:30 +0000 (UTC) X-FDA: 80606431500.16.30EDBF1 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf15.hostedemail.com (Postfix) with ESMTP id E81D5A0007 for ; Sat, 25 Mar 2023 06:24:27 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.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=1679725468; a=rsa-sha256; cv=none; b=MaF5N5tyC9kBVrf/SCaiIxddkI0PjPiNn3fYXJjt08QpCgisc6vwD0uU3ZC/3jNDKvtiWb lakC1DiBrvj3ikAHJGG0k9JkZFOhcbxtCqUgxEQp5P9xQewXW5L4p8CpC8lD2kUmMWcTT8 y1vUQ2OVLsXUkNOhjDadc79bN+mUYjk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.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-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=URgX+Q5L1x4pDLOmz0xPXrHJ48HPro6M5y2A0Xr3JOQ=; b=A0ltD82MeNRppitY5ld5IyEC4fynf6ieG/BH0EU5dnt/NQL7bpXacdqyFGo8OpCvAGInD6 x6f+VmsSbOJC/BYzyRqGRDx/s67/X+WtIUfe+PBtuJDAUuwZ2n8u3mEpGmTU+JzE7FRIbH 2SRh5YfepJXqYfwRm9zpck6CSG3i/TY= Received: from dggpemm100009.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pk88j12lTzSncZ; Sat, 25 Mar 2023 14:20:53 +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:22 +0800 From: Liu Shixin To: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Nathan Chancellor , Christoph Hellwig CC: , , Liu Shixin Subject: [PATCH -next v7 1/4] mm/zswap: remove zswap_entry_cache_{create,destroy} helper function Date: Sat, 25 Mar 2023 15:14:17 +0800 Message-ID: <20230325071420.2246461-2-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-Rspam-User: X-Rspamd-Queue-Id: E81D5A0007 X-Rspamd-Server: rspam01 X-Stat-Signature: 3qgmyyj5dezwwiekrru4meo544ae9sdt X-HE-Tag: 1679725467-988162 X-HE-Meta: U2FsdGVkX19yWDADXyHBZSMo+LBHI6slGV24U6GMGqCe44LARyk7WfqXXii365jCARFTjMSBPqYtY+Q9F+5oJDbjXXeG/W2Uk7sI0ucxXr2djQCahFA05e7IWiZnIqwwOsuIht9F/2GanJvG/ypTsi1GpWiLOVcRAHYaHc8Q910JqzwmHUn18trN9pYKgM66p1aVDp+GPagNseq0l2PqiwGMRQDcRB24MT+ZI9DuYI8y8NszVzxfeLcuUAXk/63syv1EDxYzprTfK8H4BxVUQuUa1JqHYumfunXuX3NHqU4Euk1Yb3KwruUvXPyvDJTDF+MNQsjDxxDlB6VBFzjJyed9qefDsLb9f1seOboKu17KES2eRPnskfgDvLuSN3eVkxd0xkA4U41+Z2L0VE2gBqqh/ZD6qeD/6yx4/0RiQsG7dCojPrAu4I9pUhXqNNo8b8THWPor1f7KtbZSGewH/YoKWrsl3E723/igXVi7OxPnJgTdHK5QoKN9dLVdy27EJ71woPocaYjBD5rI72KMxyUCBaI9TFZ0D65z757ycTRrGGb1bRqyAhE+foQoqTXW/N39AuEZPTwKeLQQdlX4IBjTEf1yrtJxh6CrB9+eD9s2F07WtiRlQNXB4jDcxm1SBBbgQtB5hoB8d86ivjn0w6fSrJ+wtEX4L/MNN58cdUpLPlGsJYGpFz/mEZ08MMQirVwGbfdn3UGshPrp1Y8syPfYheaFhgrdfiSRdPYhAOFn730Pexz62kc8TzGrwgNaREhyhGWpX/7/Ep5SvPATxplaV6HA823fP21tl5OIYPWkBzPWYZdmyW3YD0MdQdnr8rzKhfw8OGZ4bviTVSSTdLSp5u71Llny9EC5b9n/a34eBVxPk+PPxFRNLItNzFyveX1KglD4BGKobTZUJT+oh+DY4Qc6vIWxNLMlg7x2mH33sLgziAG0Q56lJMH96CHrfHbyTZ/kc4UZtjNNMPb ym4hna3F ZeRmyJ7LfspK2HSI+WsivjHo+Byr2arIOeKiTRxjwL0QcIvm3cVKBsbU7jnzrYb4XyypHQWt3by5ln1pRbaIKXhq5Zr4PQcSGrq/wc4VC7frgi4cL+8RxP2zD2AD7+fVURrIYq/0uZ+HqzaNHbUyHvDjcKSUVocyj8vsWytd4ZGAefc0n27LzHeRbMJe3lm3KrzBhfRiRL6e1yw7bDpyRFykU/g== 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: Remove zswap_entry_cache_create and zswap_entry_cache_destroy and use kmem_cache_* function directly. Signed-off-by: Liu Shixin Reviewed-by: Christoph Hellwig --- mm/zswap.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 2f0ebd8bc620..6d2b879f091e 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -272,17 +272,6 @@ static void zswap_update_total_size(void) **********************************/ static struct kmem_cache *zswap_entry_cache; -static int __init zswap_entry_cache_create(void) -{ - zswap_entry_cache = KMEM_CACHE(zswap_entry, 0); - return zswap_entry_cache == NULL; -} - -static void __init zswap_entry_cache_destroy(void) -{ - kmem_cache_destroy(zswap_entry_cache); -} - static struct zswap_entry *zswap_entry_cache_alloc(gfp_t gfp) { struct zswap_entry *entry; @@ -1489,7 +1478,8 @@ static int __init init_zswap(void) zswap_init_started = true; - if (zswap_entry_cache_create()) { + zswap_entry_cache = KMEM_CACHE(zswap_entry, 0); + if (!zswap_entry_cache) { pr_err("entry cache creation failed\n"); goto cache_fail; } @@ -1538,7 +1528,7 @@ static int __init init_zswap(void) hp_fail: cpuhp_remove_state(CPUHP_MM_ZSWP_MEM_PREPARE); dstmem_fail: - zswap_entry_cache_destroy(); + 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; From patchwork Sat Mar 25 07:14:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13187625 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 AC3D2C6FD20 for ; Sat, 25 Mar 2023 06:24:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0276F6B0088; Sat, 25 Mar 2023 02:24:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF23E900002; Sat, 25 Mar 2023 02:24:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6AC56B008A; Sat, 25 Mar 2023 02:24:33 -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 C678E6B0088 for ; Sat, 25 Mar 2023 02:24:33 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9DE8E1A00E9 for ; Sat, 25 Mar 2023 06:24:33 +0000 (UTC) X-FDA: 80606431626.29.97D8963 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf30.hostedemail.com (Postfix) with ESMTP id E0FA280002 for ; Sat, 25 Mar 2023 06:24:30 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf30.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=1679725471; 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=OS250J6TXvkToKRxclBAM04Jr9676l/aHHCd5o+9dwY=; b=yEAUaK8piA6Y8mzW4kK5nkOg/TxUczW7J4AUn6aMmE4jzOubGRlS66VvgU/1zTx8WY01rq 1GlJFMCssR3wuqie1AhILfhP5rY+oCVbRyhcUHmR1xbV7KezoqEEYiKYp/fwppxYN4lQV2 GcnFWyVB7ECMuwmQruTVRYT7Mgji184= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf30.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=1679725471; a=rsa-sha256; cv=none; b=sYbLIqt8bQ6ahD7Xd2CGWKDX8FsMujy3qA1WO32gkHSoDFpQS75CpBq+I63r1cqbCT/n8s N8nG9MbPNKfD4H3CuyxdlJV8XKsGMqWZ9yAcENLSVf3BU3ZwMDKH4uPWNrYbIjaFbWdF6K eclor32aXCoFQGZM5ePUaIy+Y7J4bGw= Received: from dggpemm100009.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pk8941xq1znY0n; Sat, 25 Mar 2023 14:21:12 +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:22 +0800 From: Liu Shixin To: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Nathan Chancellor , Christoph Hellwig CC: , , Liu Shixin Subject: [PATCH -next v7 2/4] mm/zswap: skip invalid or unchanged parameter Date: Sat, 25 Mar 2023 15:14:18 +0800 Message-ID: <20230325071420.2246461-3-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-Server: rspam05 X-Rspamd-Queue-Id: E0FA280002 X-Stat-Signature: uhc1j1gzwp81dxxuhm5tn83zsu9draz4 X-Rspam-User: X-HE-Tag: 1679725470-627801 X-HE-Meta: U2FsdGVkX1+D0Ccv00ZODqrZVpR9HMSQRZDhfYFr8tTiijabc2Eaff6ifAT+YMnfb6CPdooPCbHP90u2t9xzKPs6VK+el0QBU9uUoKiI1h3oIdSSLrgvvoGjXg4z+RHAwDp0DQmRN2LfxdU4zU0zudI7D9ELQ6O/Zsd5vGKWMUIsZBuNFRo75HeiJ5R8cBRG1KOIj0X31EcjoQI/9XewvK2XTXxxIAJwJu6Ma/0bS5JyO1ICnmxVR6Zz55fX+LwEGN1Kk+kK7sV3osydP7atCzN7rs2sVD/pramKzd/F+svlDf7YF0QmXY1JB4B2HiH2JqIsjmQAFhZZCrpTC8+SjjwnNDEYGaNUZj1ednfD1O6Z866B5UgqQAcoBhMz5/WxnzFbK2wsM1sSK+202uqF3ulxOp8LVlZlrOY0xS3hyfU2H017iXC6CpLx7fEpMOdcgTxIe0fUN/5TQ5QV9vneVVjGnfKsBuEw4XW+HaCGWaHRWDrKxsMhYx+0/zvUO+DZN/AzwzJjv/UIC4k0AhcUxCn+s+N5DoRN2awTGw6eeXkhMgLVb/tG+sFLpFog/0bsSrwXyFA2Vw5A4lfRTRW2+aqxhR69ve3u3hsrV+PwiPkgWxLa06JH+YI2lmibAkhGdxmArfZVlkAFl0eUz8KVdoyctRwScXuZ5QW7EVylUrWBXVg+ugenFdy3hH57VuY8PfAIidHF28B7dIbPzoq/CjOdo/7gemn7g5ZxlMKGdWiSQCqoxsrTI1Xx68KG3yQ72fzSO+cLXTlNQt6ZsH1gskxWedfwIPFi65cxsy0t9rAblb9jeP+LCI3GX6vWKRP90nkVN8COnEvUjwqcF4t/doH/WndlgPKVXOPPzLFqQYD5b8LxP250oF5SCVomyR0Z14SJtzcMKVlNB97UuqdJQtmcrEXiwszxW/4ArGWru1Lte7A0eBPQOXwjrHl+7fYRH41vwujqXSUPtFy/dW1 6oEG6mw3 /y86J0RtivBHhkP02XUyyHKt7zvVyzGUCitifk28Eg2zS9AJ+ltVKQj1occXMRt47ws5hJKai/XFZSGuhnmx+Fb1TERCuJ6qnpW0JAe3+J35a4O0dbvjCIKqNB7FYgSUg7Vkv2aejWP4tvfgdf+a9Phxbb01RN2d5V822 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: If parameter is invalid or no change required, return directly. This can reduces unnecessary printing. Signed-off-by: Liu Shixin --- mm/zswap.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 6d2b879f091e..d2adc1ffe47d 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -761,15 +761,15 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, char *s = strstrip((char *)val); int ret; + /* no change required */ + if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) + return 0; + if (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. */ @@ -864,6 +864,15 @@ static int zswap_zpool_param_set(const char *val, static int zswap_enabled_param_set(const char *val, const struct kernel_param *kp) { + bool res; + + if (kstrtobool(val, &res)) + return -EINVAL; + + /* no change required */ + if (res == *(bool *)kp->arg) + return 0; + if (zswap_init_failed) { pr_err("can't enable, initialization failed\n"); return -ENODEV; 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; } From patchwork Sat Mar 25 07:14:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13187626 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 981AFC6FD1F for ; Sat, 25 Mar 2023 06:24:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC088900002; Sat, 25 Mar 2023 02:24:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD1276B008A; Sat, 25 Mar 2023 02:24:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94B9B900002; Sat, 25 Mar 2023 02:24:34 -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 775AA6B0089 for ; Sat, 25 Mar 2023 02:24:34 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 463571C0252 for ; Sat, 25 Mar 2023 06:24:34 +0000 (UTC) X-FDA: 80606431668.27.21BCE9D Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf08.hostedemail.com (Postfix) with ESMTP id 35CFE160009 for ; Sat, 25 Mar 2023 06:24:30 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.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=1679725472; 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=uZrLSQ+dlYXGdfXxFGzfu38Xy78bR4XTsSHXkxqHFuc=; b=UcDShG/fUbIgD3D4iD/C1V/c9nmLqmtSSIemL/JaWMZ27TDidgh/fy2SMKdXcMxqgN3q+R K09PfZ2yfXgQ1FJZWRQbgTcz8ahP/5KViapJbyJBhuk3lQuD6YZFBdHzNSTRVLBzbIdIfl nAGxI9OXRG978NtYsQ0ixv/8jXdMlc0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.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=1679725472; a=rsa-sha256; cv=none; b=tWcv3BEbU3ofKsrU9Og1FfKp6BqbtpkoMvkM+odXGlhZk4Rfd1h1blKkK4lihQlbHCHKWD 4WoKbsoGolFtXyeTZ3H2baqpInkeKpuJRXb+i602yHRL99P/GF8oh3UI0rfZwA5wPFzQ7i 5l+DMzZpoE5s6iN4/mo8fxqVp0igHGA= Received: from dggpemm100009.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pk8CX0DgNzrVx1; Sat, 25 Mar 2023 14:23:20 +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 4/4] mm/zswap: delay the initializaton of zswap Date: Sat, 25 Mar 2023 15:14:20 +0800 Message-ID: <20230325071420.2246461-5-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-Server: rspam05 X-Rspamd-Queue-Id: 35CFE160009 X-Stat-Signature: kubpgr8xk5x7w6ayzf5zp6yaszoxzsz4 X-Rspam-User: X-HE-Tag: 1679725470-673591 X-HE-Meta: U2FsdGVkX1+rk06BBbCbMy1yAR9K7Rc0UXs26weKmx1Bfg3i1HTiFLpMShELbVwyE/3fzcHqTOYYMDOF7LAU3x4Hqkpo8QDrVILmFclwcIwMUDReqB9iCeZIq84s8FY2Zg/4WNfLtv/rWwxwIVSqSt50eXkcDLIWpXyp7FT4AZrIGZlOR09vzjAcpFdsHIgDTWMzwNQXniaQEq7BOIT4zOgmr6xtoYqMMo2ZVVk8Wv4M5R9jWSCuLJ2f55l9j2bfvmTqibFqXpX72N77mLxzxLvQRDFEZuT2/2e+PfMC2Y6h9kgwaLionMm71Y6kLMpg1tCpH37B/xTn+qCMruo7qCUvMQyi26QW63yGnjhCMl6eujg4u/7KxYHLi//farcWQrxxVEwp1oqYIjSJqcMJJMwqcrdQHLdliHjLzUONglk98/7BxLDoOinNTBA0mCnwNGBoQXQtNNX0Tt4DD4/3UskHBDouSTr0SnX6CD7hHb6j5/Xrm84Cyw+EN0jWYoy3uyt1IAArVF1l3AEyQ6Ug+MjrzdUh9d47DBcML0xfQIwYNfG62645CiuEnxygSh54yHjGkbLrG2JsYGLw6t9r8iY3ufR43qc/q1pI3y9F/f6qkTHF9baTCECCreD46yp8rhq59gssVZffohroRxb1dRfCAbstdkV7WkBJ/2+PR566u0MBQ71PyGxugD3tH0IjCOFXe7TvPi12t/oF5fV1RYv42PnM7DqQmJ4I31un4t02OWxAIlgGIYv/wJIXbAJj5dSi0nCrDpafYuh9Pmk/1fyFfwm3sYMC3N8aPMh4xg9d7lGHE5bP+wCejtXZTwcYE9MGaBOXl+vdxB1IrgXAYkMRdXnac3yHDq0WREB9xClLX2ezuyUKfDbFuBQphAmYr3pXsBQ/Lcm62dl/JiPooYxzrM20tKmrvjhD+dO6fUT+7VIChNspNf/WksIMV7BQmWvimiV3ZzWLg9EbZ4W 7tD/FFzO 0TcWgnbOfpBN6d8vzpscdCMtc/oYUMb+zRSALGXOdwARB/dbmH+p23ZPmOg5XCtn44vFj3cbkjKEoX0cese3DDz14Ouqlf7JZcIiTAfeqVnoGMZuFXJS4lDJeOAhSunlQ2j0/d4ZoczLg7Gt3UXjdloZzqmkYiR6UmWC9tCcfGztmAo3BJqjsWaQkNwWIF9S15vFo5F4PA/FxRXh9cD0auBYCWwY9RGssHYNV 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: Since some users may not use zswap, the zswap_pool is wasted. Save memory by delaying the initialization of zswap until enabled. Signed-off-by: Liu Shixin --- mm/zswap.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 9eda48c8b8dc..af98bd8d4b79 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -81,6 +81,8 @@ static bool zswap_pool_reached_full; #define ZSWAP_PARAM_UNSET "" +static int zswap_setup(void); + /* Enable/disable zswap */ static bool zswap_enabled = IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON); static int zswap_enabled_param_set(const char *, @@ -220,6 +222,9 @@ static atomic_t zswap_pools_count = ATOMIC_INIT(0); static int zswap_init_state; +/* used to ensure the integrity of initialization */ +static DEFINE_MUTEX(zswap_init_lock); + /* init completed, but couldn't create the initial pool */ static bool zswap_has_pool; @@ -652,7 +657,7 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor) return NULL; } -static __init struct zswap_pool *__zswap_pool_create_fallback(void) +static struct zswap_pool *__zswap_pool_create_fallback(void) { bool has_comp, has_zpool; @@ -765,16 +770,22 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) return 0; + mutex_lock(&zswap_init_lock); if (zswap_init_state == ZSWAP_INIT_FAILED) { pr_err("can't set param, initialization failed\n"); + mutex_unlock(&zswap_init_lock); return -ENODEV; } /* if this is load-time (pre-init) param setting, * don't create a pool; that's done during init. */ - if (zswap_init_state == ZSWAP_UNINIT) - return param_set_charp(s, kp); + if (zswap_init_state == ZSWAP_UNINIT) { + ret = param_set_charp(s, kp); + mutex_unlock(&zswap_init_lock); + return ret; + } + mutex_unlock(&zswap_init_lock); if (!type) { if (!zpool_has_pool(s)) { @@ -873,14 +884,23 @@ static int zswap_enabled_param_set(const char *val, if (res == *(bool *)kp->arg) return 0; + mutex_lock(&zswap_init_lock); + if (system_state == SYSTEM_RUNNING && zswap_setup()) { + mutex_unlock(&zswap_init_lock); + return -ENODEV; + } + if (zswap_init_state == ZSWAP_INIT_FAILED) { pr_err("can't enable, initialization failed\n"); + mutex_unlock(&zswap_init_lock); return -ENODEV; } if (!zswap_has_pool && (zswap_init_state == ZSWAP_INIT_SUCCEED)) { pr_err("can't enable, no pool configured\n"); + mutex_unlock(&zswap_init_lock); return -ENODEV; } + mutex_unlock(&zswap_init_lock); return param_set_bool(val, kp); } @@ -1440,7 +1460,7 @@ static const struct frontswap_ops zswap_frontswap_ops = { static struct dentry *zswap_debugfs_root; -static int __init zswap_debugfs_init(void) +static int zswap_debugfs_init(void) { if (!debugfs_initialized()) return -ENODEV; @@ -1471,7 +1491,7 @@ static int __init zswap_debugfs_init(void) return 0; } #else -static int __init zswap_debugfs_init(void) +static int zswap_debugfs_init(void) { return 0; } @@ -1480,11 +1500,14 @@ static int __init zswap_debugfs_init(void) /********************************* * module init and exit **********************************/ -static int __init init_zswap(void) +static int zswap_setup(void) { struct zswap_pool *pool; int ret; + if (zswap_init_state != ZSWAP_UNINIT) + return 0; + zswap_entry_cache = KMEM_CACHE(zswap_entry, 0); if (!zswap_entry_cache) { pr_err("entry cache creation failed\n"); @@ -1543,8 +1566,15 @@ static int __init init_zswap(void) zswap_enabled = false; return -ENOMEM; } + +static int __init zswap_init(void) +{ + if (!zswap_enabled) + return 0; + return zswap_setup(); +} /* must be late so crypto has time to come up */ -late_initcall(init_zswap); +late_initcall(zswap_init); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Seth Jennings ");