From patchwork Tue Feb 20 06:53:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13563471 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 5FFBEC48BC4 for ; Tue, 20 Feb 2024 06:53:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 006AC6B0082; Tue, 20 Feb 2024 01:53:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EF9BF6B0087; Tue, 20 Feb 2024 01:53:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D99096B008C; Tue, 20 Feb 2024 01:53:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id ABD466B0082 for ; Tue, 20 Feb 2024 01:53:18 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7F8EDA059B for ; Tue, 20 Feb 2024 06:53:18 +0000 (UTC) X-FDA: 81811265676.19.CBBD706 Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) by imf06.hostedemail.com (Postfix) with ESMTP id 9073F180005 for ; Tue, 20 Feb 2024 06:53:16 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf06.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.171 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708411996; 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=rSrN0VU08UnJ1XHlLciRWceHdRFe+MkVOKHbF6z/wOI=; b=6vAM7Wk+CedHU0ZCHMU3U3qGnVnUDNjUkLJ9x+tPP17YpxNRHljHFeLkAhaZRyS7/OlNOP 4duhz7KZ3/Rkv3OtFuFI+xVY/MZOFTSnTI+HOoqFSwfZ5oHz/Jrai33otudrTxFkDN2HaO tte3RxJgFs6VjLIgEdyxN283uWvtRgg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf06.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.171 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708411996; a=rsa-sha256; cv=none; b=bAREf/l5uXGa7uGzHQouVFoYk/lh7/dQeUVLt25q2vP9u0fy0LnzBdjR0pu3246Eu8BpWU 7aji4Ek7lnywKWQBQPcySjcI269cGV4xaM0ZPsouhblrBPnfz90BipUkvEMJGNft5AbHn7 I8h6P7GHx/F3x+bhFKr2DuTFcBLiv84= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Tue, 20 Feb 2024 06:53:00 +0000 Subject: [PATCH 1/3] mm/zsmalloc: remove set_zspage_mapping() MIME-Version: 1.0 Message-Id: <20240220-b4-zsmalloc-cleanup-v1-1-5c5ee4ccdd87@bytedance.com> References: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> In-Reply-To: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> To: nphamcs@gmail.com, Andrew Morton , Sergey Senozhatsky , hannes@cmpxchg.org, yosryahmed@google.com, Minchan Kim Cc: Chengming Zhou , linux-kernel@vger.kernel.org, linux-mm@kvack.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1708411986; l=2317; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=cqkPrPVAWUs+Ao8dP81X35doam5/5XwHmrqtbfkzja8=; b=b6RxioH3nI4BzApNzDWLkeJUM2KNNI2jIWfPF0wnvNdHFanI0ZxZ8jRdFwHgIq3V0GN2CzKie q3prV92J9KxB5aPLZFDeZyXd2Qc3kEs2h5qb8Cu+K3t4Kjat+DJ1Zyp X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9073F180005 X-Stat-Signature: 1jjqip88hxxahcxbtug57squphco16e4 X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspam: Yes X-HE-Tag: 1708411996-834268 X-HE-Meta: U2FsdGVkX1+ezPyknZYjUK9mvn5rfIho9XQJKZivJasn53XT6/EHtROMkIPxwPq5fIYly7If777mo3DxVwh8n0pk690WEy3jZ/tHkZ7CtPycT8yysAhbN3+MQ8n2PoRTeNm1EFZfU3AIVvpst4YjIJSm8v+Sru6bicNoSuL03Nqh3rqV0VR2oOJLbME1yJV58hLG0Xc/ggtoQboUPSPnOJaOiMf3DOj1O1KLgCFhrEtRBWf+HJVUv+5qb0vkmJAzYwhAgXcgQOsWngiFD3pnEZ+k5Aks9YXffz0veb5qhq4TbQSF+18VMv66ZIhJXy5hbAPlc3jNi107Y1qvDi83rqlbUOV5xWrXYSeORFs2fq7RFxC8GGNeKWjwocrSBNae+nfdiouQ7DtZVJrTygfXS79LTiQJEuszR89SZuq53L2boMuu7rTNYRFPloDr2baa83nAgt6FdQvhfdqzZuZjKnGMJ+DVa053pGniCmsHtXXMzlpmwaj6lOFh1BhvH8PJO/8V9D/fm1J0C7ezdaKP3RcS5lE/yt77FF3trkcLTKaDVZHZLwOctcumguPBGBQSCoqLhZZ3C0C3BBkUuUuM15527lqqBCUA4f/q6b3C8tfGaO+Fimz9+AVGX42G87txI9rjWc5veKe+C77BW4uL5p73XNPYZKHSJoCY+0GPIVfkgBK+ndV8BoxgbrNfzI6YsyfdZgf+sjuTJe+blrDCiHaAgD0VwURFoNzpWqQkRe9mh99iDKyP0Q1IdCyItbqSiSu5W7Zaln3B6Ys4I/s4hPgbI4AcXT7gqLIJ7Nix8HXZ7ARe2NRToEpHRfyKpKmESepF6vca22W+QZSDiy0yQSTYLJW6i4sKS3X1B9b8kalmLGp0VTZpF29+EldD+p6fm4BQVQgXSkg0wPM31AtT6WmQeqb4lnlhbSRspjWjBVLRJV3h56OZcQEMTOwFBq4JY2MvdRz8c7BukoxYLqu vq9n4Gfm Nw2Tm2vSreuJAorxBYIg1Y5IcMFJE+am2M5piJPVbSP26oKFun8eXh22FWA== 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: List-Subscribe: List-Unsubscribe: We only need to update zspage->fullness when insert_zspage(), since zspage->class is never changed after allocated. Signed-off-by: Chengming Zhou --- mm/zsmalloc.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index a48f4651d143..a6653915bf17 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -486,14 +486,6 @@ static struct size_class *zspage_class(struct zs_pool *pool, return pool->size_class[zspage->class]; } -static void set_zspage_mapping(struct zspage *zspage, - unsigned int class_idx, - int fullness) -{ - zspage->class = class_idx; - zspage->fullness = fullness; -} - /* * zsmalloc divides the pool into various size classes where each * class maintains a list of zspages where each zspage is divided @@ -688,6 +680,7 @@ static void insert_zspage(struct size_class *class, { class_stat_inc(class, fullness, 1); list_add(&zspage->list, &class->fullness_list[fullness]); + zspage->fullness = fullness; } /* @@ -725,7 +718,6 @@ static int fix_fullness_group(struct size_class *class, struct zspage *zspage) remove_zspage(class, zspage, currfg); insert_zspage(class, zspage, newfg); - set_zspage_mapping(zspage, class_idx, newfg); out: return newfg; } @@ -1005,6 +997,7 @@ static struct zspage *alloc_zspage(struct zs_pool *pool, create_page_chain(class, zspage, pages); init_zspage(class, zspage); zspage->pool = pool; + zspage->class = class->index; return zspage; } @@ -1397,7 +1390,6 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp) obj = obj_malloc(pool, zspage, handle); newfg = get_fullness_group(class, zspage); insert_zspage(class, zspage, newfg); - set_zspage_mapping(zspage, class->index, newfg); record_obj(handle, obj); atomic_long_add(class->pages_per_zspage, &pool->pages_allocated); class_stat_inc(class, ZS_OBJS_ALLOCATED, class->objs_per_zspage); @@ -1655,7 +1647,6 @@ static int putback_zspage(struct size_class *class, struct zspage *zspage) fullness = get_fullness_group(class, zspage); insert_zspage(class, zspage, fullness); - set_zspage_mapping(zspage, class->index, fullness); return fullness; } From patchwork Tue Feb 20 06:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13563472 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 C2FEDC48BC4 for ; Tue, 20 Feb 2024 06:53:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B071F6B0087; Tue, 20 Feb 2024 01:53:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A18496B008A; Tue, 20 Feb 2024 01:53:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81BC26B008C; Tue, 20 Feb 2024 01:53:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 735F36B0087 for ; Tue, 20 Feb 2024 01:53:19 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 46691160581 for ; Tue, 20 Feb 2024 06:53:19 +0000 (UTC) X-FDA: 81811265718.17.FAD7DB6 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by imf28.hostedemail.com (Postfix) with ESMTP id 69B24C0005 for ; Tue, 20 Feb 2024 06:53:17 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708411997; 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=Nb30dN0oMtkpv5BRdO1dSuW23c79nozgpyzxi6PFz2g=; b=cy5p0dfzZd3dslphx2/ZRjgQdMxDVAvbJRqFlhEvFJHChdfVnzEilgpl1Icc9amtTfAdSg T5X/s2Ae4NMgBqyV67C4JGjKkw/EQI8mWj3RUfQ3L23CsUrI6JwM3pJEGAbHjws/DhHcxo OAJF54+4ME2iNrQAgaNtHc/3kP1GpLE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708411997; a=rsa-sha256; cv=none; b=06q3KBzhbW/YxND1Str15NitldATDam59cFsnkarkh7iwcmy3fxovaTucODsDVMah0Hhy+ ZlspGrjiXI4fq3cMaAFJcMgcgbQmgKG57U++Pua8OehkYQ6PqGJRbUo5diWNwUhK6Ublpu E/26Nr78CwfJtH+3JuF7lsUa51tb3Mc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Tue, 20 Feb 2024 06:53:01 +0000 Subject: [PATCH 2/3] mm/zsmalloc: remove_zspage() don't need fullness parameter MIME-Version: 1.0 Message-Id: <20240220-b4-zsmalloc-cleanup-v1-2-5c5ee4ccdd87@bytedance.com> References: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> In-Reply-To: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> To: nphamcs@gmail.com, Andrew Morton , Sergey Senozhatsky , hannes@cmpxchg.org, yosryahmed@google.com, Minchan Kim Cc: Chengming Zhou , linux-kernel@vger.kernel.org, linux-mm@kvack.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1708411986; l=2152; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=GQWspwGCFRIlLWu+jB/4L2Vh7hNigRDA/nhdzUelvTs=; b=JNIzIQ9Lci0B3n2FEPHyXk1U9Zo0P03ME5cMyqjBhp3RwTxfdYX46ff3p2X/QxYJ6NhSNNcY7 4xNL7yvbvQYC/xjoY/qcI71XYnv5VeaKzisgJeRm5rlJnnYxTN/4tk/ X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspamd-Queue-Id: 69B24C0005 X-Rspamd-Server: rspam11 X-Stat-Signature: w7ukkx1iw4z1iugkfcdkwc4rdmoufibk X-Rspam: Yes X-HE-Tag: 1708411997-601421 X-HE-Meta: U2FsdGVkX1+g7kKJx1PmaEovL05ayELSRkHuXfygGg5n+INp1blk73PAo4gu1iBm/QCAnv9i6EIUJULu36GKvJ6foY/tnC4jSZFXT/pr+6Qr5NqdY0clp84umfqbich5JflfoHqnMOkO8KpV6h9UXGctF84STpIQLKY0zXQ1HYW1Co0K95j+T4hbCqE4z/lLjqwo8mTK+fda7ckqgHjxYt5CcL3IqF9GQ20KG/UDb7W/xeg8OgVQpC14nLwI18r2sfIkC83t7bM6bj6kHI25jeGMQRa5fdOBE9A37EoFpeHwJRRjbv41nQ5+ES4WNIPSbEA8PN+T2ypCQeOxeu14v/qJExobNXGIjJ7kZacUfRcAfoM9sa+ByPNkn7+DyaXdMSk4nU6Bbpa9nLHQfwjRBZSO7ZghRfTM1b7URQYBKcLvY6SvXl7v15UVJ+8RTWvJJdhjzeUXiRiXzqztVTWwdV4mvmSbG8JqtMFxiU5qHbX+SeajXF6xwpXJT+22UTexjNB0GPkUQNOkynixAjHUCdf8MziUEdCsSpyf7iM8OTyB00Fop5woIImdRGuXY6Sm9b/87J6IP1qd64mOu4e39EVet1dv9bcAGFC6mUJNmiCwkNb4me8qvB4qrejhwElXs6Q+iGO0O7Ap/mdI6e2A4Zt3GyWVbC9bXbZ5Dr2fj6AVHL2AFqTUoQh3I9gJUpv9ptSzGvXVaX3jlQemijvAroR5GvQ+/UtXnGvHwH73eZ11g2jiMS84eSFG0fAhjiR1B8Gv++YTolDvyJuDeIgjBmQOa5wd7FEELOfT9ppJNjQQk1BgU9kYqzKLL0Svx39Pn1f2oBiriTj97sJZKBHaVa+kYPU9TsMI0bP0/NB8klSbgbV9GBmHoCRfdnLBzN1YA1paAsOlcS1270utNJcCrntLblAbVbcnTALzRXhgTEeIhasc23LJWtSC0VMK6zVppU06Q4oP2IcpVP4/4Cv qbWKQOBb FqUinY7tPaYncxmPpDPll6Knm+0B6RGeidxuw3qxRH7mR6wTUIzhKgt7TN2BiGESalA7JvdwkYcWmGTopQDS42/QsAMnpTeZ4MqYeOf+Mk3NG0ukNdL5x3I4WG8jXXCBBIXLdNi1akIkcALgKNCdxxGOoO3mHMmz3sdg240LFL51d7KVSpmY3i1aEtdHB+3nWtl7mFwiKosFtSoTh4FS8tDcys+r2T0NWqA13vK/omdcte7J9WtRtciBZRmH3wwJGA6RGP0ej1CCG7g7YnqPM7hS++AOiRS6eaCy1HRHVYB02Alcx/juaprQ3UkCeIoWf1MvMGxyckAWeFlAqLRVXLZb8KxLIx8NQB6IoC0GSLNnowUk= 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: List-Subscribe: List-Unsubscribe: We must remove_zspage() from its current fullness list, then use insert_zspage() to update its fullness and insert to new fullness list. Obviously, remove_zspage() doesn't need the fullness parameter. Signed-off-by: Chengming Zhou --- mm/zsmalloc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index a6653915bf17..c39fac9361d7 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -687,10 +687,10 @@ static void insert_zspage(struct size_class *class, * This function removes the given zspage from the freelist identified * by . */ -static void remove_zspage(struct size_class *class, - struct zspage *zspage, - int fullness) +static void remove_zspage(struct size_class *class, struct zspage *zspage) { + int fullness = zspage->fullness; + VM_BUG_ON(list_empty(&class->fullness_list[fullness])); list_del_init(&zspage->list); @@ -716,7 +716,7 @@ static int fix_fullness_group(struct size_class *class, struct zspage *zspage) if (newfg == currfg) goto out; - remove_zspage(class, zspage, currfg); + remove_zspage(class, zspage); insert_zspage(class, zspage, newfg); out: return newfg; @@ -878,7 +878,7 @@ static void free_zspage(struct zs_pool *pool, struct size_class *class, return; } - remove_zspage(class, zspage, ZS_INUSE_RATIO_0); + remove_zspage(class, zspage); __free_zspage(pool, class, zspage); } @@ -1609,7 +1609,7 @@ static struct zspage *isolate_src_zspage(struct size_class *class) zspage = list_first_entry_or_null(&class->fullness_list[fg], struct zspage, list); if (zspage) { - remove_zspage(class, zspage, fg); + remove_zspage(class, zspage); return zspage; } } @@ -1626,7 +1626,7 @@ static struct zspage *isolate_dst_zspage(struct size_class *class) zspage = list_first_entry_or_null(&class->fullness_list[fg], struct zspage, list); if (zspage) { - remove_zspage(class, zspage, fg); + remove_zspage(class, zspage); return zspage; } } From patchwork Tue Feb 20 06:53:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13563473 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 ACF0EC48BC3 for ; Tue, 20 Feb 2024 06:53:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F8BF6B008C; Tue, 20 Feb 2024 01:53:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7325E6B0093; Tue, 20 Feb 2024 01:53:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 510466B0096; Tue, 20 Feb 2024 01:53:22 -0500 (EST) 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 35EB46B008C for ; Tue, 20 Feb 2024 01:53:22 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7A817A05D1 for ; Tue, 20 Feb 2024 06:53:21 +0000 (UTC) X-FDA: 81811265802.11.1ED75CB Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) by imf18.hostedemail.com (Postfix) with ESMTP id BDC1C1C0009 for ; Tue, 20 Feb 2024 06:53:19 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf18.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.173 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708411999; 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=SlwFkzqQmQQsUmXtYMOIIv4Pbsh/4hynGU2cMtattHQ=; b=bb+7tuuf66qV2+fsXCmn1Di+HuM9bCvLQ6ipVqVxdaxKYcI1kqLmtxtXW8oI2F7dZCMwEV dnGtckqTgXFKd9A0pZikGGmOV9tachHu+1Vv0ZRzggE6xFdtWTpkRyiVkR6mtfss5lPYTY jkQf8kYhObATm478z/7DLH7ALLP5BeU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf18.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.173 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708411999; a=rsa-sha256; cv=none; b=YTbRBCkhOE3pPRWErVk/LXh6Xm8cUsgGl0hJ0J7GnoDUMX2r8QaXMJOtv2hDWd9KTN8Wcq GClbYhmGq3uHw2iS9CGgCus6CS9Cer/282yvR04sR5gClgvC44Vl3YrNjf0DBdo71qWh+S LIn1//lbvNbJx6UAV0Q0iksPri/uMZw= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Tue, 20 Feb 2024 06:53:02 +0000 Subject: [PATCH 3/3] mm/zsmalloc: remove get_zspage_mapping() MIME-Version: 1.0 Message-Id: <20240220-b4-zsmalloc-cleanup-v1-3-5c5ee4ccdd87@bytedance.com> References: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> In-Reply-To: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> To: nphamcs@gmail.com, Andrew Morton , Sergey Senozhatsky , hannes@cmpxchg.org, yosryahmed@google.com, Minchan Kim Cc: Chengming Zhou , linux-kernel@vger.kernel.org, linux-mm@kvack.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1708411986; l=2848; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=Xgdlm55CLoh7bhkT80TmmQFtvDTRQ4HP1+zxTxJBYgU=; b=4q+yd5glcFZOpqCIQVbVR4X3XsoatKtXTiqyOtq8q0ZNNs6UmVHGxbOU+0d386EdCTHQyVWJv SM+DhZwPpWWCQGQV68PH4ymGQj6BE3cFFbARfeA4fYqACKEosa6yAsu X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: BDC1C1C0009 X-Stat-Signature: qroafkaueiuh7cdbqi7pj6zyhazzc61w X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspam: Yes X-HE-Tag: 1708411999-928284 X-HE-Meta: U2FsdGVkX19AEjVoUecKHKtXDKukauKFDD0bl9Lc5p3oDAMJpSODD/TpQQ9o/SryNg1Y9ZE5n5w1Vt0rBn604cdd0tQmEEHWPXzHhfx3fuIED1ddg3K4qVx2LfIq0lUxbbjLmDu8ikJAZAs4v/V65QbL00SSTkK5cCyq4qe72edOQYnFiP5QxvRWGUsXvaPcSSUS4u+zlYnHwQHCYkWVXWnhAhcNG4FL+1cxaZm2Z9U/7ATy4PkNPFb07HRQ7Y55zHfYvX9AQFyeTo4eelcO2nrERxyT/QBO4txSfsbEh8JZjsKEaXhX0bw9yM8f2bOXTVwCjXP5Hchi1WAYljXj0oAf8TXRrgxzQHo6EtR8glTuy7F2vPc7X2IES2cZzqEmprGsM/De/LWaXEaS854iaD40qPH5otzhqibVa0NPFo9AevGI6XdknSpvs5AFOp/OEPqlGvRSMUXhPKcUnYjkvcI/IfCfN/PuDCVQXurLx5fijdO+knTcSSOqVHPO9RWfiRcM/of7lrU7QXGTbc7ib3ph+zmuysFT3Sg2xk/JdgO1BTqg2TumHKAuXSf3HtbMgr9f69xQct4EgofB2GInQB/XqF4ophSB0mRDXxrm+Xq5D6ONvNxFCnJpCna6vlnoiLXUYHN9MtBTFQWOgIMfrfZyxFSFlTNOhis6jaY9TlW0V5Qq+24xEEFHOrom4AozA4iXs3pDwPNMGgCQGeE0S06/6Lr10vVKtlOA5J2K+Ant6i3lCvttjN/bCkFzyW50c+29C5qkXm06DuF58bPRLkPLgREP+H/qE9282v2XTALjW/HkxE3OVi1DRcPLgku1tXk8oEM4NvgJyTfSg4KvGYpIKIkLCIYXivoCmLnylC+kOF92Kc+Z8yL4hVowX46XShjH/ZqkUP+Ln6t/jHIcCvc2OvOWn1ZyZC+imkdoa7mKf57N9aSfxsUuZPo0vWym7I7LaGMmnwzODrBW3yJ bMowoY42 ZRJyly09mQD7rGT0tTV6Zfz3EYs6cKF0XFCzhayDoPAZHzJViYaOOR+HenA== 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: List-Subscribe: List-Unsubscribe: Actually we seldom use the class_idx returned from get_zspage_mapping(), only the zspage->fullness is useful, just use zspage->fullness to remove this helper. Note zspage->fullness is not stable outside pool->lock, remove redundant "VM_BUG_ON(fullness != ZS_INUSE_RATIO_0)" in async_free_zspage() since we already have the same VM_BUG_ON() in __free_zspage(), which is safe to access zspage->fullness with pool->lock held. Signed-off-by: Chengming Zhou --- mm/zsmalloc.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index c39fac9361d7..63ec385cd670 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -470,16 +470,6 @@ static inline void set_freeobj(struct zspage *zspage, unsigned int obj) zspage->freeobj = obj; } -static void get_zspage_mapping(struct zspage *zspage, - unsigned int *class_idx, - int *fullness) -{ - BUG_ON(zspage->magic != ZSPAGE_MAGIC); - - *fullness = zspage->fullness; - *class_idx = zspage->class; -} - static struct size_class *zspage_class(struct zs_pool *pool, struct zspage *zspage) { @@ -708,12 +698,10 @@ static void remove_zspage(struct size_class *class, struct zspage *zspage) */ static int fix_fullness_group(struct size_class *class, struct zspage *zspage) { - int class_idx; - int currfg, newfg; + int newfg; - get_zspage_mapping(zspage, &class_idx, &currfg); newfg = get_fullness_group(class, zspage); - if (newfg == currfg) + if (newfg == zspage->fullness) goto out; remove_zspage(class, zspage); @@ -835,15 +823,11 @@ static void __free_zspage(struct zs_pool *pool, struct size_class *class, struct zspage *zspage) { struct page *page, *next; - int fg; - unsigned int class_idx; - - get_zspage_mapping(zspage, &class_idx, &fg); assert_spin_locked(&pool->lock); VM_BUG_ON(get_zspage_inuse(zspage)); - VM_BUG_ON(fg != ZS_INUSE_RATIO_0); + VM_BUG_ON(zspage->fullness != ZS_INUSE_RATIO_0); next = page = get_first_page(zspage); do { @@ -1857,8 +1841,6 @@ static void async_free_zspage(struct work_struct *work) { int i; struct size_class *class; - unsigned int class_idx; - int fullness; struct zspage *zspage, *tmp; LIST_HEAD(free_pages); struct zs_pool *pool = container_of(work, struct zs_pool, @@ -1879,10 +1861,8 @@ static void async_free_zspage(struct work_struct *work) list_del(&zspage->list); lock_zspage(zspage); - get_zspage_mapping(zspage, &class_idx, &fullness); - VM_BUG_ON(fullness != ZS_INUSE_RATIO_0); - class = pool->size_class[class_idx]; spin_lock(&pool->lock); + class = zspage_class(pool, zspage); __free_zspage(pool, class, zspage); spin_unlock(&pool->lock); }