From patchwork Wed Mar 20 07:40:44 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: 13597422 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 667CFC54E67 for ; Wed, 20 Mar 2024 07:38:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE3DC6B00A1; Wed, 20 Mar 2024 03:38:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E6BFD8D0002; Wed, 20 Mar 2024 03:38:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0E0F6B00A3; Wed, 20 Mar 2024 03:38:07 -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 AF19B6B00A1 for ; Wed, 20 Mar 2024 03:38:07 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 89221A1738 for ; Wed, 20 Mar 2024 07:38:07 +0000 (UTC) X-FDA: 81916613814.04.5DAC5AD Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf14.hostedemail.com (Postfix) with ESMTP id 46D2810000B for ; Wed, 20 Mar 2024 07:38:04 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P7kGTdOt; spf=pass (imf14.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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=1710920286; 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=XcL7u56NLzAPEzXQH0hEzLcGTarQ+zwsSoGtAxDm4h4=; b=gujojCt6F49vgl0is90FmKUk3Exoz+r5UGreW3mLNkxwGDsOjp6p/QybZcf04TsmfKi7nR lKOgL7rF8T0DozWSmyYXgKgrg7ezKr3ztfmcEQv7Rkpre+gSH3I2fhe/Y08v8zsBjBvnPL 6WoaDtL5Ci1iAJRkDKNR1cAZYEeuRW4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710920286; a=rsa-sha256; cv=none; b=k6Xk3jmR42eHpsH63cAmhO6M49/fDddc2CTER2MIi3GY6qChf+pTJ+J5t3EgzOtejHtmtO b34gV03aijW1dBuf/AStTO0PZGxo7UAGx1s/1aIwI6EK1yts1fUa5hywFcXPbbq5iH0zm6 34ED4qdglvTsxPwfcw9sOVEDTu0f64I= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P7kGTdOt; spf=pass (imf14.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id A7166CE109D; Wed, 20 Mar 2024 07:38:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4B16C433F1; Wed, 20 Mar 2024 07:37:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920282; bh=rdqHFbrLbUfNMTwK9NhbP/z7rMDrfdCWv7WBbuSbpoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P7kGTdOtJXwS+CqqQBmTtS71n3PQ18LbacGDQuh/lRh42lDg2iTEayH6tSB1h2bxN MrFoF+KbHSF2yqHtMdOX1qs+tosrFeLbpmemFHjLSVQmFpHa7XVRdgfCq44+BC2GQn hNlKEFkjh8KST5YownPLSNmyqo1XOoJhOYDcFNAsw+aE3GVFYVKTJ+/uLPlccUufPs X3wpNM1X8oqEebZhud/wtB3c2YdkoP9UUxDdszXnW+UBNIEJa9OhaeYN0j6V1EE/Nu zB9352SkNM7OKNTbg5EXBn8mtVsfJzr+hH2RNih4eLmYGeKuW/hUwDb+DbtupYZfg7 x9DhUNWe+gMfg== From: alexs@kernel.org To: Izik Eidus , Matthew Wilcox , Andrea Arcangeli , Hugh Dickins , Chris Wright , kasong@tencent.com, Andrew Morton , linux-mm@kvack.org (open list:MEMORY MANAGEMENT), linux-kernel@vger.kernel.org (open list) Cc: linux-kernel@vger.kernel.org, "Alex Shi (tencent)" Subject: [PATCH 08/11] mm/ksm: Convert stable_tree_insert to use folio Date: Wed, 20 Mar 2024 15:40:44 +0800 Message-ID: <20240320074049.4130552-9-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240320074049.4130552-1-alexs@kernel.org> References: <20240320074049.4130552-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 46D2810000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: q6f1yfr61gy9ma9dohkecdu99ba73fwo X-HE-Tag: 1710920284-821425 X-HE-Meta: U2FsdGVkX19sIHucDnSx/AbDukV3Jc6fKz9xJ+LmrlNaMYU+eSxI4z6hmWfX2WzP2ExAeKWA8BKphcWlMRfOSZaowxpd2AM6n27daJ7KvTP8HN/bdwMUm7/wzfFeowdUeyYonj4eQcYnfqjEbEeaXw6nm2aCZuEBvV3OwXOj9VvJlwUfnuziJ6CFyiCINrExVmUIHHwv4UifNOx0tSbH39l/dRHFmakDf7cZbcxwblVrHNlG3esWha/ukJivBHu8l39MTp47r0pTBz+EqdrcyCCM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/hC6hHzFJE5o2QWD8wlyi3pe0jYbT3RqNsIWYhIeIdH+4nUH0C4qlx1w7pSV/2YXnhHmFmUIMvPhRIyIpuluJAl+FaiJPqq2tKJac0T1En48WLU/tP/47H+FtqMCb5i8f7edLSYrjG 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 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 648fa695424b..71d1a52f344d 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2062,7 +2062,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; @@ -2072,7 +2072,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: @@ -2080,13 +2080,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 @@ -2108,11 +2108,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, + tree_folio = get_ksm_page(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 @@ -2125,8 +2125,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) @@ -2145,7 +2145,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); + set_page_stable_node(&kfolio->page, stable_node_dup); stable_node_dup->rmap_hlist_len = 0; DO_NUMA(stable_node_dup->nid = nid); if (!need_chain) { @@ -2423,7 +2423,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);