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); }