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/CrSRnXmPXGIN6LTO41rVJaIMQVY5F/ENxe0J1/SvcXJouBICQkIHmIb3YUqFW8xYTlMdFLG0Sykd4lelKsi9GEewOYvtprs6iby9YFy7VHHGwzpYR29UEMLg5vsTTzAjJtoKKpG8+FMBDp5UYJpVMi8WjeSUg6jv75gwjd7LJee3EwYQcFs3rkgy70fif5C14HzDG+gLsH7bZ8Hd+aGeY94QA7WIlR+E5HkidOXPQFKjEN2RPZ5p4KLMKaQXSKOMez6NswUQLyO+CkxkfD2oQT8P9127Oam/FAM3masWIQGXrdyuCUe/LAexRAaBn+s+mARSA8YCEnFXZVdWTuZuTr7GpJHPGmsXhr+hRfX1Ch6eNaUmGr09Edv1SYQtcYZvrmMtFLv0TESAMbckzwwEry4PoCL363MiK7QOAQMysjtjiyHbk5xN+tT5xAE+T1qo0xlQNFarjJolaCxKJQvIKrHmy0cJW2K6CTv3FksSy0fc/Rx/+tVVTg4iQvzWWpbTyZSQ+AZPfi/SPLO/i184cNhn1m4Yu3jv236t8FNu8L8ULKGjeodbBbfK6/HLzFnV5HhSLYST+EToDHOYO1wfH8X512uGXK+6QmH0AUhsOEySf9rdCJARj9ThO0QhA3pyykBqdw1/ypw9vQ+x07QEMgh6hWqvxSQaI8MLpB9bQY22K97eWyrJMoKKeaFINo5mvHl8O9ZuOxtuR0 0gd/4iyY KboQn2lVNmRF7NIHAH52Ymg7NAd2nnPW5xwZQYLu8jMlXGW9S60VEZ7JA1mWd3TcQpb+nUy2vYiv7CpkCVkhBp4g998yv6vLx4TiH5+s53+2xRRSxVw8fgenFUvOTkMztfnon+gaT3t3FvMpB2rOSw8uMMfcx+/j6d9DdHb2bZCrJPT5TFQQgfCwzlTgUPvEIbTkDcdh/Awpws/Jh4Gp5QwJu2UNYWkeV/9isyRxuKBgN8pMRG/sxG+0Ta6Le5AOUXfZ7eX78gmh5fObVKRd7mTajncTTwVEjOaPuHMkkhtrCAzSSVvu+V6Obj1skilkqVxCvZE6ksn5Wnc8rQhtGubWtq7aCa6PuvfHov3G1/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: /* From patchwork Wed Mar 20 07:40:38 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: 13597416 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 7C1DFC54E67 for ; Wed, 20 Mar 2024 07:37:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0C236B0093; Wed, 20 Mar 2024 03:37:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBB7A6B0096; Wed, 20 Mar 2024 03:37:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5AFA6B0098; Wed, 20 Mar 2024 03:37:46 -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 BDB9F6B0093 for ; Wed, 20 Mar 2024 03:37:46 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5465B120351 for ; Wed, 20 Mar 2024 07:37:46 +0000 (UTC) X-FDA: 81916612932.23.42DC8D5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id B2E0F1C0006 for ; Wed, 20 Mar 2024 07:37:44 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UxsXOdDy; spf=pass (imf18.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 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=1710920264; 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=P3PwTI3lC441cH7scUPR54+kprIKpSjAWFlcAfP6FSE=; b=7Iqdvn1FhVFwUFOrZPanhzUZko56V2brz/zcnhXu3S91ByY0+xPBTQun4L9NrFRBj9WSGR 0+IblzsmEPvjrBIH2a2gTHmfa/JDIt3ceNYzv5xjaFOJQ2QhdUd4M9ibvVNqbg+8ArqjOt OeCnNLbxAYsSTcPM96ypawQbGdeX81I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710920264; a=rsa-sha256; cv=none; b=3Qc2u98QMOvCK54MDaQOXp2xxLYjeAHQ5idPrA/YB6GbInur4IdkqOIS8PcD71cPvMEDQu itEBlszqhxTNDjWnnGUXmV7fJjT3p9OfgTippsoRN1iwXQSve9B5rAhzRX/US120Zr1YH/ wcdbygrfzrKTQEvY5JKLbSmB5HqQ2ek= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UxsXOdDy; spf=pass (imf18.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 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 dfw.source.kernel.org (Postfix) with ESMTP id D329160FE4; Wed, 20 Mar 2024 07:37:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 565C8C433F1; Wed, 20 Mar 2024 07:37:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920263; bh=ogVdYvzWIODvepKssBDhcBjAFm2MyCuzb8iad0ikR9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UxsXOdDyeQz/LeOFJ5thcrVWPFUWSF0xAf89HiGMSe1y1BQ5CAtLaFvVrMHInOuCX n08x7z24gQKQo1Cys2BHt6sOQ0roKLbru2L4miwJv5QpKzMF0f31/Lm2LEH6kR523t 20RATbtX0L90o6l3JGyxonZhk3vkJOCXrcafdQzlPDTPVbAFVtXtB6Tv1vhu/iEyVG G7HhTffwrFbNX6CMK4TGBGryk31ciBggJCmbLm/iNrVqu7JvPkUAnhs0cNnxl4w+p9 pej6aCsV5pTOSmF5hEJTHfIxd7MPpkAe3JtPHU6COh7OhEJLXeBnUgbRwgXSco1Jsf EYGDO6JVtUAnw== 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 02/11] mm/ksm: use a folio in remove_rmap_item_from_tree Date: Wed, 20 Mar 2024 15:40:38 +0800 Message-ID: <20240320074049.4130552-3-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-Stat-Signature: o94zx48145aybyqybks4xisbup1i17qz X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B2E0F1C0006 X-Rspam-User: X-HE-Tag: 1710920264-872909 X-HE-Meta: U2FsdGVkX1+w3D/vRSgUX4seTLP5j4mb56svTEc695gDSGtah64DVomJJCfO5JauQxVujcHkQ6K6GmWwiB1JN5nY6ahHK1Pu8wfiBSaT05MoaMCksGLhMPFFjk5jUrRVUs3+jq7E9+Y0RD9zxEcqFXkuO9vh/p1JZZqmZkRlNgn2xq11Wq810h4r5WLsvIXNsdjoBuOQou95A6+nOgAaI4ZepZRhbrL9Ndf+TULVncuRmrdyvH+5astqPZ7oRdOHZtIX9PEpqaxHYMPWPmqCUg07XeDXn5jMPNoE2fOumSkLiLoDneW3CBOaEAiabuvZtylTOHm8vo5syin97coWgIozhlHhwSXK7+Qc8GeGcn53N58qJXMZ9qvZsZBwmLCE0RJishvvFwcImzhdwT+20YgzrSkruo5d7ITWt2pGD3pvr08KMo5rIS9QibVLERF51DYg4Um9jRoF9hZqpXn1LMKU40gcadkHRS8Zi5g2Rln1czOCUljAGURkOBfvl5354PzCWGj0s6qGQhhhQMx8CSBAPhswR19bUQgbGreNJe91dX9yrwL21aBWFBj2AlWPSjfUaC2m5qe+FO+pjxLhpqWaEO6qCDWTWsGJvuve9DVSx3Z3HbHQ11GnJ5iBftW/zbSh5BJhtJ06lNPJ4V31WNECSzwnLgJbWInSDc9r8fN6odTyyl37Suja21jOUx+5aOANbstTarI7f4sHLfc5PIp9sHHjqIrQm22cWKpeI7b8fA6sToIG98s6uBWkSe2ui1wmWJgW+oRr9j9uWGMTh0+ZmdjJA+kI09PwFfhAh70mjYZftPk7lnTMiEwTdKsL7Oud5uR0f1ALxOmP/wFjkKwTT+tpTqu5KNdKQUBNYf87k0RMwEPD4xUTwjkuMZ/SNXrJaWHv3goTdaaLWnVvW0OEfzURDmZQ5psIY9hDamhCfLVUBtkJPPW70sF9iOe2Ga4bTM5w7rbxQcvCmWM ctHmIGpI uoW1ZDIp/6Xj0MhAdDjvmlYodDjEfxifn+xqIPjhBKCREXaGmBEcXVsr0GK8zV4MBtgs26/4PP8lOOw2NjlwX93BvBKxms9B/hDyIYruh1LcXLMSJJGfT038/P/aPAheIz5x+4sPFNQwjaSUBzYJlFs+QR67bOdmqBAiqoMyRC7gO2ymP7SOOev7bHZuOCqIVAW7MIHrZXKh5NZSxdNuI2D3Yk+hzkvgcRmkK2NQTmHa/vEx1UpEWHcybh3DLY4zjnHTtVBA4kopBh00GYUcdS4wfEbHErWSdg/HOmlqvnp5RKt872Kw8lZQaNjBedDXLMMBTVcFur2T+yXKlhlEbNyHbiGMxEL9ItYd2wGD9oggElhHkHtGPt3c9AKt+xkXomY4PToderxe9z+9EqgXqwL/XwrB9hYk3aK+2o85C5hcTAFr+9WL4FNf1lnXSrjrQCMpVR8mg1RVEIg4L1GI218QR0dMB15s/VKxjHEgNmb3unGv+Szx+J6WBSHyR4RPKocfJ 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)" 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index fda291b054c2..922e33500875 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -998,16 +998,16 @@ static void remove_rmap_item_from_tree(struct ksm_rmap_item *rmap_item) { if (rmap_item->address & STABLE_FLAG) { struct ksm_stable_node *stable_node; - struct page *page; + struct folio *folio; stable_node = rmap_item->head; - page = get_ksm_page(stable_node, GET_KSM_PAGE_LOCK); - if (!page) + folio = get_ksm_page(stable_node, GET_KSM_PAGE_LOCK); + if (!folio) goto out; hlist_del(&rmap_item->hlist); - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); if (!hlist_empty(&stable_node->hlist)) ksm_pages_sharing--; From patchwork Wed Mar 20 07:40:39 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: 13597417 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 9A0D1C54E58 for ; Wed, 20 Mar 2024 07:37:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D6CC6B0098; Wed, 20 Mar 2024 03:37:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 284DA6B0099; Wed, 20 Mar 2024 03:37:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 174E16B009A; Wed, 20 Mar 2024 03:37:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 07B0E6B0098 for ; Wed, 20 Mar 2024 03:37:53 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9BDC980937 for ; Wed, 20 Mar 2024 07:37:52 +0000 (UTC) X-FDA: 81916613184.20.E360D5E Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf19.hostedemail.com (Postfix) with ESMTP id 83AB91A0008 for ; Wed, 20 Mar 2024 07:37:50 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=L37WiUcZ; spf=pass (imf19.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=1710920271; 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=7Mms33VJ54sgRp8FnyAenQsmXNJ7i0i74OLC8Z8JYlk=; b=4TU2LPoQtvgUBEWyWIy5f6SbkK+WaSR9UhnuGtKXR7gAebbUxJYgj96bRUSrZM61ploYj9 ENsdl/xK99YLvWxOV9yIqzlZbHP1rfApo4HyHrHtnCHtz3XQlkq1+T9bPJC0vwafaNjJL+ XnNeUfZJ2zax4lrxWgAk8CgD2PfrIjg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710920271; a=rsa-sha256; cv=none; b=cw+TKTCXYt5BNxcqMJoau/eg+PsLD/2+xZMmiqPF4jA5NiQrg8al8yBi+IPUNFSvVGag9l Z3OM9fDTdbD3ZSENDrJKnLg2jWxRst2IfIIFQsth9IMv0ri49jZRaWeB3VcztcULxUqWFx qJ4rZu1jroSuuAQ2P2f7wCpyfq50ocQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=L37WiUcZ; spf=pass (imf19.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 09FD0CE10A3; Wed, 20 Mar 2024 07:37:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52E33C433C7; Wed, 20 Mar 2024 07:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920266; bh=QBm6pSuc3VKXpcso3yJosqmwb8/BJ2OoR9I3H0hBrRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L37WiUcZJsGDbOCHOPrSNTjyO0gSDx/iv+H7FACJLgcKsiZeTGrjxxkD+tePXxwzO WU/+a1n3c+tMsi/tk2O8Gzlwg/FAiUawPXh7x/4BAkeKr8YTmc9fE6ielqPWONuj93 Ww0aiZc8FfLVgEa2KjV3ORGARjUO3JItK016YlNbAU6e2v0Dc/fFd8+ab5keQ7xi8S aS9uwYzTy+ZEcrELKJecDguNV5953wDpPrZ+/U6DcP4heEe6vamrHAOEzr8kP02UQt uwZ1NaS2JnE/kpLYI1IEnYWxb+eaRQHQN5SL64g94xDcd63nVvXdoLNlqfqL8bJDhg mrQj1OmnP2LNQ== 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 03/11] mm/ksm: use a folio in remove_stable_node Date: Wed, 20 Mar 2024 15:40:39 +0800 Message-ID: <20240320074049.4130552-4-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-Stat-Signature: stuibykojabebcyi9doqrsi84w7tso6k X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 83AB91A0008 X-Rspam-User: X-HE-Tag: 1710920270-168445 X-HE-Meta: U2FsdGVkX19THJ/8VF29ZAI60E7eUcdwsQFPsGUioS/ntSYtckIXRAfxmW2yKgpeGN9WIa93+0u7l7CGHJwyPadAK2+3QQLY/+HqyJrXKZxbL19IuBU+m0MwBNfCfqR4LcNclL6bNyP+IQDQfOUJpMHOGAQ2nVz3L6kT5w5Qty+ZNa8qWyqPhrQVTYSy59yXdA04G1MrFFGJFBHiW16N2VHsVFTE0QpKAfXuiY1eFR82gAsZzvGyoz+D5tXOb053A6rAQCAPBDJiwoHJ1dMtYr6FyIOZzbHpyz5DgwmWgciPq7/UebH/zfDktwTGBQbzpCp+p8cLiQVHngOEcZ7LX+D01vCXiarx0LYioZb1+7kXb1NYXVPnA7gKXdAYZOmPR/tpfs5QxdE4u6dwzHX6fo6IO2dBQfkmtMSqjMZHMyl1swUuoiTSon5P3nXiOcgPsxMArQIn+YYYbCfFbDQfSiTdAft6fNRC99iMZ+TEDOVWMYdisK7Fyj2Xx+qWj7LEBOCJGGFSfQU7YgIiWe5JvyLqQWeHbysZVNjh9GbxYWfDrXhlwU8rYJE6BSakf15JG3y6hEo94m3eHdYDuhh2OEvCLuEzbAg4Q5iLp0DznKuM3nyKf2iRWQO4JXdDy4a+73nRINRg71QJ+Va6TkKk/MK1LvRazfEjvALRpqVG+v0JG+vQi4lW9uCyRqKSkmJMBJYZjmfVgRyxxv5wwa5hsssDk4XQWkA3DNsAEF7mxW39Xz+t7B+15D9ATnLZ/8TLKRI7HXcwejsl9XOCm53hipfN8Ypt1jP4SGfPsVEWiNHgU70MuOuuc0XZQiU0tIBV28Zpk2O+xCGsZOXR7YicYeyDHJDVCbHpeRaNCDiWW7cq27R6OunxJLZ7Q+dHmkKJb+rg9Ixn5GNHXIDAUIPxrhv5d3XR/eenNhQpBc3ScLWEMqNMQI7EKcD5DYKarQpyZv8/UIHCZDm/5QjP2kU QkYMK76u IQ7D41XwLX7U/SGxyACfWdiVIq7F5mGYvfF0Kzwu0S1IAoA5Ygv1JTBsA7MDL0p0uxgL9lHNedS3ALLK3zAnccYg87nvHzAzv/WXlj1dOqU9tRD2ifHY01+nI2XuZoDz3SBjIqA88jbraIhvxwnGeahObbIiWR7oAWJq7uoa2NYfWD0ERTJaVjbnc+L6L1BtTQdvBigpuS+KJI6gJGZFqj49wQ7Ax/jb9Jtbk3DGcAZn1kjEKOTTWtq3TIuwmz2N51CuBZ6xtfgBJVUL4MVqp3mCOeMAMHJNgDhtqjxdyXXODZ88J5CvVgf0WYAFTjxOf6oMaE9RZcdbmArECUkGPfj7uHpEDJGyqMZg6gD9ueX3A8bppvdMK3Kk6nB6EJbmJ12rpNWkHwn50nqt2Z3TJfUD5DhlBFe2ZUiVkIV5nlcYCfRvxb/0c4cB8XvQqRn56zFq4uWCJsK3+ZgpRJQuxu3KA00iUSkxg7u5kJ9GpMcmexCEKQGjU8C1YsOyUPpxBtEQn 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, use folios could save 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 --- mm/ksm.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 922e33500875..9ea9b5ac44b4 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1107,11 +1107,11 @@ static inline void set_page_stable_node(struct page *page, */ 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 = get_ksm_page(stable_node, GET_KSM_PAGE_LOCK); + if (!folio) { /* * get_ksm_page did remove_node_from_stable_tree itself. */ @@ -1124,22 +1124,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, + * This folio might be in an LRU cache waiting to be freed, * or it might be PageSwapCache (perhaps under writeback), * or it might have been removed from swapcache a moment ago. */ - set_page_stable_node(page, NULL); + set_page_stable_node(&folio->page, NULL); remove_node_from_stable_tree(stable_node); err = 0; } - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); return err; } From patchwork Wed Mar 20 07:40:40 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: 13597418 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 70E2BC54E67 for ; Wed, 20 Mar 2024 07:37:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E21516B009A; Wed, 20 Mar 2024 03:37:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DAB276B009B; Wed, 20 Mar 2024 03:37:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAEEF6B009C; Wed, 20 Mar 2024 03:37:55 -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 9C65C6B009A for ; Wed, 20 Mar 2024 03:37:55 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6A00D40AB8 for ; Wed, 20 Mar 2024 07:37:55 +0000 (UTC) X-FDA: 81916613310.05.4ED9068 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf26.hostedemail.com (Postfix) with ESMTP id 27E1E14000D for ; Wed, 20 Mar 2024 07:37:52 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YI8Hv6Xm; spf=pass (imf26.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=1710920273; 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=0FazGL3FuTt1mcjMwnjMXTdVvVz5+26grHrof5VpqTc=; b=n+qOMP0u6Ou+ibDIWHBrVxOp52A+P1+o3dfE7aSR84ZPB89oiM6Td7pPzdPqxdlYY11L9t ya6Kkl0nO+8+B228SpSSh6GEdHd2p+11oC0Y9mTic0JmMP32ketILEHOc4adT/1Bw1s7TC 2biJEu9Z7RUhEJWseUiGp8iuHppGwyM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710920273; a=rsa-sha256; cv=none; b=Rlu5ojarNk7+YQjnWJEiTiYkEr1VC5VMYM8ePkZSESRNMeHRZlVCjTVa2SPwWL5SJgY3VV jZHeYvNPHFiQFz2kDbTOTGI/zM2Dw3nuSMC4gAKI+WaujRTdG5F/drfLB/X8Zy0BidW3eF vbHcvd5KGx7J3gpRccyR+Mkf3jQYrQ0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YI8Hv6Xm; spf=pass (imf26.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 31611CE1098; Wed, 20 Mar 2024 07:37:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5001CC43394; Wed, 20 Mar 2024 07:37:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920269; bh=o9GRn+UUdxaobJAptmjj5VgVz5sUBp61iu84lZ36vgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YI8Hv6Xm0jtVWQtKp1cEyat0wmWHkY/j8Kn9DULx7rBhfbctCAntP1sNzBbd/Bgxf GKK43+qd3J6n4vPv1LSUBWx7F0jGccn4GAjoLM7vsPEws0j8wqHcpLDkSqObqPUuVx S00afiEWDkzZAspltpRvm6n9CzWLkZZD+sF6Yv437TNRj14g+lzb+lT9VmbZKVVdi0 S0FJt5H5PXEH4w1WFjdRasWZANKxZgTMKd0TGJwcL18EO4qG0Z+afEB0r2hCI/K5mL QKchWwWwSDnOFXDVHupER88Io9H7AnuzjlMcmemfsbxURM5CC2DJV+0FmKEL2WDgAX 1i5wfHTNMdfWA== 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 04/11] mm/ksm: use folio in stable_node_dup Date: Wed, 20 Mar 2024 15:40:40 +0800 Message-ID: <20240320074049.4130552-5-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: 27E1E14000D X-Rspam-User: X-Stat-Signature: itgxsi3ybwii71jux79i1xbcqsrdwgja X-Rspamd-Server: rspam03 X-HE-Tag: 1710920272-307861 X-HE-Meta: U2FsdGVkX1+ldZdpgUuXufreCUFaQPRPayOVneqcbthtVl7DoMUswgxyF3gxFXilGvT81GD0w9JmoGgfiz0C3g1lFPw6sLUSXUesZp4K3whZWzQ4JHfIJmbkA1QJoC+py7sv0i3kAwDND4esDWwGn5bvAKrnyufvwQK6gRg782weH4gEkrBFVK7ODFZR2nYTJ40B7lQlWeQaKvLVZolUbKNyh6mYbFFLEF8vsy9YmMah7tsVBBRgx/w4apCrrVoYuDytd4iPOSZVC5lJh4TkSlA7tYxZPo2OXAphpOR89bKRO8HVTShBCWHdNxWvFivnBJYyiYOrM9PMYSR8Y5LMZUg+RioOzf9iB5CNREWca8st8FNjh62+VQFA6o4NTWIpGTxfUIjxWmE+l47mw1sTgyshU9JwJlodExZUod5BznyW3Vu9LcBkweBkg4gcWFMsONwTRqnUDiUbzRnc2PlNg1wMT8iFqMM44pPzmG3qluXQj/XCZ87uNLss7KThC018L69zaXSL5hr8PqjOIm2NdoPz7EjS3N0/viZnDCm4e2UfpM0g+fQWEfo9ov5CRNDrC05lh6FyAuVyA6tWqIyRiBMzCWbZiLEwn1E0pTc3PF8l1az4QiUnDNHj/NDb7qummanHDNqc8fG9Yvlfl/7NQIzldPcW0ut5IzHlVMpRiqZnZCyWLFDuzHn2xQjOkOOJW7pJuyZcAAX0ktWpaqjh4BDsMf0GpBDmkvOOpgUgMSoR6IpZkT/6cDMa0Fk8gzDxglH/TqvUIrewkoKn3fyJB7jHtWYnlEzuir0VpWfFzQ+PIx4OcWROJEdlQKIxWuPMype2QNpl4pYc5005pmTCoLq2wIpSFmFedTn9Wqe1uhsuMH6Qn9hcf6qbpQ43Z2jQ1z5+wvk0euNEjfQ35QGHqOSbPYdh4oWTcAXo7GKRCMcteebOs+fqMIBnwSOxBkPrXEElHIbPgefTYKBTP7i AY40h2xS dLLmgMVMF97O7/UGU7tKf0Xouife9qojKFb58E9kBS4aiO+zDkEbSYxgPWh8US/21wWAbe1TrbmA9MQVgJD4dq2U8U0AOrA/x4PL4E1w0WQqLQkjlh1bVi+/kl61TjtTJDzwhRFaNj1Rjpr6lYYW6B6vrPNehHlah34cbGf+ErTl66e19wZi7LuSE57Eyuvfc6QRSsaS5b09hxSjul966QHn6CVWAKdb0HMwMsr4VqUJ35vCBnxUmcMl3+KyhV2mAWQwSQ4yPLeFRO11dZTUxn2YL0b+pc+FDByFQ/2iH2u+HS85RVd6zvPZoKo61RPNJFWLZCOVF+udlB4hxK9o2hnx0PBkJvGpF81gUuLjFSAqilpLzi4acXvkcjvwxrRZisSOMzhj1FlJh9gYIVxf7muR3LEbLFQjTejE1jPXWV13MThejklrzYeZgfZauvZTKZ+XfdTYBBfA+QbGm7ebo2OPvvEgf2jfHkjBjRqZkg2cMjvEMRWDZgQd1ue9lgMbsbJ4e 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)" 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 9ea9b5ac44b4..f57817ef75bf 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1617,14 +1617,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; @@ -1649,18 +1649,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 = get_ksm_page(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) @@ -1668,7 +1668,7 @@ static struct page *stable_node_dup(struct ksm_stable_node **_stable_node_dup, continue; } } - put_page(_tree_page); + folio_put(folio); } if (found) { @@ -1733,7 +1733,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, From patchwork Wed Mar 20 07:40:41 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: 13597419 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 19728C54E58 for ; Wed, 20 Mar 2024 07:37:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DAB76B009C; Wed, 20 Mar 2024 03:37:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98B156B009D; Wed, 20 Mar 2024 03:37:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 806466B009E; Wed, 20 Mar 2024 03:37:58 -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 6C2D16B009C for ; Wed, 20 Mar 2024 03:37:58 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2E710A17C9 for ; Wed, 20 Mar 2024 07:37:58 +0000 (UTC) X-FDA: 81916613436.18.1B8407D Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf29.hostedemail.com (Postfix) with ESMTP id 31319120002 for ; Wed, 20 Mar 2024 07:37:55 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gcdYDTwN; spf=pass (imf29.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=1710920276; 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=S51xzmjoRElqeNHM40zu12N4nDJ3bCoHpH+pG2n/2a8=; b=580RKEviS5TaKbF+sxuagvfxMafmuk0mnw0wyV3nW+QDDO+8YcxFN3qmzirPiF9x8WfycM pgc9wm9tFCYZq1e9TVmV2r+DFxuy8uKnY9qGcso9fpQoJsD8TCrwpBRlyZ7GdufM53Ahed 4f8+sRr4S5ps4poX7FBZ5ho/uTQl6lM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710920276; a=rsa-sha256; cv=none; b=jTQrqzvnCP1hVM9OcNdk8XXi333QsA/DIneviRCUBmoqJ7qCxQU71SYs0AzX+eG3KUeBYa g9+/m7pFe0nu+Alr+yK11DgNilEE4bcDwQ4t0TBpEQwd2fiIqPrxZg7LHdH+JiiceE3EPQ HFUqkeMZ9s+tn5kPGzsUL/kY2n5mxBU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gcdYDTwN; spf=pass (imf29.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 8CCDECE1084; Wed, 20 Mar 2024 07:37:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 783FCC433C7; Wed, 20 Mar 2024 07:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920272; bh=4seeVX6AVPqZd4ygjF/loS0RJCIz9ENpBZHyDB1ONgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gcdYDTwNpPfOraYNtauQXzItCR4li8hYgUl6TNOp70HPLvjFG2OMzp63eiaHDkVJ4 lAQiNnL/FmDu2tGeykqradjGyyPa/riMOWFVA50dZoE5tjUOTyTWCivB0NUf4ZrLoA fXk6NuuqeTNyJVVuuLSoY8a7zoorFJ5HM06+E122HCv7C62/d67TiJISYDBBqXDASw MyCoEdgzJzMC+EVEbqI/DyO6j+yzlTpQeGAoyL3VrfpBmRCXr9VJmd7L4M3Yb+ZcXW NTgWZ7emrvaOYBFaEKJBAgDvaiqJPYAimCIhBECxGHQ31uddId4Ou16GQwAim0Vl+N vt2YiIJwwpK0w== 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 05/11] mm/ksm: use a folio in scan_get_next_rmap_item func Date: Wed, 20 Mar 2024 15:40:41 +0800 Message-ID: <20240320074049.4130552-6-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: 31319120002 X-Rspam-User: X-Stat-Signature: 9en1ccem8o7wzbhjq3qwwwgnsgr8p87a X-Rspamd-Server: rspam03 X-HE-Tag: 1710920275-398447 X-HE-Meta: U2FsdGVkX1/HjYqNf2+38IvLYFFfMxf2V2QHX+g/lekc3Nxi+an7SbnVy0JF1A47kLohOXxblvJBiJiWCxIqFS8/qqXIGy6NwmWoECqCcoTamhPyVzvNWN6EH1O8a1vxQAL58dN700jOtUUDv0U+F7qWemWpBnmIcmWeK/hUsMNXureu8xfIsALXSxpn7uzlGRQCFTVKBSYc0IfvgHCMZCFbroy5DYAanpDX9B/RZLtjzlR4+8O7PhCv5nBMHsWJySOjGCag26WmYECqXN9m7706iHXDwmg7eoAYdqEjNq17HjcHonXooplZnwn8QO/XTuAhPvOB2tEvt57LtQwHIrOeQQ8Af5EHA9tyP1tEwp6USF6HEPkgpSXMGqDg0tGRz5SxBlKfbO2JqvJppxAp5/ZMzvnX95fHB0ywQiMphq6eBy9ZZC7LvydjSlA+6w2WGfh7KJtxuHOP3okTo4rHM3KHtQnJ+oCtIi4pK6eIR9RhJ5rtseG360WFALsJ6FJkhRt5YFjHIU8YRegcTu8INyJUjOKZnTnRhop35T2y+IWqAZJabCsjyrAe62ADoWd2s9MaFpwlnAEnkDpOd+wfqTQzVd4H/hvIeBXibdjcCKUn6AxBwgK9YmYHwKEeR1FMyDNlPaoZD6G9e1kHpImiNE4SqFkODTvZQ3s6OoEmroBhoIH1SEi3Q9AZkWpYTZBWrMlf8YnOhxTiSSEg7MBSfPArTSUyrfaxKRV5kN8zWVYf3va3ye0uXukKFqGBXyMk5dkM8CkeeIDgPUBsXOINRm1ue1NFox3BRMcbi+pOmvxnmDYBAXF01GCiCtr4TEuhbC6D8bHyRQ+XFTYfKK5xxSDovtISAzBBTgXOmINmHu6ztvU3uCuhanxvAMoWoBAR2NCkXPxOoJWTgSPjGU0S9Cikv2PcKtNjcxowj8iEnCHvg+OJ828Suupv5ph1XirQd3EaNsaXIbENkdVG0zM FrpWgm47 t8j/x/p9gr1tYBHhIthnI/X7P8oUxsFguBfHDPn0fOlslYx/G301NtIqT3MM7CqVf+M6/Zc/qvo/oap4uhKxswg/Wfc7AE/c1QKciwab+NMWP5jlNJYkZz3czoSHrP7+G53NU0TuDna2jdQmMBfmq7vApeKOfkfKXWtE8HSQ1POcfq8Vwi2wE5VBajv4AxwOdVZN15TJoGJKpTgWQSIY9Zp2dCS6+50LvCTIc0Kc+c92C08000bZg51LMl6VrSqjcJy/0x322NBZo9KP+dDmSRm1vDz114YFy9HSem8mM8rPVQd51JdON7ochAg56YpaLK3PRW6LA3zxqd31vkxdrtu1e1fAg+wiYmW8BgPy4fuogXCZa2R6FyfL1V6xss5FyuRc0FVdwOlrjUSlu3QinDEp+80yRNI1Cmfjc0ICcyf7axPW8O970aBbk0Yt5bvMnSFdvdcUZFk+03zLp6CpXXwjZtvZ1ufPeL5ssm8811Yo2fNqlyZs1gpgiNPVhq5PxT0vi 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)" Save a compound 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index f57817ef75bf..165a3e4162bf 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2597,14 +2597,14 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) */ if (!ksm_merge_across_nodes) { struct ksm_stable_node *stable_node, *next; - struct page *page; + struct folio *folio; list_for_each_entry_safe(stable_node, next, &migrate_nodes, list) { - page = get_ksm_page(stable_node, + folio = get_ksm_page(stable_node, GET_KSM_PAGE_NOLOCK); - if (page) - put_page(page); + if (folio) + folio_put(folio); cond_resched(); } } From patchwork Wed Mar 20 07:40:42 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: 13597420 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 2E28DC54E67 for ; Wed, 20 Mar 2024 07:38:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9F7E6B009D; Wed, 20 Mar 2024 03:38:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A27136B009E; Wed, 20 Mar 2024 03:38:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A18C6B009F; Wed, 20 Mar 2024 03:38:01 -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 6F20D6B009D for ; Wed, 20 Mar 2024 03:38:01 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 475A1120351 for ; Wed, 20 Mar 2024 07:38:01 +0000 (UTC) X-FDA: 81916613562.03.ABEB6C0 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf11.hostedemail.com (Postfix) with ESMTP id 3EE8840015 for ; Wed, 20 Mar 2024 07:37:58 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kDzTtQlW; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.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=1710920279; 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=6OGvgHX/9Iv74u35Uk/YlQ0Iz4C2uQ3pGHId60/YHtU=; b=ugeDx/1zXaoHDr8BEBtHcr8HOcsxMVo/TRHYpMwnTYzhEOkuJ8+XY1ZIIx5YVH22qiDt2m cyt5UC0jyZi4OlBk92ibSNqbtiBSt86nIIpHoaMztqcSCB06cGc+qT8ys0wsn+YUCdLipg D6aPrwCT/Lgwiw8xcSiwMKpbnvDMpqc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kDzTtQlW; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.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=1710920279; a=rsa-sha256; cv=none; b=OY5+qWA7bJHc2TI02LrUe/Hgjy1eo2HIwpyprjg3zoMkbeTVDDTyiKpbl8wza0f5Cosz4N ZnbPLBLfCl+NBm/8kPCsIsauxWWOw8ffXjPr+HW36jDa1exfUxO1/dmBoqyDjf0FfAY0tI IeNpckbGv/9LyJbguSopUUFF7ZnK/a4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 59803CE10AF; Wed, 20 Mar 2024 07:37:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 778E8C433F1; Wed, 20 Mar 2024 07:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920276; bh=19yPEARCpp8Ts03v7RxMxCBtzle77h5p1XW4PvUaw5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kDzTtQlW47rs4jpnYM++UgOMgMjc6JVlGxhM/IaBtklgkLeG6r4Tnxl1Xk+XlC8O/ KQHON/2ylQa9Yuyx0B8AKyEW5/TRrTxN4xBejiHEVqucOuTU7IwSba7JJ+kXWreOOF R4+4Zyn9/Nev/5bFVVQ4UkccMEbHgMbDM6uTF739A2wUe83+/7uDOexjTk7NkSdnO7 dcnb3ZAD1eZm7Vkx6yt8emCSnB7fcs+Nq9lIWGKaeEwRTnfw1B+r3bex6R9HSkNFbI s/2hdV/dzXTTLvLx7rtB70nOF7m9hfqY35R7h5eY35GCu8RyZf6Qj9ygfbX6Qednoz MHs21FcRRCPOQ== 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 06/11] mm/ksm: use folio in write_protect_page Date: Wed, 20 Mar 2024 15:40:42 +0800 Message-ID: <20240320074049.4130552-7-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: tj7wm96rend9m397jhm7sas4cc4qzzxy X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3EE8840015 X-HE-Tag: 1710920278-117759 X-HE-Meta: U2FsdGVkX1/qpd9w9t+pD8vQUkU19wugoqRMy7b28JsMXDalOW2xechDlriYYGQHdI4v15EdYa6bJJ6GvV3lvvXmkfS1q8VctxYomUuwuip9ltnECiSOdSrvCRiWK8/LHDgqq2nzqnvmitdSVile9wTglade28q5sJhsUv2+qE8690Rh/MCeySgZ9nNNcX/df0uHlbHNXqhFJYaRGZQ8MN/h1P3bfcPJ+YcfFMzQZe2Rin4wa9PzJi0NoUAOkqDgLwIOQ1ipwQ7ig3B37dvT47d3nTJJRM4EjVm2DcGoo8+DyLrtaKL52KMynq4ecGKLZpuKMjZ0LELTrzUVIjc2v4IKFM0B7Nl8CUeSq1MC1RsLs33WWEbU3Rv+rLTz65KZxAOC2pcNURb3+Xkh5W1gkxtwaP7fjJbspSGrdC777mz6e2bUVkpk9yrgWwoNW/Ztxdp539O2ziZsgKEo9M6lfK9fMsIBWVfTSql8c9t4ylKpzuWCskR3N8jX/NQbeDSleklOxg3PEPtZsqDpfyszgsV0qe1tn3Dv+7dWgzislFE1tdrPev+HOis8TEz2vt1URJUC217BSdDwcoHqUWrKmHCD26Gyc2uWpsq7oA6/Lv5/xjvwqVbu6+Ti2F3BW88v2aUaYtU8JC2t4G+KbgOc/w+oDFGmniJzB6dSAhLCshB/BdxA+dl2cq70z6TBjRbU63eSiJ4TRaX/irUwAfr0k8CK9a0KAnRrAqvT5BTtdjMyWMDYcu1DXM1RwKy8S/WOu6/0hk8ekHBlPEv60h5y/OTVghMJXZFxC9TY9taNVhwPw2rZm1x5b4+10cID6mA6YQcIRYNlETAu9EF2SvKdFBlFq+tiP2A9rC7M1CC6thmR1f1pM7njCQkM5N5aUEL7MS2VbAt7ScY1vtueQSqFpsDgrg6F2Zbsj7WQZKvsq2JNjtzIDOY4RvsyWbcz7rxmJObYk4JXm83bsLlVIyC 28PH0VOW AN0m9 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)" Compound page is checked and skipped before write_protect_page() called, use folio to save few compound_head checking and also remove duplicated compound checking again in the func. 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, 10 insertions(+), 12 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 165a3e4162bf..ad3a0294a2ec 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1275,23 +1275,21 @@ static u32 calc_checksum(struct page *page) return checksum; } -static int write_protect_page(struct vm_area_struct *vma, struct page *page, +static int write_protect_page(struct vm_area_struct *vma, struct folio *folio, pte_t *orig_pte) { struct mm_struct *mm = vma->vm_mm; - DEFINE_PAGE_VMA_WALK(pvmw, page, vma, 0, 0); + DEFINE_PAGE_VMA_WALK(pvmw, &folio->page, vma, 0, 0); int swapped; int err = -EFAULT; struct mmu_notifier_range range; bool anon_exclusive; pte_t entry; - pvmw.address = page_address_in_vma(page, vma); + pvmw.address = page_address_in_vma(&folio->page, vma); if (pvmw.address == -EFAULT) goto out; - BUG_ON(PageTransCompound(page)); - mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, pvmw.address, pvmw.address + PAGE_SIZE); mmu_notifier_invalidate_range_start(&range); @@ -1301,12 +1299,12 @@ static int write_protect_page(struct vm_area_struct *vma, struct page *page, if (WARN_ONCE(!pvmw.pte, "Unexpected PMD mapping?")) goto out_unlock; - anon_exclusive = PageAnonExclusive(page); + anon_exclusive = PageAnonExclusive(&folio->page); entry = ptep_get(pvmw.pte); if (pte_write(entry) || pte_dirty(entry) || anon_exclusive || mm_tlb_flush_pending(mm)) { - swapped = PageSwapCache(page); - flush_cache_page(vma, pvmw.address, page_to_pfn(page)); + swapped = folio_test_swapcache(folio); + flush_cache_page(vma, pvmw.address, folio_pfn(folio)); /* * Ok this is tricky, when get_user_pages_fast() run it doesn't * take any lock, therefore the check that we are going to make @@ -1326,20 +1324,20 @@ static int write_protect_page(struct vm_area_struct *vma, struct page *page, * Check that no O_DIRECT or similar I/O is in progress on the * page */ - if (page_mapcount(page) + 1 + swapped != page_count(page)) { + if (folio_mapcount(folio) + 1 + swapped != folio_ref_count(folio)) { set_pte_at(mm, pvmw.address, pvmw.pte, entry); goto out_unlock; } /* See folio_try_share_anon_rmap_pte(): clear PTE first. */ if (anon_exclusive && - folio_try_share_anon_rmap_pte(page_folio(page), page)) { + folio_try_share_anon_rmap_pte(folio, &folio->page)) { set_pte_at(mm, pvmw.address, pvmw.pte, entry); goto out_unlock; } if (pte_dirty(entry)) - set_page_dirty(page); + folio_mark_dirty(folio); entry = pte_mkclean(entry); if (pte_write(entry)) @@ -1505,7 +1503,7 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, * ptes are necessarily already write-protected. But in either * case, we need to lock and check page_count is not raised. */ - if (write_protect_page(vma, page, &orig_pte) == 0) { + if (write_protect_page(vma, (struct folio *)page, &orig_pte) == 0) { if (!kpage) { /* * While we hold page lock, upgrade page from From patchwork Wed Mar 20 07:40:43 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: 13597421 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 8C287C54E58 for ; Wed, 20 Mar 2024 07:38:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C26296B007B; Wed, 20 Mar 2024 03:38:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD66C6B009F; Wed, 20 Mar 2024 03:38:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A75A46B00A0; Wed, 20 Mar 2024 03:38:03 -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 94F986B007B for ; Wed, 20 Mar 2024 03:38:03 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 74D77A1569 for ; Wed, 20 Mar 2024 07:38:02 +0000 (UTC) X-FDA: 81916613604.29.5793178 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf29.hostedemail.com (Postfix) with ESMTP id 6D162120014 for ; Wed, 20 Mar 2024 07:38:00 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lhCa2Ax5; spf=pass (imf29.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=1710920280; 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=bZRLc1zIpAsHLe3qAuELxC9pbVO96Bp7szB4EtEAC0g=; b=V1RNl2rMIczV1gggKXeqaB0Q5OT+25VsD4EUkF17yvj5L+SNb67K/YawIZ0Zeq0rsrnhzW rbnyEidXPeQCr1LyO/RuL1Agj/6i0nUhZwbgzyCnvXmtOBVZdJhypj6jSTbBcHVUVwpqcm 1mBb5bBHYcR1nhy05FPEYPk171fghSM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710920280; a=rsa-sha256; cv=none; b=1B/58CquaKse1SU7S43Fu5jz7ezqHSXtKXpgH/rfzQhKiycRu8Aft8fBrEdX9FXqfZY+Em PpliZjCBe7ZsNvpGUoffi7rfrM9jLLxu29avm6F05i2ixWNLlE9FkYgQaE9FwQIwUilb7R IUjHtIdb7qVJAaGlBlwg2+4nI4CJ1CQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lhCa2Ax5; spf=pass (imf29.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 7EE02CE10B3; Wed, 20 Mar 2024 07:37:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CD8FC433A6; Wed, 20 Mar 2024 07:37:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920279; bh=1ed6BHhGoxgGo7EGuh+4C4k7rhnha86RpFOxOMhqKzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lhCa2Ax5ueUSpXQj0Ttzhxb1k/1JVJoGcXSZZKbOYPU0aS/96v+eP5ke/tSy7N662 6DPmG+505PRZFGCUnmZSCvPx3WlBVs1RRA0XcpitnGkrM4XpfG2+lYZchImhrASWGO EcWQvcNxlf6/hHiuh7IQY1B9Ic3LnWLnJ1jLpMPMW2/8EzOLrr2wPG/KRvzYgT9yHn CpugyVk7CXv2ky9jyU8gzOp79le3M7KmVcTXdeeeBhTuDBXOVcTN2YtpAL+FUBdK0T PdRNe9PQZwHr24y72ln6sr4/2fihO/p3mT3hoZdMOUfNrybuYUqoerKx9wGy2IoKy0 Y13qi1nGB8Gbw== 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 07/11] mm/ksm: Convert chain series funcs to use folio Date: Wed, 20 Mar 2024 15:40:43 +0800 Message-ID: <20240320074049.4130552-8-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: 6D162120014 X-Rspam-User: X-Stat-Signature: cibuzsf5ikgnqkqh8xgqe1od5dsmadmo X-Rspamd-Server: rspam03 X-HE-Tag: 1710920280-336423 X-HE-Meta: U2FsdGVkX19wQfYiFU+0g4GVPjLm0QpT8hx6W7DYS2hpz8PDrXKI+NHthwfizhyvO7SSNKDMXXP9HDg+zYBUcP0CxHO5X6YIDAp7efHAu27j7EpIfSz6QGc/WBwaJiqM2E2GFe6zWMnx/isx0QUgaOcJVyoYuGOcBVp5979wF2eU0W6/fYM1oJiUd2S/Dlcz95Uxr2D3kKCjyAnTULHvcOQs04z5HSZyNhOm8T7bYwKScEP6nqIn18GwCMTt0zFZbpxxIOQiYXYpEiOZ2elSkeD2BWtKSmxCHF+ZQ8twERNdhfKgHnmpOSetvia1Tz76n3RKKZUY63z12ZfpC16oNOVblSUV2F80HGyfytbMPvhO/wbfFvHE3gmeyYT5vZ06GpOl+ICMAypqVW/D19xaZbk8cEf0P3aBPbIe14csC/t3hYcfOWT1NIedn2TT6/SKoif8Z8ZsbcMssAExwdmIvyuQCmJ2xv+aWnXiqqWAw3SoP3Eka5hAUUbdAsX4jD8eXjPY5/EaGL1K9VVSej31MLl+V290vw+O+yZqS6EmbxDyg2FgGYM/pIRgmtZhqcgNZ6TcVoVUmMbnSWQ3OjBDhW7tV44Re9jAz3UQeJYQTbR0QCW8/TlGI0ZBF6ug6cWjije9Vg6YclCBMo/72jbT8qSbE07jTkShHuxZmOBsI4JVtHMXg/Kxj2tH2fqOap6OWUBn7j+kVBz7bVlRsvUDZzFVwZmWf/QSEPt/Tw6lTxFdjJTNDnwoOEweMnU4wmyXzjjE6++weITDuqZBX4CbT7iiZhOJh4AeNFHunEQPHXwOV2cedosMmVdz+fuOYy29mRLTbZqEG5WMgE2TaTXrMy/Ys+7Oo9KSBFbrqxT3avziDCcxLJ5n51PM9rUBhuXY2Ysd9YK124zQm2OU3MWRRLcADvfD2B8p1k9BF2S2FuCUNfnnZ7dStKV9fKxh3j365giX+Zhf9bYuxEuUUOf kvvi6BaN eMtIJPXwenq4Uhsel12iHrFIWuiulud7VVTMndTRRoqX47roNMsQSbrXNPTf9Y0WjlzgTFrzi3s+ty0rhKv9qifxy3T0gFK+YEl7QNNERVwyJDQCOR4XmIJedP/cFAW1bM/fxnffYRgNV2PQCXNKsb3WG0c3m3DRu7WoKNPKnC1kUpWPUCp0t2rRZQm3lanfZNbjEZyzVaRhLB4qUy9MMuNL3T8NpUCk8q99boMSZTOjxjStKJBVE+ghlU6rWk0d5tRO/+6QSFf85Y7IR9Ial/vjvSWV/V8FHdb0oWCWkMFbqR8b6VeDlQadEfzV2vb1YVfN28cvrSWIKDZNszuEt32l30qGYudXCSILYYnvl8PzzY4yJIleLdG+JS4VmMDwOy68uMID6LfcHDQYKr8z2maEbhtTz0CG2iQOHM5gp8Ti8cuUNQf17NTKg/Eg/S+zn4que5Vbh8Zi+TMU= 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)" In ksm stable tree all page are single, let's convert them to use folios. Signed-off-by: Alex Shi (tencent) Cc: Izik Eidus Cc: Matthew Wilcox Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Chris Wright --- mm/ksm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index ad3a0294a2ec..648fa695424b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1761,7 +1761,7 @@ static struct ksm_stable_node *stable_node_dup_any(struct ksm_stable_node *stabl * function and will be overwritten in all cases, the caller doesn't * need to initialize it. */ -static struct page *__stable_node_chain(struct ksm_stable_node **_stable_node_dup, +static void *__stable_node_chain(struct ksm_stable_node **_stable_node_dup, struct ksm_stable_node **_stable_node, struct rb_root *root, bool prune_stale_stable_nodes) @@ -1783,24 +1783,24 @@ static struct page *__stable_node_chain(struct ksm_stable_node **_stable_node_du prune_stale_stable_nodes); } -static __always_inline struct page *chain_prune(struct ksm_stable_node **s_n_d, +static __always_inline void *chain_prune(struct ksm_stable_node **s_n_d, struct ksm_stable_node **s_n, struct rb_root *root) { return __stable_node_chain(s_n_d, s_n, root, true); } -static __always_inline struct page *chain(struct ksm_stable_node **s_n_d, +static __always_inline void *chain(struct ksm_stable_node **s_n_d, struct ksm_stable_node *s_n, struct rb_root *root) { struct ksm_stable_node *old_stable_node = s_n; - struct page *tree_page; + struct folio *tree_folio; - tree_page = __stable_node_chain(s_n_d, &s_n, root, false); + tree_folio = __stable_node_chain(s_n_d, &s_n, root, false); /* not pruning dups so s_n cannot have changed */ VM_BUG_ON(s_n != old_stable_node); - return tree_page; + return tree_folio; } /* 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+EqdrcyCCM1P9sCueO0n1bjtp/wEt2JsMZK0MWgGe1lvYxsz4CaH0ZuXHoC8d5rDF9T3tfiS4imyCUrM3xLZGUlJjPhNHju9xlPt/2egulFsPPxWr3gs739j8DyXpwvWtzI9wVTVAvAjQC8wRPITnFzjk05yF7UsWV/PmmOUCGtf7IKqHdjuexC7i7bDTRzhCHsFJKwf7LxHcOyEEgw6ACu8OBwGprZFcVHWd4BbbnwfyvHFQoCHHo1nHmnrn08X201pLZKS6AHtmm9qnEnZnugPOEbZ5vF9k7PEA/OlmfztGGr2ial3+jEIVY/Acu25eu4F+Q9LTJWoIxy50OB8M3e/iojG46EJzLXfBc2rYpRs1E6Mt+XqFwVNIEw4kh/gDNqla8WE1B+S1vrmodoAWmC6bGdzXfVcPDSNMOclbO9Z414CKwuhhnyS0cSzqP23HpuFqA/GwFigZsvwUx99X/f0/1YivISJW6xnQaHZ8exoAopmXRrhd0entubXYxVyIUQf3TnQ+a46MxDSmmv2A7kAvEF7oXd6D3rfrYIBoKEpP38KzRQIXReTb8jRfDkndTCpKGbeCdsu2D9+st+qSPACH7fYECeexubzBZY6QdOLp8Y5lN2FiCARlQo7iJvmVmAJ8kHwC9mdDQ5kfysIfNMgFy8Ug+i8OBxcmizSIVZODf7zxV4sRcMKui46bA8zBSRNo meYW75qS 1Q9X5t/nnRQvovk8FU9zGP+RWmkeVbfPJFBnHZNIEx+o/ze9qFtYaStq6t08gb/QnC7TsSXUT8zkgfzgutfJs+VXRri0MvpGTCm8PmyQA5Y3+1uLzy1mSFc/xuMBUrhs/RtgzBDEskNp/keGLxOvlk2eZSBEOlK2rw4rTBbbO126/shJGm1OrSNpbyxaLTp0lXN18QskSOamzHa53SH4BXzX+qD3/Hh3914qsEBycPvlAIevUyoBphDwSvFMXWBHnK5F/RplhDcVM+kauu0fe9Zz8WKkFPmPqRMymeCcSdosrWJha13Rb4842KBiJhZhbQ/lZOpuUXk1z2bBBKQ9R8ayhZu4Gd11XXdTANP45PvmjVdcc4Jq2jxhI8j/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); From patchwork Wed Mar 20 07:40:45 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: 13597423 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 7B1FCC54E67 for ; Wed, 20 Mar 2024 07:38:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 102358D0002; Wed, 20 Mar 2024 03:38:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B1396B00A5; Wed, 20 Mar 2024 03:38:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E96E38D0002; Wed, 20 Mar 2024 03:38:13 -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 DA6AD6B00A4 for ; Wed, 20 Mar 2024 03:38:13 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AE4741C0EAF for ; Wed, 20 Mar 2024 07:38:13 +0000 (UTC) X-FDA: 81916614066.25.35603F8 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf17.hostedemail.com (Postfix) with ESMTP id 7E3AD4000A for ; Wed, 20 Mar 2024 07:38:11 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QnyMHcy7; spf=pass (imf17.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=1710920292; 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=EfnUB+zh6Jkuo8KxC5rPnusQaj/Ro7vi77DeDl1FMzg=; b=drD3w/W4muRlzd3+yeHeySN4dm1oZXp7CRX/jxfE+xHupc4eavmi+/XFGtzQTiwp82N/XA +7KORpfoLMGIh7/hFLKuI9/V1OraswWHZvz3tnrQYW2WgqwGNWDbIVb3xIcQID0MmzKriS 6uOKotWe0K7R8GiAPJ/lAs3lN1rK8FE= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QnyMHcy7; spf=pass (imf17.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=1710920292; a=rsa-sha256; cv=none; b=CPujvBNFXX1tEryIvRkSWSD0d6EB6jtQ33OaFXXgDkMzwv8T1RwxR0FZB16EHBnqXYuMoU BVRJjQjPs722kWjAZGpE4K1afD8atbZexd/OGML2Gi8indYvqVZ+q/xnH8LsRlyARZCI1B jilLy5JkmvtgflOjiQo9GKXI/7XVf1g= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id D79C2CE109F; Wed, 20 Mar 2024 07:38:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F12D5C43390; Wed, 20 Mar 2024 07:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920285; bh=tjVPu2LfV6/oJL+/cGFCPeE7wstp4Ud62/5nB+tu7Fo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QnyMHcy70fzp8mjnSBi4o1+7TO69JWuiRoHjNyhFVoYTtNUcOygYYs1aYzSwHZ4tP B1BEQoxvGpCI5WgyIKpDPphqywUn0C0GwKZ9osVoCfI7FwSszybl7JM+X7kspzNj1U ZaUyDOXUqJMrYPlAP3tjgfC0glaUofbiUSDuv3ZHGJJXB3urIxTdY8dqSOJpLF7Q4J +0xpRLKV7XWf7OvDi6wMx13J5ewLV5vUggPB+1o1apGUrBvZIVUI7PM1LA3+YdCGy4 16PM0s7aJeQoqB4eV7jgHGwGxedDMFcl/prNrGkefrYvjHT9OTNC9gi84ELn/jrimA l05LCkNlt1caA== 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 09/11] mm/ksm: Convert stable_tree_search to use folio Date: Wed, 20 Mar 2024 15:40:45 +0800 Message-ID: <20240320074049.4130552-10-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: 7E3AD4000A X-Rspam-User: X-Stat-Signature: e3qb1gzi9o6fedn9x3wkapz5a8h9et3h X-Rspamd-Server: rspam01 X-HE-Tag: 1710920291-288500 X-HE-Meta: U2FsdGVkX19H6D9GdabaxWqzn1UjJ37paX1Z/yrH+uU5AtJYv0/4mlPXypeOykX6HMifPZJgr4Edq62+1/V72+pHxG4Soothh9+SRwboDNvcTIMbwRI6GLXIS7R7NfxLzt4cA87KUzHPXJjpwzt4XiWvgh6Yq1J6ZrgNhz7/bZorCxS8pFxM/uOqHK7sTdeX7WjmK211j0JhA8Q1S36TCiN5tZxGcxm55nDKW3do1di4CnifP8BIq3L57XdnBQrqpv36Wjv8pbOEEVUJI/GxTW3/9uiSq7yoTAxvo6C23FYRvVIlWetkY59z8pIW2VInNGf0C2hirDEjOA0wi3xucxzcTFrUMHG/vrIZiJzPKWxcXDFUOZhSJCIZkbFmILgKrmGrxkn7M7a6VZXPmRIcr76xepD4uvOaKNRGfvrGjEyyDY7AZn5yV70cXU+ub1uOruWK029UpCV/SK7U4AXUTYMpZ/zcS8nbqw0skZnB0z4Qg7B5Nsum3u3iO2UxTU2P4eTWOIBQbf+bauqE+D+k+L4Pl5dXSMTU5v6WPRJ4hft6arzqMhCMdRh1EAObYs/HbdfegOVCOIUZx07EpTdZEa5P2jaYHnsQJHlKo0uIVCV6g9qH87sdVDM2828CSC09A0ZVZrnszBjO0kuPqs4/A9AP5a88m3Rk3rk28gIJ2t4BnMGwMrv6fwI00e+yj4ImLJKUCFkSQ7fH/pmVxlQYg4+1WehpuWKtCegFgqyaQqap8CA6YeYicNosnZy6RPOhsGkvjou8ZgqhOjU2ABjAeGCb8pxfLGq5F7htXMnDswEe249lWRRSaaNF1nezRSqqPAzpU1Jq8yj1/mJ3ty6khbpMKX4f2lEFp/z/8q5INvijDPODABcdRWDTpJjquMZZLelSDM2ue1eicIgfA467ePtbbvu58LNeGoMUwlv8tpsv/xywcQ7wEM/yJjbMas1octs8+mQ76KXH0soo379 JQxw5jc2 V+WC8 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)" Although, the func may pass a tail page to check its contents, but only single page exist in KSM stable tree, so we still can use folio in stable_tree_search() to save a 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 | 60 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 71d1a52f344d..75401b3bae5c 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1812,7 +1812,7 @@ static __always_inline void *chain(struct ksm_stable_node **s_n_d, * This function returns the stable tree node of identical content if found, * NULL otherwise. */ -static struct page *stable_tree_search(struct page *page) +static void *stable_tree_search(struct page *page) { int nid; struct rb_root *root; @@ -1820,28 +1820,30 @@ static struct page *stable_tree_search(struct page *page) struct rb_node *parent; struct ksm_stable_node *stable_node, *stable_node_dup, *stable_node_any; struct ksm_stable_node *page_node; + struct folio *folio; - page_node = page_stable_node(page); + folio = (struct folio *)page; + page_node = folio_stable_node(folio); if (page_node && page_node->head != &migrate_nodes) { /* ksm page forked */ - get_page(page); - return page; + folio_get(folio); + return folio; } - nid = get_kpfn_nid(page_to_pfn(page)); + nid = get_kpfn_nid(folio_pfn(folio)); root = root_stable_tree + nid; again: new = &root->rb_node; parent = NULL; 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_prune(&stable_node_dup, &stable_node, root); + tree_folio = chain_prune(&stable_node_dup, &stable_node, root); /* * NOTE: stable_node may have been freed by * chain_prune() if the returned stable_node_dup is @@ -1875,11 +1877,11 @@ static struct page *stable_tree_search(struct page *page) * write protected at all times. Any will work * fine to continue the walk. */ - tree_page = get_ksm_page(stable_node_any, - GET_KSM_PAGE_NOLOCK); + 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 @@ -1892,8 +1894,8 @@ static struct page *stable_tree_search(struct page *page) goto again; } - ret = memcmp_pages(page, tree_page); - put_page(tree_page); + ret = memcmp_pages(&folio->page, &tree_folio->page); + folio_put(tree_folio); parent = *new; if (ret < 0) @@ -1936,26 +1938,26 @@ static struct page *stable_tree_search(struct page *page) * It would be more elegant to return stable_node * than kpage, but that involves more changes. */ - tree_page = get_ksm_page(stable_node_dup, - GET_KSM_PAGE_TRYLOCK); + tree_folio = get_ksm_page(stable_node_dup, + GET_KSM_PAGE_TRYLOCK); - if (PTR_ERR(tree_page) == -EBUSY) + if (PTR_ERR(tree_folio) == -EBUSY) return ERR_PTR(-EBUSY); - if (unlikely(!tree_page)) + if (unlikely(!tree_folio)) /* * The tree may have been rebalanced, * so re-evaluate parent and new. */ goto again; - unlock_page(tree_page); + folio_unlock(tree_folio); if (get_kpfn_nid(stable_node_dup->kpfn) != NUMA(stable_node_dup->nid)) { - put_page(tree_page); + folio_put(tree_folio); goto replace; } - return tree_page; + return tree_folio; } } @@ -1968,8 +1970,8 @@ static struct page *stable_tree_search(struct page *page) rb_insert_color(&page_node->node, root); out: if (is_page_sharing_candidate(page_node)) { - get_page(page); - return page; + folio_get(folio); + return folio; } else return NULL; @@ -1994,12 +1996,12 @@ static struct page *stable_tree_search(struct page *page) &page_node->node, root); if (is_page_sharing_candidate(page_node)) - get_page(page); + folio_get(folio); else - page = NULL; + folio = NULL; } else { rb_erase(&stable_node_dup->node, root); - page = NULL; + folio = NULL; } } else { VM_BUG_ON(!is_stable_node_chain(stable_node)); @@ -2010,16 +2012,16 @@ static struct page *stable_tree_search(struct page *page) DO_NUMA(page_node->nid = nid); stable_node_chain_add_dup(page_node, stable_node); if (is_page_sharing_candidate(page_node)) - get_page(page); + folio_get(folio); else - page = NULL; + folio = NULL; } else { - page = NULL; + folio = NULL; } } stable_node_dup->head = &migrate_nodes; list_add(&stable_node_dup->list, stable_node_dup->head); - return page; + return folio; chain_append: /* stable_node_dup could be null if it reached the limit */ @@ -2109,7 +2111,7 @@ static struct ksm_stable_node *stable_tree_insert(struct folio *kfolio) * fine to continue the walk. */ tree_folio = get_ksm_page(stable_node_any, - GET_KSM_PAGE_NOLOCK); + GET_KSM_PAGE_NOLOCK); } VM_BUG_ON(!stable_node_dup ^ !!stable_node_any); if (!tree_folio) { From patchwork Wed Mar 20 07:40:46 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: 13597424 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 22E01C54E58 for ; Wed, 20 Mar 2024 07:38:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 917558E0001; Wed, 20 Mar 2024 03:38:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C8646B00A5; Wed, 20 Mar 2024 03:38:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 768158E0001; Wed, 20 Mar 2024 03:38:14 -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 678416B00A4 for ; Wed, 20 Mar 2024 03:38:14 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3C9B21402C7 for ; Wed, 20 Mar 2024 07:38:14 +0000 (UTC) X-FDA: 81916614108.18.6F64422 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf09.hostedemail.com (Postfix) with ESMTP id 120D8140018 for ; Wed, 20 Mar 2024 07:38:11 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NAz1Jtn5; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.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=1710920292; 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=Gy8pt/xqRJMf3r7GZ9kkqZx4ekh1Lp8oaLaZ7e4CbS0=; b=OQHaMeGJ/+OxhEf5NGJQoan45o5YxASB+KMXPcP2iRb43HPYbv2AFegj6wZ5oZWUo4CTSz gssk3VE5FURBHkEShatJTa59VpbXUcNCixsEAdDr+RS/C8kb8QiLpul04P4K4rwgA6+fZ3 ApNRPB/FVKpHeAXBY2kHWVmKe4eKKik= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NAz1Jtn5; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.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=1710920292; a=rsa-sha256; cv=none; b=ih0yG3S7LPbsIVpZQs0o5EIV5AzVcBapfUwceB6hp5/zR/Udl/1SV0z9Wk9wHHsJocFmFS 8oeEXtHHt/R0+N2Wx/EB0ZKjTf1CoFjath8xDR2mf+uoPNbAt/WrRSnKFnBfLtDQvuT6yy uY/3fEUDPOnYqCiM5YBEbKDyFcV2wsw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 746FFCE1093; Wed, 20 Mar 2024 07:38:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3178CC433F1; Wed, 20 Mar 2024 07:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920288; bh=4/ipLVxA+I+/npLz6EvsQqobqTxElBqybjRD2uQTgUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NAz1Jtn5Tv7xWex39egXoEsKh+6Jyz4na6sqHGHE5Gn7vpfr/BD5NGADxf131MnF8 nS679xCkTyyQY1M8WtgJdNq8mqaUixp8HZrftKU44Ld/m7tOJd5wILQYaeRALdGZav wS5kjN/WFPEojTEskJziqJTsLeXlW+eoz/PRYZVDNqgGvpd/i/xAsOTqtjaZ9HN5Wl e9MSXRQFkU1funeUToZImXIzxFfPPfX05lRAjuCpOe/pKbeh3Vldew9uu+mJRTZuYg XcIxbGSEnfSyVXgguUKGdo2qx73PFtZy6OF36ZSemWtHs+H/mFl9yoO47rNR5HxZDP teWlc/3bOCa/g== 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 10/11] mm/ksm: rename get_ksm_page to get_ksm_folio and return type Date: Wed, 20 Mar 2024 15:40:46 +0800 Message-ID: <20240320074049.4130552-11-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-Server: rspam09 X-Rspamd-Queue-Id: 120D8140018 X-Stat-Signature: 5k6ug4wnirdy8jba7kb3cghsu7demaj4 X-Rspam-User: X-HE-Tag: 1710920291-636578 X-HE-Meta: U2FsdGVkX196u3ue+nKLQRvWXG9etpRrqUMxj74hr6/NcFtnAc/KYx6KLnoR4dEdIeADnJzI1hqvfSzmW92YpIUXsuVHUrvk8ca22YXXDqg2HMy/+ZwLQB37Y6dtH5q0D5ZZyxs5CxHrBoM6IDus+m5kANBqGufH075jXihUmlyKAaXJHyAVt2kA6T0+TKo1fViWL6zkWXmorGndIG2hKyh2oVFjpCeLQZvQL+pnMHW9UUNtwy/pP5J9HvcN9N6Qbx9efhUn1rXuR2iqs1w1eYNU3CUCk0nhw/U3G0QOabr+PeNHi+G5Kgsexpx1Hn4irFh4NXyLUmPdEvuBbQ3N7azO5n+mvUKVKGz/9q7SpLr1wRjw6/x1Jnx+lx0+hCB87LBbSkey8WgUhVKzn4mAJa3LqEMetT+Tfgadv61AX/J/zaaExR8+t559ElOftu7eb1LopU7oiOQXj+u7yvLkL3FkubQ7Y/L3qmF5NGmroL63tTmxIJUc+DPjlyjuLKCg7rTN/qICf66uPe3NnZja2Q+5yCqB3D1mZEcw/3wBRexy7BhDXDNtHLdxZRucobtkiwC0eq3yD4AKXWVI9XJfvbibX29NvA5GbeewVewIihz8xGn5GrYP7j2p6iDyRYk67WxXAFV2boAKyAvuMWAtdIgSIpaYSqAkTzkHEZ/k21vhrxsLnsgnVoFV/oFWvsqi5QVMeZg+af2WBZXcKBSnrrcTvobm1rI2st0xhgUDXoWN0ae8KPgHq74EGOOCAiKGqY3hDOkfZUx2gTHyCAEUiYH6crLx30CNLPrR9fi7Vj/uetb+RqzYOpBHxzV+D8QSumQ32jRwmMdncMIbF1yXtnWD/acrjMSF3iwX9J3a0PGO/c8IiYQjZx5V2ZODy6WXDfMFbBXrwVlGUSrNCOX4HiNV9rR43WLsv5ecHDAQS1+yrnMGu+m9xOfz82GKLdFALPyw+L1i/9DorosXO8H QUcnioCZ 8b3e4 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)" Now since all caller are changed to folio, return to folio and rename it as get_ksm_folio. Signed-off-by: Alex Shi (tencent) Cc: Izik Eidus Cc: Matthew Wilcox Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Chris Wright --- mm/ksm.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 75401b3bae5c..806ad4d2693b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -890,14 +890,14 @@ static void remove_node_from_stable_tree(struct ksm_stable_node *stable_node) free_stable_node(stable_node); } -enum get_ksm_page_flags { +enum get_ksm_folio_flags { GET_KSM_PAGE_NOLOCK, GET_KSM_PAGE_LOCK, GET_KSM_PAGE_TRYLOCK }; /* - * get_ksm_page: checks if the page indicated by the stable node + * get_ksm_folio: checks if the page indicated by the stable node * is still its ksm page, despite having held no reference to it. * In which case we can trust the content of the page, and it * returns the gotten page; but if the page has now been zapped, @@ -915,8 +915,8 @@ 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 void *get_ksm_page(struct ksm_stable_node *stable_node, - enum get_ksm_page_flags flags) +static struct folio *get_ksm_folio(struct ksm_stable_node *stable_node, + enum get_ksm_folio_flags flags) { struct folio *folio; void *expected_mapping; @@ -1001,7 +1001,7 @@ static void remove_rmap_item_from_tree(struct ksm_rmap_item *rmap_item) struct folio *folio; stable_node = rmap_item->head; - folio = get_ksm_page(stable_node, GET_KSM_PAGE_LOCK); + folio = get_ksm_folio(stable_node, GET_KSM_PAGE_LOCK); if (!folio) goto out; @@ -1110,10 +1110,10 @@ static int remove_stable_node(struct ksm_stable_node *stable_node) struct folio *folio; int err; - folio = get_ksm_page(stable_node, GET_KSM_PAGE_LOCK); + folio = get_ksm_folio(stable_node, GET_KSM_PAGE_LOCK); if (!folio) { /* - * get_ksm_page did remove_node_from_stable_tree itself. + * get_ksm_folio did remove_node_from_stable_tree itself. */ return 0; } @@ -1126,7 +1126,7 @@ static int remove_stable_node(struct ksm_stable_node *stable_node) err = -EBUSY; if (!folio_mapped(folio)) { /* - * The stable node did not yet appear stale to get_ksm_page(), + * The stable node did not yet appear stale to get_ksm_folio(), * 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 folio might be in an LRU cache waiting to be freed, @@ -1641,13 +1641,13 @@ static void *stable_node_dup(struct ksm_stable_node **_stable_node_dup, * We must walk all stable_node_dup to prune the stale * stable nodes during lookup. * - * get_ksm_page can drop the nodes from the + * get_ksm_folio can drop the nodes from the * stable_node->hlist if they point to freed pages * (that's why we do a _safe walk). The "dup" * stable_node parameter itself will be freed from * under us if it returns NULL. */ - folio = get_ksm_page(dup, GET_KSM_PAGE_NOLOCK); + folio = get_ksm_folio(dup, GET_KSM_PAGE_NOLOCK); if (!folio) continue; nr += 1; @@ -1748,7 +1748,7 @@ static struct ksm_stable_node *stable_node_dup_any(struct ksm_stable_node *stabl } /* - * Like for get_ksm_page, this function can free the *_stable_node and + * Like for get_ksm_folio, this function can free the *_stable_node and * *_stable_node_dup if the returned tree_page is NULL. * * It can also free and overwrite *_stable_node with the found @@ -1770,7 +1770,7 @@ static void *__stable_node_chain(struct ksm_stable_node **_stable_node_dup, if (!is_stable_node_chain(stable_node)) { if (is_page_sharing_candidate(stable_node)) { *_stable_node_dup = stable_node; - return get_ksm_page(stable_node, GET_KSM_PAGE_NOLOCK); + return get_ksm_folio(stable_node, GET_KSM_PAGE_NOLOCK); } /* * _stable_node_dup set to NULL means the stable_node @@ -1877,14 +1877,14 @@ static void *stable_tree_search(struct page *page) * write protected at all times. Any will work * fine to continue the walk. */ - tree_folio = get_ksm_page(stable_node_any, - GET_KSM_PAGE_NOLOCK); + tree_folio = get_ksm_folio(stable_node_any, + GET_KSM_PAGE_NOLOCK); } VM_BUG_ON(!stable_node_dup ^ !!stable_node_any); if (!tree_folio) { /* * If we walked over a stale stable_node, - * get_ksm_page() will call rb_erase() and it + * get_ksm_folio() will call rb_erase() and it * may rebalance the tree from under us. So * restart the search from scratch. Returning * NULL would be safe too, but we'd generate @@ -1938,8 +1938,8 @@ static void *stable_tree_search(struct page *page) * It would be more elegant to return stable_node * than kpage, but that involves more changes. */ - tree_folio = get_ksm_page(stable_node_dup, - GET_KSM_PAGE_TRYLOCK); + tree_folio = get_ksm_folio(stable_node_dup, + GET_KSM_PAGE_TRYLOCK); if (PTR_ERR(tree_folio) == -EBUSY) return ERR_PTR(-EBUSY); @@ -2110,14 +2110,14 @@ static struct ksm_stable_node *stable_tree_insert(struct folio *kfolio) * write protected at all times. Any will work * fine to continue the walk. */ - tree_folio = get_ksm_page(stable_node_any, - GET_KSM_PAGE_NOLOCK); + tree_folio = get_ksm_folio(stable_node_any, + GET_KSM_PAGE_NOLOCK); } VM_BUG_ON(!stable_node_dup ^ !!stable_node_any); if (!tree_folio) { /* * If we walked over a stale stable_node, - * get_ksm_page() will call rb_erase() and it + * get_ksm_folio() will call rb_erase() and it * may rebalance the tree from under us. So * restart the search from scratch. Returning * NULL would be safe too, but we'd generate @@ -2601,8 +2601,8 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) list_for_each_entry_safe(stable_node, next, &migrate_nodes, list) { - folio = get_ksm_page(stable_node, - GET_KSM_PAGE_NOLOCK); + folio = get_ksm_folio(stable_node, + GET_KSM_PAGE_NOLOCK); if (folio) folio_put(folio); cond_resched(); @@ -3229,7 +3229,7 @@ void folio_migrate_ksm(struct folio *newfolio, struct folio *folio) /* * newfolio->mapping was set in advance; now we need smp_wmb() * to make sure that the new stable_node->kpfn is visible - * to get_ksm_page() before it can see that folio->mapping + * to get_ksm_folio() before it can see that folio->mapping * has gone stale (or that folio_test_swapcache has been cleared). */ smp_wmb(); @@ -3256,7 +3256,7 @@ static bool stable_node_dup_remove_range(struct ksm_stable_node *stable_node, if (stable_node->kpfn >= start_pfn && stable_node->kpfn < end_pfn) { /* - * Don't get_ksm_page, page has already gone: + * Don't get_ksm_folio, page has already gone: * which is why we keep kpfn instead of page* */ remove_node_from_stable_tree(stable_node); @@ -3344,7 +3344,7 @@ static int ksm_memory_callback(struct notifier_block *self, * Most of the work is done by page migration; but there might * be a few stable_nodes left over, still pointing to struct * pages which have been offlined: prune those from the tree, - * otherwise get_ksm_page() might later try to access a + * otherwise get_ksm_folio() might later try to access a * non-existent struct page. */ ksm_check_stable_tree(mn->start_pfn, From patchwork Wed Mar 20 07:40:47 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: 13597425 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 7F86FCD11DB for ; Wed, 20 Mar 2024 07:38:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D6798E0002; Wed, 20 Mar 2024 03:38:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2129B6B00A5; Wed, 20 Mar 2024 03:38:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08A118E0002; Wed, 20 Mar 2024 03:38:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E25366B00A4 for ; Wed, 20 Mar 2024 03:38:14 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7F0B1160B7A for ; Wed, 20 Mar 2024 07:38:14 +0000 (UTC) X-FDA: 81916614108.21.054F350 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id DA95540005 for ; Wed, 20 Mar 2024 07:38:12 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JJwpJSdF; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.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=1710920293; 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=fWp2INN/oXeQRE6IS5X40tDerR+6irsQ/sE/nbJlu1I=; b=zew63doTFPnXWXqT1nmJk1xGTfUXOeqFmOnBvOHuMYL4D1Hg/itCs4TckNmtiqRy9k5Ddz C6YvBn1b5pOT8GxQHxp08xLkFLUXyJBbmJspWU+0hSqu4TSMHcu7350Vmq74uKY96vJPBM qCESoIISOHmeCgifRlA2+k0JQwf+w3M= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JJwpJSdF; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.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=1710920293; a=rsa-sha256; cv=none; b=nKIQIS0gz2MN3yys562wNaWCQDGXzNeDXZ7mNGql6IjklhflKxWLuPNiXPI1th3KJQ0lz0 ASOWeL4GFQm/oKs9X1UlUYJj0+cDCFJiZsjI/yl1gfLJGltM6qXePfJtdgokIQNdbEwYU8 Pe30rLldOpLwVr+Kz2yDxV+WB7nktAc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0A8CF60FE6; Wed, 20 Mar 2024 07:38:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57DADC43399; Wed, 20 Mar 2024 07:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920291; bh=2eCzaBD/FPlVUCW+3c3mpz0T6iG1rGJcXt6EJeYetoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJwpJSdF8PMQwKdjVsH6aJlrbH9++/7WiZkEWLeurmSr+JfpMJKrW+x4hDWfZCJfn dnRIC5q3bejKL1Rdjecw3lZ9mQfSrOecTOhXOsUmFmCHmT3nzZdOxZglTE6xGXFO7c jXeNkxlgkQZ5SMTxR8JJmBr2KNActnCXSpXBACqkNiERLUIZslmxWTpMsWwLpIjOeQ NXmB9l0gy1Jr+wUf/lw+AMatfNFMp0xfp0CdxVBc+c1jcuJS66HpsTnovaxLpVG+/k CXUcwj2LgYj6pkUzNz7WZ7VHtMwZEUn3E7O+PeCIqK7vRhs2kjEoEK5Mn7mwWr/nLx nLX9yNep5BLJA== 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 11/11] mm/ksm: return folio for chain series funcs Date: Wed, 20 Mar 2024 15:40:47 +0800 Message-ID: <20240320074049.4130552-12-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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: DA95540005 X-Stat-Signature: wfjmu6tnt1j31wfzxg48wg8rare1cyjo X-HE-Tag: 1710920292-146871 X-HE-Meta: U2FsdGVkX1877ToD2VMcjeEO4Aeb/dmY1GDVF9gTJ9YjUNhHtPuECNmgtBFty/CWRylXokMl56Yp5QWFWyIOtmYUEc6/JLLb4wqqmWkdn/BUot6tJdoVVufnAnMqt3SJTD+rltdSNdAxGyTP0yl5aZT3ANOjeUlKtA8uwnSGiQnQJm77Z2iv7QaqkZQk7WLFfXnAAs3XRkIcoR5UmA7dkfP38oe8c5DYiPQzTEX1dNW8V6YnbJNYjI+nQEW1UUaPGX4vKR/lxXoV/xOCuI/U6nAjQcGPw9u6WjFhKRlEnKllvXrW2TlPpu+vI4Rs2xLFDEvWw8zjhPFcA+P51Ie1hIF+6348DQOTiLGwkk5CCW6iFP2C6sr4CWffUuukZF5L2q0mJqPODFTV0dVFcdT5gME6Q3SeflOR9X4Zi7pYJQvpPO7IiQVxA67W/5bwm8Z7qNn2WJh/BlpWBvXT0aDqnwc1xJp9o+LJu+V+0BJADHT++r0ErJOQ1PfNCtI3csAuJAUoxjsmXUvPIVgIpIXWh392n9oAF4BjZuTlrmgg0iJEmLv3q1cLKBK9THHSR+WVWQB02cGgMqL698EYx+FUPE4lNj1I0uxDLIswwF0H5IVTQBFO8nHCZtG0z6j3+/a9c4bz6qSseFu6eRw9C7jNfxi1+6l+crKgjKtLS9tqQ4kXiHDd9y7pwHTLjr/1gdOc5n+wFLZCLlWY6ZvgSjxTqtMOd1GBDUqrZsJJCjUrhH2PssOi0z2lyE8CqjRwnnmcwmuwNiiv7yleZjc5+eI2SLX/AHhnHhvDi9JRw9ib5LrWicHoaJSMFJGAkYZdW3GhB3IEitOApDf+b7ii2nKqMFtPZViUsU+kowafvjgkenYrosvUYVS3k4hDAtdbuQSrjEj/VRsEbVQb4QOSc18pW9RjOWAIEQuTe6/6izC7LLb13NdFx3F04l8AvinEskRqfDi7o0mUhera87to4jP 1DI7UzuU rqeV+qcecLtGU9qu+qMpcRXppKRDBxp0nCEJUBNyxVMJxsH9Dyq0Zp40SKBpZvZSvqtLjW841FZ64UegFGhWDStrM8TVctxVPtseTnFzEjrtBpuC4/yZrgQwx//vI/g933MuRotFoij2hhe5M/O4pQpS1IfGKXbiBpBLXpSPvDzVNEsqsYdaStaQuJ8qGEP5xHCMqrj7GIpbOP+cXBwIZQREjN2lUHTy6XvVXRLKBKT2A5mPwknutbC7nl0ZeLHcje5fuWoEvrXIrXROdNk2mzS2Sd0qmkwtX8okn4vdACNKrhmsy2cW7PelWz/TOB6Z2I3Ee5em148IIshcYX7gyESw0Cg2OS6/cP8gPp6D3og7vbbdamkwj0UNSZuk2qxd9WGwhCpZBq5qCUThsstHbdGq2utTHrkdQSPxj8uxYuwv4NiEmN6vf9VAVioltKIWmAkOpGuoXyNSK4aQ= 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)" Since all caller changed to folios, change their return type to folio too. Signed-off-by: Alex Shi (tencent) Cc: Izik Eidus Cc: Matthew Wilcox Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Chris Wright --- mm/ksm.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 806ad4d2693b..74cf6c028380 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1615,10 +1615,10 @@ bool is_page_sharing_candidate(struct ksm_stable_node *stable_node) return __is_page_sharing_candidate(stable_node, 0); } -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) +static struct folio *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; @@ -1761,10 +1761,10 @@ static struct ksm_stable_node *stable_node_dup_any(struct ksm_stable_node *stabl * function and will be overwritten in all cases, the caller doesn't * need to initialize it. */ -static void *__stable_node_chain(struct ksm_stable_node **_stable_node_dup, - struct ksm_stable_node **_stable_node, - struct rb_root *root, - bool prune_stale_stable_nodes) +static struct folio *__stable_node_chain(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 *stable_node = *_stable_node; if (!is_stable_node_chain(stable_node)) { @@ -1783,16 +1783,16 @@ static void *__stable_node_chain(struct ksm_stable_node **_stable_node_dup, prune_stale_stable_nodes); } -static __always_inline void *chain_prune(struct ksm_stable_node **s_n_d, - struct ksm_stable_node **s_n, - struct rb_root *root) +static __always_inline struct folio *chain_prune(struct ksm_stable_node **s_n_d, + struct ksm_stable_node **s_n, + struct rb_root *root) { return __stable_node_chain(s_n_d, s_n, root, true); } -static __always_inline void *chain(struct ksm_stable_node **s_n_d, - struct ksm_stable_node *s_n, - struct rb_root *root) +static __always_inline struct folio *chain(struct ksm_stable_node **s_n_d, + struct ksm_stable_node *s_n, + struct rb_root *root) { struct ksm_stable_node *old_stable_node = s_n; struct folio *tree_folio;