From patchwork Tue Apr 11 09:36:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13207216 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 BE93EC7619A for ; Tue, 11 Apr 2023 08:46:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44C196B0114; Tue, 11 Apr 2023 04:46:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FB446B0116; 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 201EF28005E; Tue, 11 Apr 2023 04:46:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EF99C28005D for ; Tue, 11 Apr 2023 04:46:38 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B3B2B120B14 for ; Tue, 11 Apr 2023 08:46:38 +0000 (UTC) X-FDA: 80668479276.25.DCF106E Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf21.hostedemail.com (Postfix) with ESMTP id 3E55F1C0002 for ; Tue, 11 Apr 2023 08:46:35 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 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=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=DZ/SUniV1JtRkr7SINojZDbyN4/r+Vf3/yK5HT+Jekw=; b=1Kj+yFx2zr3Tp5uKSF/uRbC20N56l1saULZmqmtktBsBI7xMSzrJJJWrsiwRYc/4dVfw7l Sa91vo3O7ZIuu8vbQvS3aDWKn9vNgf7oN0e7+7Vw4moL/IJiNQLTU2+EAMCS2MmCckN0ol udurTiwJQ0MLODofeQFOZhUSvPVRhFc= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681202796; a=rsa-sha256; cv=none; b=5mQFDeYkeh2J/nMT8IPXbq6xLG4p0CrfRPs5whxKBlUprQdEukHTqxLqWTkgQkatlyjyFa Mjx89YgdaUpJGZ95VWsaczD9n3No9GibvCk/7TJrs14x4CctZO7ONDWYxl7ZpbIcqWVLwv aYKguFWjN5mJXWjX6EfnMCvLdsBSNq8= Received: from dggpemm100009.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PwfWx0VJRzKxn9; Tue, 11 Apr 2023 16:43:57 +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:30 +0800 From: Liu Shixin To: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Nathan Chancellor , Christoph Hellwig CC: , , Liu Shixin Subject: [PATCH -next v9 1/3] mm/zswap: remove zswap_entry_cache_{create,destroy} helper function Date: Tue, 11 Apr 2023 17:36:30 +0800 Message-ID: <20230411093632.822290-2-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-Server: rspam04 X-Rspamd-Queue-Id: 3E55F1C0002 X-Stat-Signature: 9j3eofi1yystrg9qfm4dcqidszce91c9 X-HE-Tag: 1681202795-768284 X-HE-Meta: U2FsdGVkX19fnwY11VF5qcmSVMmEb6uK88hPxvx9UhsTIXOsqhmixlywEenQvbKV0J41/8+o4Jabw65VkfuUCMmgmZWmva7Iv1QYZVQjVbAdU9e993GO8aJol1gSZdhhBci8pGlEfRly0toFenkmpgnb/gdMVLH5S6E8t+IYykM3L84DLt+zG6DD9daQShwoCZLBOXp5wMAlvEusHzUHFMzUpoCxu0z2e4Q9Ax+YRtLfvjhwvTj6B4HYOFpJN9n5JzlWtVgFa5StbBEz/PiUVyzKyTj9HYE0Xi7pj7Dv5WFa1uQBztJoAk/iR2rY1rTstTbYaMJzOU7BmCSB7eIDxnuf8Md40+JpB7EQnoNAbsWT8OFXRnvbfldtqNQ3gdx9qBF9bkY97VnVTPvs6xjtFCHB+/eAI92iVIwOfEzisrmI/KI4Xyi0APVDjYCWoL3tW2uV/LDIEDJTTiNp8m7HAWWPA+IhsAanB3LdjL0ZFivtmI6wTlFM2cJfPNWtRcgfGZST21aE20hOV4ePk+UkdcyE6mKe6OKXqW+l3/79YlVjh+uOXqTe+9NqmOdaPOiHtyUD8VeU5UBvqVjgRSVAFq3gFM+OQRBnafPCKk/o44OFJallogUdrmgZhCBdp/C3a2V2ilQuTrj/33ro1LbkKjs6KUZajTd00E3P7u8xUZnFkaeZMqd0HsvYEcLE9gYVkoakAmEFcyOD+TMHz07TXt9IVRClIX2JMt3RCuCpsHjZIjf+7SWDLfWg3wtFmH/utC+fIT7B/cE0a6EFfhGmu2LJbZsojjsTSx7w/y7rqTfAzEZmbMDrdomUrFvdfSJwU5Ssi8Es8P3WAfFLpGjUhTPxMind1nwuwJRlC7/VdEwYOtIwGpxU6wlm9ZAgx17kkDwADRa2zx9xqgN9ZYdSIBQIxywkvFSyxrid1uqZ10cRH6bbBEjjS8ajpahc6AMwaPn4qN3eDB+gUzxf+LP nbBIZo1R iJAtZmYliF2f+jwTffy56TZBJWAgmumwtuCr5Yt6vm5mi3A/5M910p21xbtyXiQx/FkmGTp80oAYV2ZD9m16QjgQnydv1e0qm4spegXZlNmkyW/aQGTng6Wi9W+WVO2zcCvaMM7H0exTRKxC+LIGFsB4l8DOfKVdz0sGDCsyYISrYy+/IPBc3O+yarD5YbIciYDFWjuMdgf/Qnb9f3zQ772P7ig== 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 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; } From patchwork Tue Apr 11 09:36:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13207215 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 8EA9CC77B72 for ; Tue, 11 Apr 2023 08:46:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 006376B0115; Tue, 11 Apr 2023 04:46:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F07066B0114; Tue, 11 Apr 2023 04:46:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBEFC6B0116; Tue, 11 Apr 2023 04:46:38 -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 CD85A6B0114 for ; Tue, 11 Apr 2023 04:46:38 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9B268A0A84 for ; Tue, 11 Apr 2023 08:46:38 +0000 (UTC) X-FDA: 80668479276.26.11E6BBD Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf06.hostedemail.com (Postfix) with ESMTP id 17B83180009 for ; Tue, 11 Apr 2023 08:46:34 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.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=1681202795; a=rsa-sha256; cv=none; b=t/vuY7rjBhwkL/e7p4s/bGqFzpQgWzXPuy9P+v3CfWjUtIBF24q8ipH3imPXE9FWAET0L8 CQTzHP9huqORJlNsmZtNl9vBPPq2d8YYzhGZHMgpNAfj5lOrtkTnyBGmQQuUa7VwAl1/mG 0kIzc/wYsMMUqnJS1aD0Ysd9Kso12Vw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.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=1681202795; 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=Eohi5X/qwmbm1UVCekfJ1YLnYtTqNIOSNTla4RtlBGQ=; b=WO/K/n4U5Q4CfY5gbVNKQgsRMz04QzCcrm9THciUB8cHtN/Mv/z/FB/Ztp3Zg0ZvzONywn RwJvGm+Rf7i2PvT1waTMqUyYoWA7YaTlXbDieQvDP4AJWIl8gp6JhEBbDsO7zZAOAorPN8 L2a0mvTjQYA9ub1DR/FVJf0XAZkUp9s= Received: from dggpemm100009.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PwfYL17MqznVXb; Tue, 11 Apr 2023 16:45:10 +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 3/3] mm/zswap: delay the initialization of zswap Date: Tue, 11 Apr 2023 17:36:32 +0800 Message-ID: <20230411093632.822290-4-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: 17B83180009 X-Rspamd-Server: rspam01 X-Stat-Signature: 15wzomimsrr7f8ebw4k6ia8w1qn45a6f X-HE-Tag: 1681202794-220183 X-HE-Meta: U2FsdGVkX19IEtJWjdx5UGJQrkw03CcQAhtwfDJuGTz29yDvtOsdm6Hd8RRwKxb24ylux3DtaPilLivUex0oYuzHCk/AvHBuTg/N/IXjUNIi3ELSuoFkrhcH77rhxBqfycsDKAZj47pzcnUlZJbaM6cncJhePUz/p+kx9tqmM04QmLnttNzfkymV7tmwll+fkqsIksICxeNsOavzobAhrH5ehDQisyYRZtc8QEBbGqzsK5C3Zm3vkTFK8AkU0g33fTfM/7IGMltSpzyT9iZkEpmv8yKmnUGtfgadjGvlekw+rfSphcMvRP9t+7fBTPYJglHrga1q0EynXIInAptRgArDQruKkHN7K0mjzWGGlQuyRiv9fxRm7UpQ2Pq2doHCY7+26CzSLJEo5I3puvt9V1dQZvyRh2Nm1B8AcVOIXA57z29VBk6zDw9Px60p79LdqdrZcUHwt8CXTIFA4MN2WlOfEdCnAxoQzOlZfmpp1wry0+TS0Z5KAWVtdHxgbq/4kFkJI6G20ynIyGNRwjCw/CGoItal/EgthRuFtKEqnjVb/U8UnP5AV2aBSMp1nRziarprX4ATZcFw9XFjOScD5JoUoztPKOv0JAKWtdio5nP2XyxoRok4aAedfZl1AjJ2CkUBUpE/bfq9J4IfXLSooyDTJKm42MCapjCA7H226P5s2R8T+DncmsIsN090BFYUcRngncOCut7YKqkUzkW9Y4mq2YOH0ZSA3Wa2ikhjpgRCW0A+BBiMR7h5Cjzap+hq/y6NCHvNhFIzh7cjNN3wSgp2Jef+F+Ri73r151HoU6ZceJdpG75XWyTwKAIlxsDgDw8hFb5rCyFiCv+YQIWo0wvw/88PSvjVnbVnSXfxqoUC9WY3LxiSA0NaEgmQdX8LjUXNM+ljPP5sGSVIzStgsceSf8vgW99l8/AGmxnZe+xK0cSbWP0u+sm5YNCZ+EFv8wAER7haEx4Hh+dj6Jf KUQmtYW1 dzhOebLRbuQKktQ9Z7AQ8p30oqMo5VYQ2KgUv5nsBZZblEp63+R0ZnYgC8wtm/AtwOkBFT2dPSBJnsn47z8v8q4B2cseOmibiBXzg3rweOQ6KtZmTQ+NC+TNgiaQ3tbgAixMXaSSl1VzEkbjYlBzUItFvZx/gxClOeUjHQ4M4dN4rs5rEkY3vdDMQSuYvjb2PzFTBD9kHaHqlkxTQTSbT5zDfgXJYoqgqm9mo 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 Reviewed-by: Christoph Hellwig --- mm/zswap.c | 71 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 9169c2baee87..af97e8f9d678 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 *, @@ -222,6 +224,9 @@ enum zswap_init_type { static enum zswap_init_type 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; @@ -654,7 +659,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; @@ -755,29 +760,43 @@ static void zswap_pool_put(struct zswap_pool *pool) * param callbacks **********************************/ +static bool zswap_pool_changed(const char *s, const struct kernel_param *kp) +{ + /* no change required */ + if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) + return false; + return true; +} + /* val must be a null-terminated string */ static int __zswap_param_set(const char *val, const struct kernel_param *kp, char *type, char *compressor) { struct zswap_pool *pool, *put_pool = NULL; char *s = strstrip((char *)val); - int ret; + int ret = 0; + bool new_pool = false; + mutex_lock(&zswap_init_lock); 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); + ret = param_set_charp(s, kp); + break; case ZSWAP_INIT_SUCCEED: - /* no change required */ - if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) - return 0; + new_pool = zswap_pool_changed(s, kp); break; case ZSWAP_INIT_FAILED: pr_err("can't set param, initialization failed\n"); - return -ENODEV; + ret = -ENODEV; } + mutex_unlock(&zswap_init_lock); + + /* no need to create a new pool, return directly */ + if (!new_pool) + return ret; if (!type) { if (!zpool_has_pool(s)) { @@ -867,19 +886,30 @@ static int zswap_zpool_param_set(const char *val, static int zswap_enabled_param_set(const char *val, const struct kernel_param *kp) { + int ret = -ENODEV; + + /* if this is load-time (pre-init) param setting, only set param. */ + if (system_state != SYSTEM_RUNNING) + return param_set_bool(val, kp); + + mutex_lock(&zswap_init_lock); switch (zswap_init_state) { case ZSWAP_UNINIT: - return param_set_bool(val, kp); + if (zswap_setup()) + break; + fallthrough; case ZSWAP_INIT_SUCCEED: - if (!zswap_has_pool) { + if (!zswap_has_pool) pr_err("can't enable, no pool configured\n"); - return -ENODEV; - } else - return param_set_bool(val, kp); + else + ret = param_set_bool(val, kp); + break; case ZSWAP_INIT_FAILED: pr_err("can't enable, initialization failed\n"); - return -ENODEV; } + mutex_unlock(&zswap_init_lock); + + return ret; } /********************************* @@ -1437,7 +1467,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; @@ -1468,7 +1498,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; } @@ -1477,7 +1507,7 @@ 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; @@ -1540,8 +1570,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 ");