From patchwork Wed Mar 20 07:40:37 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: 13597415 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 AF96AC54E58 for ; Wed, 20 Mar 2024 07:37:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FB916B008A; Wed, 20 Mar 2024 03:37:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AD5C6B0092; Wed, 20 Mar 2024 03:37:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 19AEE6B0093; Wed, 20 Mar 2024 03:37:44 -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 07ABD6B008A for ; Wed, 20 Mar 2024 03:37:44 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AEEAE140C2D for ; Wed, 20 Mar 2024 07:37:43 +0000 (UTC) X-FDA: 81916612806.03.6B6C45A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id CC9BCA0014 for ; Wed, 20 Mar 2024 07:37:41 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lrtdz9EN; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.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=1710920261; 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=PEpOEeNnd7l1doLqgw8v+weOW16uqOzVr8P7QMSTpZE=; b=R5XtLx+CKsiPVoERpZRLgbpVltpYUqaT8bRSAELCz7xVJlnMELdppuGiyzu0uKqJqK2xK0 uXmBRRA42aIiKDMh1NymlLTL/Du+nz6AHrMjXG9f4q7g7xX3RT88un/3XE/qbX6XWekqQa nLWhLHlXpYDq935jg466wyNmQD77FyE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lrtdz9EN; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.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=1710920262; a=rsa-sha256; cv=none; b=NTxNHHjjBB1H8zv6VIkG3pHZmTRRBsOC3H42xOrbgCEjm7k3vXDbAv77i+7uF06TKOWVP3 zBMAgsjLzxBe9Ta50Dzd5C3vonbCUDh9VK3Y6ZmxNOzr7gfb01zuxj/LoQ7iLuMlxmMHqd 1kIyShEjLK4BwAX1vguJ13TrEZgHQDc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D7A3B60FEA; Wed, 20 Mar 2024 07:37:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3238BC43399; Wed, 20 Mar 2024 07:37:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920260; bh=hzC9nwLvXTVgwQOMkdq44QZXi1tFep4qsRHVCT+3k4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lrtdz9ENRa11JSKhFuvNFzK8VDpY0QZ3x4rb6MBEa4oyMr2NJgCWpbHV2jZYw40bR o+z3HRQmduCdwuPMRFCiwdzy6MGkVlEhjTWCTGNYqu7oxcFus/w9HLX0YwV8uDh04h LqiI/CIgTKp/fa+5dnIicIq1hBK7r/Bdj41woNUyiRQVRrHmwoMRNKzSXt64RKgzyn p/CBIhtJBRbJtxgEIVB1GFVMzThQDWNeS2DCDX1aXc6SdcK1MXKOFDNN+2z8JuEzkQ NWaikWuHwAh6prjmxQyspSNviArYSxO43vZLCD5/cZuz28n+XaeKJc9r+l7JG9GlYp ttRhrdmd7DzPQ== 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 01/11] mm/ksm: Convert get_ksm_page to return a folio Date: Wed, 20 Mar 2024 15:40:37 +0800 Message-ID: <20240320074049.4130552-2-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-Rspam-User: X-Stat-Signature: 5jeer99bta56yoes6b1crmhede8rywx6 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CC9BCA0014 X-HE-Tag: 1710920261-210286 X-HE-Meta: U2FsdGVkX1/Lk138zqcWew3QtrkxkYjuKzzQp6OeGC/r100GwHfxnQIcwA78SgIcLGMYE1Je0CvBeJIvc3AfmM4GZ8kwNBousiMM3Bc3L4Qcj4P7aXy06mtFZ65G92WD+St5j6Vln77+FfmGu7sOXxpbEeeGXuaxXQli8Y3RDeSyQZ+UqjBtbKcxxuWb7UR6Na78XWHrEmVvE5ma5zfOZkdcD1G/3jzKfYh9OKqO8cQZGynzQc6tqTdNZsJygUftEbyl/CrSR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uvfHov3G1/D6gVUqfzStmnL2K0RBMPLG7bBTgxI5FsBybnBqncIx0G0tqJuZlvAW8N86duBKgFNkivkNuj8y6yx8MR22T47JNBQFGPiFTJy1QBGbZHvhA4il2zRL6VrssuNc9QSB5qwzUcm+QLeJ2TH3v4ZXVMtppYgp9 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 ksm only contains single pages, so use folio instead of pages to save a couple of 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 | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 8c001819cf10..fda291b054c2 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -915,10 +915,10 @@ enum get_ksm_page_flags { * a page to put something that might look like our key in page->mapping. * is on its way to being freed; but it is an anomaly to bear in mind. */ -static struct page *get_ksm_page(struct ksm_stable_node *stable_node, +static void *get_ksm_page(struct ksm_stable_node *stable_node, enum get_ksm_page_flags flags) { - struct page *page; + struct folio *folio; void *expected_mapping; unsigned long kpfn; @@ -926,8 +926,8 @@ static struct page *get_ksm_page(struct ksm_stable_node *stable_node, PAGE_MAPPING_KSM); again: kpfn = READ_ONCE(stable_node->kpfn); /* Address dependency. */ - page = pfn_to_page(kpfn); - if (READ_ONCE(page->mapping) != expected_mapping) + folio = pfn_folio(kpfn); + if (READ_ONCE(folio->mapping) != expected_mapping) goto stale; /* @@ -940,7 +940,7 @@ static struct page *get_ksm_page(struct ksm_stable_node *stable_node, * in folio_migrate_mapping(), it might still be our page, * in which case it's essential to keep the node. */ - while (!get_page_unless_zero(page)) { + while (!folio_try_get(folio)) { /* * Another check for page->mapping != expected_mapping would * work here too. We have chosen the !PageSwapCache test to @@ -949,32 +949,32 @@ static struct page *get_ksm_page(struct ksm_stable_node *stable_node, * in the ref_freeze section of __remove_mapping(); but Anon * page->mapping reset to NULL later, in free_pages_prepare(). */ - if (!PageSwapCache(page)) + if (!folio_test_swapcache(folio)) goto stale; cpu_relax(); } - if (READ_ONCE(page->mapping) != expected_mapping) { - put_page(page); + if (READ_ONCE(folio->mapping) != expected_mapping) { + folio_put(folio); goto stale; } if (flags == GET_KSM_PAGE_TRYLOCK) { - if (!trylock_page(page)) { - put_page(page); + if (!folio_trylock(folio)) { + folio_put(folio); return ERR_PTR(-EBUSY); } } else if (flags == GET_KSM_PAGE_LOCK) - lock_page(page); + folio_lock(folio); if (flags != GET_KSM_PAGE_NOLOCK) { - if (READ_ONCE(page->mapping) != expected_mapping) { - unlock_page(page); - put_page(page); + if (READ_ONCE(folio->mapping) != expected_mapping) { + folio_unlock(folio); + folio_put(folio); goto stale; } } - return page; + return folio; stale: /*