From patchwork Fri Mar 22 08:36:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexs@kernel.org X-Patchwork-Id: 13599736 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 3AB0AC47DD9 for ; Fri, 22 Mar 2024 08:35:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 641236B00A0; Fri, 22 Mar 2024 04:35:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C6AF6B00A1; Fri, 22 Mar 2024 04:35:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CC8E6B00A2; Fri, 22 Mar 2024 04:35:00 -0400 (EDT) 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 239866B00A0 for ; Fri, 22 Mar 2024 04:35:00 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EA5D5C117C for ; Fri, 22 Mar 2024 08:34:59 +0000 (UTC) X-FDA: 81924014718.03.7FDFF42 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id 75738100012 for ; Fri, 22 Mar 2024 08:34:58 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="h4/d94dF"; spf=pass (imf14.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711096498; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=M5OZV6oozIQ/jl7bklYmdOsNVkzp3G00p0hMTEP2k1U=; b=VIPVrJ0lWi+3ctvCKHPhs/9IW7WQGhke/VTNoviYZ2g21G5ZQvIU+V57qjxGsxmjRVN08l XvLuGXbqfoLAGwXYsH7A5aNnfyYGPNo4FGA98SSKpzJVUvqL42Z8Z63CEAVsJTBqkbMj2c zMoN5eKT+WOoG3GyqW8ZVn9nGMi6pbI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="h4/d94dF"; spf=pass (imf14.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711096498; a=rsa-sha256; cv=none; b=3xY57U2lQkiciRKSR9BAZK4bJl2aLXlAYZNFCxl22CUbCbhf7oJOo7PBgHEigguVKmR51T 7RkCezRFofLMzYai225d6x9Wtp+k0HKSecIwEhxgbh2T5PyWnbBoE1RldxNVZeXpRA2pLJ w/bnwhYaBUrblzKZE1QZj6FysOJnZHA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AEA8B61423; Fri, 22 Mar 2024 08:34:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26435C43394; Fri, 22 Mar 2024 08:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711096497; bh=WVA5iQMpP6XRPAUdm6BGPXwO6vUlPgINWjhmK5fNggI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h4/d94dFJHh92jVFstIb123+K+uECJMzjhO5h6qNXziYhpASueY+JlCKsaASBC+B6 /kJdoOCiCE9/rxMx3VTLNNK1Dpd34UZDHm+FWEqaJftEAHTC+UneL2xXg2HGZFNUHH SVcA+FYM77wBYYMu6uTlKeYWFjsJhs8wJfd6mbR6slOLLb2dGCEg0O7Rbfjw5kEDmw VIA8AsLhzenXMSa8OzzAKuSoTa2rW3/BOkmCBllehPo+yTPgSWRNyM07qug6chSimL WEgTi0VvMwYWegCZkEERh5MdlBztXBBTNm7XvJcjUUfg/eP/bZe+UzB5S/hrpwq/ND namI+bYeJFPvw== From: alexs@kernel.org To: Matthew Wilcox , Andrea Arcangeli , Izik Eidus , david@redhat.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: "Alex Shi (tencent)" , Hugh Dickins , Chris Wright Subject: [PATCH v2 09/14] mm/ksm: Convert stable_tree_insert to use folio Date: Fri, 22 Mar 2024 16:36:56 +0800 Message-ID: <20240322083703.232364-10-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240322083703.232364-1-alexs@kernel.org> References: <20240322083703.232364-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 75738100012 X-Rspam-User: X-Stat-Signature: zx9319uknrf7dpgrbys86sco385gy96p X-Rspamd-Server: rspam01 X-HE-Tag: 1711096498-461546 X-HE-Meta: U2FsdGVkX1+c0zYvaydxf2x6QyfllszAYU2zPB8u5yJhgo10gecbGIaMtI03Z27HOtllDn/shqM9ux7tudMId6Ss1u9GPch5zKV5D/QFBxpA2yePVJ2fY0+qkpSDIy0YbJCyK+dowAaiaC2Nwk+Lr79Jey1t4nNcT8qIVuKfKG5Xvh981F55cqZ4VWxfjDpkc0ttLZVPaFfsXMppIZi05JJ6Zva+Yxf96iLh/5DScCIFJKTo/k/fEjQBvEqVfZLqwsrtKwqbvOeYoGvW1ozfeGMd0e/NwM7oGPP3Lbti+p3lrhdNwQDo09JqhNx0Y3DmModq5NJpax00DOUQFD748TVh6zx7828wDJu+3lzlj1UVDZGxc1Rs1rcRaN2WuZFyhmmX9AwpvzV4UowP8OPrZxWYvmLzEkqhiyWpTTMULNFEYp+4CFwLvH/ap/fBYiX8DCXzce+k2ft3Q4Ho8jltzeDPUf+2MdylpSaTFe8FwMO/Wbd5TntW0mERZ+KIlzmeu4LDER0e8t/dv7jplCSCoM14Um068tjC0bgJIywr11XdJ0W7vrHCNW/kiXASQ1YHW3DwRAelVkt0ezTiO3rplPB5rRIbCSxGb0TyZnxLbA4R9JH2JSKvCuQzC6ypX0LBqTy07U+uqLA1znr2LtAZgjTgUv4dJvf54NvbTQ/sviMn9kyMdPn+JBKNTtkPNcHSwGvGk5k2LSb6wW3s8LJOgfD1RhcDYvXgzuS8sJpIBfMihO4CVAttk0juCI+vzLAqtwxWU3xzTBZe3Rc1DbC2o/6l3pvv8XIG/fSgJ2bbey5z/v+rOyDRhp8ROwGDTP3wa2Tgyv8abEns/6pWVXrEKSDugmHEvnb35ABGIwqxIfHsYQkkYZ7Q/AJbYaMKwvt3knVvqXAJSHViNp9rmQDEKJMFsBXStbZ99dFdGWQ1m3KFtSq/hwvUxWWK9ZJIU51LW4VNC8VUX2XPoAz7gQ6 J5l1S9dk uQ/wy 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: From: "Alex Shi (tencent)" KSM stable tree only store single page, so convert the func users to use folio and save few compound_head calls. Signed-off-by: Alex Shi (tencent) Cc: Izik Eidus Cc: Matthew Wilcox Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Chris Wright --- mm/ksm.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 30570e1f68ec..e6837e615ef0 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2078,7 +2078,7 @@ static struct page *stable_tree_search(struct page *page) * This function returns the stable tree node just allocated on success, * NULL otherwise. */ -static struct ksm_stable_node *stable_tree_insert(struct page *kpage) +static struct ksm_stable_node *stable_tree_insert(struct folio *kfolio) { int nid; unsigned long kpfn; @@ -2088,7 +2088,7 @@ static struct ksm_stable_node *stable_tree_insert(struct page *kpage) struct ksm_stable_node *stable_node, *stable_node_dup, *stable_node_any; bool need_chain = false; - kpfn = page_to_pfn(kpage); + kpfn = folio_pfn(kfolio); nid = get_kpfn_nid(kpfn); root = root_stable_tree + nid; again: @@ -2096,13 +2096,13 @@ static struct ksm_stable_node *stable_tree_insert(struct page *kpage) new = &root->rb_node; while (*new) { - struct page *tree_page; + struct folio *tree_folio; int ret; cond_resched(); stable_node = rb_entry(*new, struct ksm_stable_node, node); stable_node_any = NULL; - tree_page = chain(&stable_node_dup, stable_node, root); + tree_folio = chain(&stable_node_dup, stable_node, root); if (!stable_node_dup) { /* * Either all stable_node dups were full in @@ -2124,11 +2124,11 @@ static struct ksm_stable_node *stable_tree_insert(struct page *kpage) * write protected at all times. Any will work * fine to continue the walk. */ - tree_page = get_ksm_page(stable_node_any, - GET_KSM_PAGE_NOLOCK); + tree_folio = ksm_get_folio(stable_node_any, + GET_KSM_PAGE_NOLOCK); } VM_BUG_ON(!stable_node_dup ^ !!stable_node_any); - if (!tree_page) { + if (!tree_folio) { /* * If we walked over a stale stable_node, * get_ksm_page() will call rb_erase() and it @@ -2141,8 +2141,8 @@ static struct ksm_stable_node *stable_tree_insert(struct page *kpage) goto again; } - ret = memcmp_pages(kpage, tree_page); - put_page(tree_page); + ret = memcmp_pages(&kfolio->page, &tree_folio->page); + folio_put(tree_folio); parent = *new; if (ret < 0) @@ -2161,7 +2161,7 @@ static struct ksm_stable_node *stable_tree_insert(struct page *kpage) INIT_HLIST_HEAD(&stable_node_dup->hlist); stable_node_dup->kpfn = kpfn; - set_page_stable_node(kpage, stable_node_dup); + folio_set_stable_node(kfolio, stable_node_dup); stable_node_dup->rmap_hlist_len = 0; DO_NUMA(stable_node_dup->nid = nid); if (!need_chain) { @@ -2439,7 +2439,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite * node in the stable tree and add both rmap_items. */ lock_page(kpage); - stable_node = stable_tree_insert(kpage); + stable_node = stable_tree_insert(page_folio(kpage)); if (stable_node) { stable_tree_append(tree_rmap_item, stable_node, false);