From patchwork Tue Jun 4 04:24:49 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: 13684612 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 E79A7C25B7E for ; Tue, 4 Jun 2024 04:21:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A04B6B00A1; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74E506B00A2; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57A136B00A1; Tue, 4 Jun 2024 00:21:58 -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 3592E6B009D for ; Tue, 4 Jun 2024 00:21:58 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F204DC0CCD for ; Tue, 4 Jun 2024 04:21:57 +0000 (UTC) X-FDA: 82191908274.20.AE658F8 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf01.hostedemail.com (Postfix) with ESMTP id 09BE540008 for ; Tue, 4 Jun 2024 04:21:55 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RHO3PveI; spf=pass (imf01.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=1717474916; 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=0qXDX5IodeViaksXd9hYvuDk0UPvXZwbSx+HRfowjMw=; b=KvTGy+V572Bb4CxPQuzMdis/YAnOJWYQyI9rH3WoHo/WAXvxCI1rwjSaQN1RdOdpwmYlPR SmmAE11hmJbzt5bIfKkL9+O7EX4DKP/u1uz/QDadY13gTBH7nKLD8QbG5d0Wr1hWf/95n6 Fad9VbYDM4rE2dxTnaajJfjRIK28oR8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RHO3PveI; spf=pass (imf01.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717474916; a=rsa-sha256; cv=none; b=JA6+SaZR6lN9ru8PTaDZA+NEq3PKecRmEU8CsEEQ0oeH/EsaOspvkDnrBZT3hxWLpjGhtp lNMqus+FDmjD9L/N+DSggNfNUJmDSIZ5pUCaTl9K2BO67cbZRfvAswlZ0yVodlZRzG93yT aRL/1eO49Jf/eXvli+vOCL7bUBXA4D4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 6C3A4CE1018; Tue, 4 Jun 2024 04:21:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58B25C32786; Tue, 4 Jun 2024 04:21:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474912; bh=LoJfO2Ls93RlnzKSfQa0n7wjB2DL3+BBi16/0XKQwOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RHO3PveI2oavxMNpkEuXKJde+ksLgcEi44dvri14Czc1WMsBGUjH7nsZo+HgzTwk5 kfBBUNQ1X2VjlkCaCQICHYJLyHlCcfs2H8EyjLEvhrkJwzbgl4rmrIrXh8KKw4GWgO +B7V62sDNVW43wX7GKXMJgGFTVJ+75KTJIAEthNzgAiuA5wbii6dkqQrRn+CrErtt/ njhraJfTdI1oXQjkB2w2DQlBnqUjSaHG3MCsGDWZMPTiVe+phXMDyARlN6r68pExT/ RKud+RLAPmKjpo5VaCpohWROwJiE50q3C3lYnqt7siuesgAwYO0z3cbI4Ctydrks5a OfEPkCx5Z9wyQ== From: alexs@kernel.org To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, izik.eidus@ravellosystems.com, willy@infradead.org, aarcange@redhat.com, chrisw@sous-sol.org, hughd@google.com, david@redhat.com Cc: "Alex Shi (tencent)" Subject: [PATCH 07/10] mm/ksm: use folio in unstable_tree_search_insert Date: Tue, 4 Jun 2024 12:24:49 +0800 Message-ID: <20240604042454.2012091-8-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240604042454.2012091-1-alexs@kernel.org> References: <20240604042454.2012091-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 09BE540008 X-Stat-Signature: 4xpcu1md6n3mjs7fsy58ypxwb59way7s X-Rspam-User: X-HE-Tag: 1717474915-489523 X-HE-Meta: U2FsdGVkX18Ivd3z4q9TKtHEoDDdEVsFGkgfUYCbpJW5jFT6i4XQpcHrZBWFRSamCRBGX0S6YmVhT+gmOZDejzOqnrll49/4jGeHmjVftNWAx1mNgpy+CHnyy3DFOrwGGRb+BcWnYq1FcUtBLpzs2Ot/AxJu0gga10ZDreYv7W8HqWkL7AyxOob95jayjYuqxkvIjOYFaSz6voywnf57RAtkr3sVzZLPQVgu7oJMtuAq5BqkF9ZMz6kBkeU3ZXM8D7qEoZYXLTE7rEf7jmhcEFlTXkzWsg3djNQ3TcdI3YASDvVSC6NUGI/RuP+z7bWpPnabA8VSwaZdc7WWJKsUyFDTGYOVj04NsiufADFicVw2yELwEBhjs5KBWHhAcCF1wlBH4KUhvCk7Js9GzYq+HFPcWKLWIxrAxo4OJ/hxFAunpkfOg7mrIYXg27bOoGfiUXUStOL9OqpaoOP8w1ToYkAK3tlJXaPgY8K6uw3ryJQAElQcCPqqVRiPP47eC009mvffSuhkVNt5VS9RYrNx/ZZrDdD0TuX1+9tJ0nUAZTxOSlK6t5HKA8mI2c9op2Kmx5jS62tYMfJcSKKZI+csbkSQaIKAihOgp1g8w70HygqMdj6O4N+64XYKv5Ds8iLzsQiUkpysZYy45bBCOfqbnzjCX0HdwEpLSxuasy87xRtst0pa0e188XQI6fLG9u9jNI+vqGZ5YxhLvKWdDDAth4+RSnXdeqx1rfif8TPKI/+MJ0yTowXJU7l+BpXsR4/WzcLVPpYk3NWYJGWmoXipyfx1V2XRO4liYm0BlQKeeKxgE2RwvFxYJfci43skAfsQrU7WFWqOBT3t02G6BnyyVu1uGdS6SEgCzTj4gHl6VIUzSswqJpzg1cFBvL7QTcQEHPvHpXBkIHMRtUdvfrV+I9KPISBwK/LxQL7osFvjJZXO6q01+7BFwgZp9l0BAfBfCAnK3CVkInLMq2Gxy2h Sy9Ei2xq TadlODnaxaMcRzlitE3phXsoet9JWF0MSkzGxQVQ/Jh4/R0sIF5cSm+hHk5Bp4DHDVeynNqVOfo9J47fPg5KAm2aIpVOXQoCxxQVRhsTmbXBrtbtVqD7AT/fA7gt42G2D6bDKt5eCyM9/9rVgaNPZGKMcy/SOYNkfHKmmSxosW+0bqTlcEHi5XZdTOwxspHVUkWKMxZvMaPL5uNs2q6aVl3PmDRTNYPB59F+1zcSsgQ2x0+8UxZS315HNWQirITnlQJAmyFaKu+uksHhtYy+lJ3DUIDWN//abljIS 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)" The calling path are using folio actually, so start to folio in unstable_tree_search_insert to save few compound checks. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 24de562b64e1..14a7ca53fc91 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2194,15 +2194,14 @@ static struct ksm_stable_node *stable_tree_insert(struct folio *kfolio) */ static struct ksm_rmap_item *unstable_tree_search_insert(struct ksm_rmap_item *rmap_item, - struct page *page, - struct page **tree_pagep) + struct folio *folio, struct folio **tree_foliop) { struct rb_node **new; struct rb_root *root; struct rb_node *parent = NULL; int nid; - nid = get_kpfn_nid(page_to_pfn(page)); + nid = get_kpfn_nid(folio_pfn(folio)); root = root_unstable_tree + nid; new = &root->rb_node; @@ -2220,12 +2219,12 @@ struct ksm_rmap_item *unstable_tree_search_insert(struct ksm_rmap_item *rmap_ite /* * Don't substitute a ksm page for a forked page. */ - if (page == tree_page) { + if (folio == page_folio(tree_page)) { put_page(tree_page); return NULL; } - ret = memcmp_pages(page, tree_page); + ret = memcmp_pages(folio_page(folio, 0), tree_page); parent = *new; if (ret < 0) { @@ -2244,7 +2243,7 @@ struct ksm_rmap_item *unstable_tree_search_insert(struct ksm_rmap_item *rmap_ite put_page(tree_page); return NULL; } else { - *tree_pagep = tree_page; + *tree_foliop = page_folio(tree_page); return tree_rmap_item; } } @@ -2312,6 +2311,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite struct mm_struct *mm = rmap_item->mm; struct ksm_rmap_item *tree_rmap_item; struct page *tree_page = NULL; + struct folio *tree_folio = NULL; struct ksm_stable_node *stable_node; struct page *kpage; unsigned int checksum; @@ -2411,7 +2411,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite return; } tree_rmap_item = - unstable_tree_search_insert(rmap_item, page, &tree_page); + unstable_tree_search_insert(rmap_item, folio, &tree_folio); if (tree_rmap_item) { bool split;