From patchwork Tue Apr 9 09:28:19 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: 13622064 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 EE185CD1297 for ; Tue, 9 Apr 2024 09:25:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FC606B0099; Tue, 9 Apr 2024 05:25:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 65DBB6B009C; Tue, 9 Apr 2024 05:25:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 417436B009A; Tue, 9 Apr 2024 05:25:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0E4746B009B for ; Tue, 9 Apr 2024 05:25:31 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9CF11A0794 for ; Tue, 9 Apr 2024 09:25:30 +0000 (UTC) X-FDA: 81989460420.15.2882FF3 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf22.hostedemail.com (Postfix) with ESMTP id 94577C0006 for ; Tue, 9 Apr 2024 09:25:28 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=p5Bnq1HO; spf=pass (imf22.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=1712654729; 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=6QulrtiHM3qMf89NRSaECQx6TgoGBwLTjWk8wB72ft8=; b=XmiccHuHdU2Ys/11N5+Dqvdn+Vo54Fj0AnHxKPlIgR8hsGlOBEDbEEvWOT2hQJkCxJLCPM 5N/pIa51WDScR31B7apohk+9qfE11NPd2sdwZ7VyuuiagFOPxblQpDyXms8bs1/skSImHF o/ok8ZQUYvijLp+bwaGak1rjuy4tZA0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=p5Bnq1HO; spf=pass (imf22.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=1712654729; a=rsa-sha256; cv=none; b=QIXDfpGPo6oIodO+iCLpa+3zPuvGG7HxSIyvV1NehwoXk2N9OgwZXa315IiPMbw5RhKiwo XT8SQxHq83FXACdfNWETAeXtlDHOIWUQKJjh53PvLJnRIgcUKaZxbINVrk8Tp6TE6eNE7f BZTPKKTEip8uBlZAViAGbgvUJE68BRM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id ECF6ECE1DFF; Tue, 9 Apr 2024 09:25:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 215C9C433F1; Tue, 9 Apr 2024 09:25:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712654725; bh=75r9vBcHOLP/QZTkSWPs35KE2gnggcdp1NXQWqEu+94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p5Bnq1HOAUtLmDUOgf30B1us3yYOvoqfbsqdgljPW7tCMagB+HFvKmmnfPuHCqaAA WPbEjJPAWmlTdry8oDNy9VfvJlw3qvFvbmUGQul6e8oP+RnraHBE2TakqzFIhvQuIq gphN4ixndTfyy2XxZ/Ih4+dcjLFX157nljTFeGMVlsqBhy/vxZP0XlmVcr8GIPuJKa g7j8plpLvXti8Y8cI7oq9RyAyMvD0AqSfkFNlBH7UdUQtfuiXx2IH96mDn4IDRkCZo dWGzI82T70q/SMpExS+ufP8Za7G3Te0vL34DVbmTxufVb5E77tIJ5+arJk5Z4eqxrd Gymd/Ri0z08AA== From: alexs@kernel.org To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: "Alex Shi (tencent)" , Izik Eidus , Matthew Wilcox , Andrea Arcangeli , Hugh Dickins , Chris Wright , David Hildenbrand Subject: [PATCH v4 4/9] mm/ksm: use folio in remove_stable_node Date: Tue, 9 Apr 2024 17:28:19 +0800 Message-ID: <20240409092826.1733637-5-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240409092826.1733637-1-alexs@kernel.org> References: <20240409092826.1733637-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 94577C0006 X-Rspam-User: X-Stat-Signature: ajbt5yxak9t553f4f41jojugmcy1sxyg X-Rspamd-Server: rspam01 X-HE-Tag: 1712654728-969281 X-HE-Meta: U2FsdGVkX19ujgzY03Z+Ug+CVn6nf1Nqi1ockrICOiIp6ajOlOuVh3Q94KsZ11wA8pP24ZAtnBnwV640U1DzUGFB1kP0F7U1zaSiWvwLy8tZ9sC6SeB6h7MTbtoQIRKgZUywQVGTULdVH3uo8OR4aJx3tNCmD7flSZqjrqp34T3WBL9HfZC0AxZ/kGmG1C/EUWG1yfWAFeCLTg0yaRDhrh1lH8gezFxcOUIKJQRFcVVqL+rCsSJR4iHGPhP21+GLeI/QqGRIsRnMbIBaVCzQijKrtZU/fOh8vNe7Eui2CCpiUVmpXP8LnjkBgB65qUHsvbm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O7Om8xtX+ruiEHBSINCeJFWrUNv2rxF9+3XBBQtxPTtRJZtEOgMakEvKntLce5lyQHxn8NPzPwwaljWv9JjdZowXvIjNDjy 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)" pages in stable tree are all single normal page, so uses ksm_get_folio() and folio_set_stable_node(), also saves 3 calls to compound_head(). Signed-off-by: Alex Shi (tencent) Cc: Izik Eidus Cc: Matthew Wilcox Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Chris Wright Reviewed-by: David Hildenbrand --- mm/ksm.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index c9b7c5701f22..b6ee2bc7646f 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1121,11 +1121,11 @@ static inline void folio_set_stable_node(struct folio *folio, */ static int remove_stable_node(struct ksm_stable_node *stable_node) { - struct page *page; + struct folio *folio; int err; - page = get_ksm_page(stable_node, GET_KSM_PAGE_LOCK); - if (!page) { + folio = ksm_get_folio(stable_node, GET_KSM_PAGE_LOCK); + if (!folio) { /* * get_ksm_page did remove_node_from_stable_tree itself. */ @@ -1138,22 +1138,22 @@ static int remove_stable_node(struct ksm_stable_node *stable_node) * merge_across_nodes/max_page_sharing be switched. */ err = -EBUSY; - if (!page_mapped(page)) { + if (!folio_mapped(folio)) { /* * The stable node did not yet appear stale to get_ksm_page(), - * since that allows for an unmapped ksm page to be recognized + * since that allows for an unmapped ksm folio to be recognized * right up until it is freed; but the node is safe to remove. - * This page might be in an LRU cache waiting to be freed, - * or it might be PageSwapCache (perhaps under writeback), + * This folio might be in an LRU cache waiting to be freed, + * or it might be in the swapcache (perhaps under writeback), * or it might have been removed from swapcache a moment ago. */ - set_page_stable_node(page, NULL); + folio_set_stable_node(folio, NULL); remove_node_from_stable_tree(stable_node); err = 0; } - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); return err; }