From patchwork Fri Mar 22 08:36:52 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: 13599735 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 60824C54E71 for ; Fri, 22 Mar 2024 08:35:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 205E96B009C; Fri, 22 Mar 2024 04:34:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 15F606B00A1; Fri, 22 Mar 2024 04:34:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E04816B009F; Fri, 22 Mar 2024 04:34:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AF3E16B009E for ; Fri, 22 Mar 2024 04:34:57 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7BF9B1413BD for ; Fri, 22 Mar 2024 08:34:57 +0000 (UTC) X-FDA: 81924014634.24.F06A5FD Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf05.hostedemail.com (Postfix) with ESMTP id 35939100010 for ; Fri, 22 Mar 2024 08:34:54 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tGS9D7Rv; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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=1711096495; 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=abZKdZWqgpqATcN0E2cm42vDhXwfWSfcAYNHtPBFWlg=; b=Qzvgvw2ZZx5l+eMyJuVWUu7MtPU4dpsnrC8NXbNl9LczFqw02C+Eg7Pkif6PEMcIjOgQHB dYoDtvtywcHIiXpNLMNVbgagUcNhvcRdoP+lgOuVE5dP8Ua163wObNi02XdRKB24mYNkTm DV6yH4Z1kpcruq4Gsfya7xS8Igd9CKg= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tGS9D7Rv; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711096495; a=rsa-sha256; cv=none; b=lwXOczhOBAcCb67QdPsghIRs82CKEUtzFVTP7o4pha93oDBLMYsg1xf70IEjzjUftWFFPk MHJrY6GeaFmcPX3HwSOT0IRkKC+xWOnGGwiiKBsJxbWRlbHB8TulhPKLUm1R6TVJ+Kz0Y8 uepAVRPNqnTMM4B9edWx8Dy/wbtYYO8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 86A94CE169E; Fri, 22 Mar 2024 08:34:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87C74C433C7; Fri, 22 Mar 2024 08:34:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711096485; bh=swBWDDTfKPZfIshmO9+8+Tzqpp1exgNxKwXg3dE2124=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tGS9D7RvKPTXxnlUVQ0m7lLcLgSe2JsQ/C16nFNsWIGdx4hoVu89jKYQPZ4pVIQkm LUZdfrNIl0j5qWWmh4/GQMYf3eOKTE6mHp5fIGtBMuuvvVAP+R5SFBNQbMPnw36m3V Rf2vKsB8o3WwISyorzm7bMYUo9LsItXJR25HAL8vwOxVRpln+3DCSY0tLqkFXpRFcx xS1EuUj37mxQQVQ1p71HaIYocf9QpwNj0O7EzfE4w/5f+JtGoz5o3C1LZy8CGETqLl Bm7PkXRuP6Zq38bMbL9QYNQNM6p9vGLqBrL3lahxrNBsWhLEtglFCySXScJBlQ1LDs bCd5xTUf+YRVA== 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 05/14] mm/ksm: use folio in stable_node_dup Date: Fri, 22 Mar 2024 16:36:52 +0800 Message-ID: <20240322083703.232364-6-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-Rspam-User: X-Stat-Signature: 1u83x61swo1h1r889ydrrqqd9tdzg4xj X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 35939100010 X-HE-Tag: 1711096494-455729 X-HE-Meta: U2FsdGVkX190dyPi2dacQ7nwR/0bkTd8bmzfu7uP2hPv0Bx+BVloTNBueiljyKHBafW0dG1wqu1hygJeCm7xsE2i2JrF2Zb24fcHAClWVyzrCOx9UQOeowsQ6FbOVzImA+dz5pRcyFnquqTrNZtFRe2SyoAtpCw5L5aEpRqc4CzlU+rJU4UuXK3LzHGPGZYTjqhv2xLJdvv8PLOreDAF+XGV+KR+LWYqop89/2yYcjII2NltV5uCbFIfdqMmE7TpEN7b1UNx4qHtC41/s/FWGbWkoIucotATq4hqW0ZvZ6+Lj2xZf3Nn9AcbJS3Qney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jA7CjrYsy90gbTodUGGr3370KwfbWtKpVZcuq1h1FpBo4IhwhJWmaJXHUv4KEobraifrTSqaGn3oIFGoACqT6AJ3j+gJPfan0AuOsEzy7w 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)" Use ksm_get_folio() and save 2 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 b6ee2bc7646f..a1e382ecd501 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1631,14 +1631,14 @@ bool is_page_sharing_candidate(struct ksm_stable_node *stable_node) return __is_page_sharing_candidate(stable_node, 0); } -static struct page *stable_node_dup(struct ksm_stable_node **_stable_node_dup, - struct ksm_stable_node **_stable_node, - struct rb_root *root, - bool prune_stale_stable_nodes) +static void *stable_node_dup(struct ksm_stable_node **_stable_node_dup, + struct ksm_stable_node **_stable_node, + struct rb_root *root, + bool prune_stale_stable_nodes) { struct ksm_stable_node *dup, *found = NULL, *stable_node = *_stable_node; struct hlist_node *hlist_safe; - struct page *_tree_page, *tree_page = NULL; + struct folio *folio, *tree_folio = NULL; int nr = 0; int found_rmap_hlist_len; @@ -1663,18 +1663,18 @@ static struct page *stable_node_dup(struct ksm_stable_node **_stable_node_dup, * stable_node parameter itself will be freed from * under us if it returns NULL. */ - _tree_page = get_ksm_page(dup, GET_KSM_PAGE_NOLOCK); - if (!_tree_page) + folio = ksm_get_folio(dup, GET_KSM_PAGE_NOLOCK); + if (!folio) continue; nr += 1; if (is_page_sharing_candidate(dup)) { if (!found || dup->rmap_hlist_len > found_rmap_hlist_len) { if (found) - put_page(tree_page); + folio_put(tree_folio); found = dup; found_rmap_hlist_len = found->rmap_hlist_len; - tree_page = _tree_page; + tree_folio = folio; /* skip put_page for found dup */ if (!prune_stale_stable_nodes) @@ -1682,7 +1682,7 @@ static struct page *stable_node_dup(struct ksm_stable_node **_stable_node_dup, continue; } } - put_page(_tree_page); + folio_put(folio); } if (found) { @@ -1747,7 +1747,7 @@ static struct page *stable_node_dup(struct ksm_stable_node **_stable_node_dup, } *_stable_node_dup = found; - return tree_page; + return tree_folio; } static struct ksm_stable_node *stable_node_dup_any(struct ksm_stable_node *stable_node,