From patchwork Mon Mar 25 12:48: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: 13602024 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 13165C54E64 for ; Mon, 25 Mar 2024 12:46:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE4756B00A3; Mon, 25 Mar 2024 08:46:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D6AF36B00A5; Mon, 25 Mar 2024 08:46:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0C2F6B00A6; Mon, 25 Mar 2024 08:46:13 -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 AC91C6B00A3 for ; Mon, 25 Mar 2024 08:46:13 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6F1388017D for ; Mon, 25 Mar 2024 12:46:13 +0000 (UTC) X-FDA: 81935534226.18.CD40EA3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id C8957C0010 for ; Mon, 25 Mar 2024 12:46:11 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nBzjRhYA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711370771; a=rsa-sha256; cv=none; b=JOGL0jSU7B5joIfrVZ7jqrlOOO3IzUiRMg6VYofCM8KEjAVcmmQgp0xYUsqJNy5TwqXA40 sd5v8ZLB43CSAuhClkAYJvWVkZpB8E5vA3iM8N7FQ9iVAFXo79RSZqofQxzF2BKd4wFW18 j56iux7H6Gc+f/Pne73l1kUxpPARwu4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nBzjRhYA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711370771; 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=drZ8VsaKg2g/ZkhLYU7ItdOSAFvCMG+KJPpQlCmXG2Q=; b=X04zWDHNYQK955EpGHqBiq317kMC136Q/xvk1oU8ULjriv6o5MkGis99bndS9C+liMMNbX Ez5HgiXUd6K0K+IDbo7ea68cyjllnlgGA2pQdwKsHpGW4BmFV4jyE2JUTLiDOdZZR/XkHv N3F+AKzkup+yHiG9FPB9HV1OXZNtL4I= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id F147F60FA6; Mon, 25 Mar 2024 12:46:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46A41C433C7; Mon, 25 Mar 2024 12:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711370770; bh=iGqchiYFmo0ETruqN+yqTmLWs9IEH21XszhOvMHk718=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nBzjRhYA/s+ei3HHXwyi91lkTt42O7ifcVbgqgcEbQ6VgULgAXnG6f+FJB4vm7f7R hzX3NDEtbPSkPPHnwEteD3fCeKNlNNTm5Ak3Zhy8XEPfpjmCRSqPDgF+xVmlE376JH yq07703jv7pjhsHtZCQcCI6yvjhsoqaWJh3dHMTqLxgnIOZ8XPXWB2W93tD1/mCESJ tGgvR3enYDoFwJ3j8gou3N2SlDsfwwf1pgxPFDvC5L+WqHBK4Cdzn/1+dwCpaF+/TS LBssjlDr/u89yJ2CGBNIydvk/6G+d7mfRYX6p7ivRTY8ml7tJnYDaZlJ56a8fYf9Pj Aea9WXhpwo4XQ== 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, ryncsn@gmail.com Cc: "Alex Shi (tencent)" , Hugh Dickins , Chris Wright Subject: [PATCH v3 09/14] mm/ksm: Convert stable_tree_insert to use folio Date: Mon, 25 Mar 2024 20:48:56 +0800 Message-ID: <20240325124904.398913-10-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325124904.398913-1-alexs@kernel.org> References: <20240325124904.398913-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C8957C0010 X-Stat-Signature: 9ngdddfgu7t4j3izy4crtdsnsn5t4xfy X-HE-Tag: 1711370771-251077 X-HE-Meta: U2FsdGVkX19X+NK1w+x38cAdoDpp8hGfRhuNjilDL4ak7w/y7q0v/00M14vsnll5qFuWhT61ufLD0wpJbHCPJcrzEB7/2AHjSBFBbNQ6jQB3Lz+HMnWqLFHEax+Ix64R/SsxWUiCbJZJJoYG4y7iLfgs/6MBP7IAKs+/jV0a5IiCTBOrjklmjc4PyDp0c51fBJBPBlzOyhNlL62xU+b8OSV3ShL4IB8uz35YVpQ4+UEhAUArn5Jhu235ERN2RDb0vw037BK7MqKTqwQKvbDlEXS15eN6BPsCowY85uLd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WC5xkf1lMzcD49quMsyzHax0Bs0aE4rDqcYsbJOxTBIwZxLSVsre0mxAJJ8TCc7vejGp3l4uQ8rgnH67dL93fievlNgnEbLlmMtiQemRaVg0ZXPizyg43tk29ziyl2JXNInSobbIWgOd6s6Y/ES 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 7188997437d3..c2afe2f926db 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);