From patchwork Mon Feb 26 20:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13572833 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 1B72AC48BF6 for ; Mon, 26 Feb 2024 20:56:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C14E4401BC; Mon, 26 Feb 2024 15:56:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 24DC044017F; Mon, 26 Feb 2024 15:56:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0759A4401BC; Mon, 26 Feb 2024 15:56:13 -0500 (EST) 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 E64F444017F for ; Mon, 26 Feb 2024 15:56:12 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B15CBA0A22 for ; Mon, 26 Feb 2024 20:56:12 +0000 (UTC) X-FDA: 81835162584.24.7DC62CA Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by imf26.hostedemail.com (Postfix) with ESMTP id B55E3140010 for ; Mon, 26 Feb 2024 20:56:10 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=hJT3EihE; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=Q5oLgEgT; spf=pass (imf26.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708980970; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WJOIcMtfPYUOzzIot1iJ43LJYEvqslRWUKho7a0H8UI=; b=aX3zzVcCQbqLd6TZKE+aRkLxeWxZAH/Ue9cx/7/qJinuwv9QwXKTtBqjXkAXcoE2BvVY2e QwBe1oe1Z6lAP9r4AI6bB9nB7+iDa4bgtITLG0pFiCu0z6aqjUDVTp0syffA5tFuhsE4HD FjcnZBs/wiEsh7avuwVOn9QpOqgPziY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708980970; a=rsa-sha256; cv=none; b=WhNfWMf1I5wIaQ9D/BmPEfbeUD5+Qnqelc6Rz1pP3TJrAOf275oSf/BLqw/gMoKMPmED9N XAKzftZVFS8caPuPjxGahfzqEAdVgTpAHQX0c6TNk1c1i8PNmQD2zgwijn8VDFNXCK0ict y2wf+hVEeGtT3jeK/NtkJ57V0BzPlgo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=hJT3EihE; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=Q5oLgEgT; spf=pass (imf26.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 102EB5C0098; Mon, 26 Feb 2024 15:56:10 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 26 Feb 2024 15:56:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm1; t= 1708980970; x=1709067370; bh=WJOIcMtfPYUOzzIot1iJ43LJYEvqslRWUKh o7a0H8UI=; b=hJT3EihEH3zjGCbTc3s5Q1Im8ArJH/JWJT0hNhjb5JGTqkagU5W Q4hNKBxOinzn7ifNib2G/h16pcUfmI1/bqfx0QW9ipxOVL/z73oO0wIhUCRQrKIj QuyalNfeyGJhvoNoBMmNqOoHD+mZAQ4iOtS8zkzd6wxJ8UyxHfUZ7eiBm3YO68zB bD7v8Gb6j9T3B3OXeUkLj/ck3cczpXMLeakNCkel/zMJnic20K6wkIi/8IhA0LwU ozLTnlOLqs47hU/ehXc616Wd6Xip/Gxu9kBPBoJ7LBix5axVEearJu+HgHnojEdA XYKCy/eTe9paK7oZmye1sK5ka3F4fZ6sVbQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1708980970; x=1709067370; bh=WJOIcMtfPYUOzzIot1iJ43LJYEvqslRWUKh o7a0H8UI=; b=Q5oLgEgTHIUoilhhh8ikGrW+fLZkXFebzxvzF+BCqVKz0mFbfKG dNwr2FwozKoylm8kaJXYNkoNFkoj/B6kyoT3uz81JV7UwxrafURxKGHdux6Te0b3 Bni3HMV50CWoYfsL+SLnqjBzl4Ui3boCn2vCF+xDO/x5DeJRTh6DLcbYuO+HHwOi AJLzPdTJ3wgzyZECzE9t6vANiyVrnMz4l/+p78bUdO5MVFirqZUmCBiB3alPjaAb 1ztIjR0tLINoL8O8036DDADyCfaJuyE2PsrIAa3kOJ76zPSKzcVqY/XV/ewhmKav mI2WkIBa2+ajP1dPmr7bZ3UmQU+9kDzWP7g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgedvgddugedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 26 Feb 2024 15:56:08 -0500 (EST) From: Zi Yan To: "Pankaj Raghav (Samsung)" , linux-mm@kvack.org Cc: Zi Yan , "Matthew Wilcox (Oracle)" , David Hildenbrand , Yang Shi , Yu Zhao , "Kirill A . Shutemov" , Ryan Roberts , =?utf-8?q?Michal_Koutn=C3=BD?= , Roman Gushchin , "Zach O'Keefe" , Hugh Dickins , Luis Chamberlain , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v5 1/8] mm/huge_memory: only split PMD mapping when necessary in unmap_folio() Date: Mon, 26 Feb 2024 15:55:27 -0500 Message-ID: <20240226205534.1603748-2-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226205534.1603748-1-zi.yan@sent.com> References: <20240226205534.1603748-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: B55E3140010 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: u5ebgbuuatsz5q68hnkt1795siozw6jp X-HE-Tag: 1708980970-5533 X-HE-Meta: U2FsdGVkX1+CuAzK0YTEYjkDyfa1hneqVoizlE63IUz23tr0w4ku2VQdncyTamo7PDORrVipiC4q+hHGK6IUZwxMBT3fhR/SOsHA0SQ7GbjqSF0w6xvcyz1YqasWoF7xB78zF08OlIEKps/ev57Y0OfDnNkxDfwhRmDFpuD6apx3E5YrBo5Yy6vZit0wM4V7NiwxM0tna39rr5cvPfQVWmoXoU1z2o0Sdj9X0cqhYQ8Z4cNv/0gIDVMW4EAosDZ/T04h7gNitKAZS9dEexW9mXbdBldWsf/dKT3PQ2ZAEaawv6fZheZnYhHZNAHHWKU4FS0a7QVH/CEi40jdthi1LCkNakVc5c7azhpRBsiNFwWVQgQ4CjnULbHkN6oo/nW9Rw+lMhQ1wTYARCzD9ONV7viEdaW45FVTKRrFcL3m7x7+VBWRnF/gtGm3aKSaOXTQH3He/OCD3Nr1FKXUp4deYCWz439wEnS0pWEs8SjLHcRNY96rLO5I2lR7qUVCXNsDrI1Ti5yPiohA0nByfeWIyDPbCTtPuUlNKV5CRoQxb0LI0uPOxVNhm7rnDlrMqdsvc51eDlKfYAT1s0kCMcdrtjf/WrXV6PiWo36+WYt1JGR6Z2br2ieH+5aNq3uHCMPVhHIkPN4k0+M8UtNdbSmsNZoma76pt+1skbHJ78Ep2jTeiKxs+mtL+1DUBIODCrxS9/u/wL538JaNFT545duy4aYa2iGjzUoirjq8szSFmJh7wIxXBMZVuUTC/+tQKAKBgepSuP2zyVvIz4r04UqojoelOO6OOE8VRT9XB444nxBY1RbTRsC980LE98H1qAkN7zkxFr7EBuocFCWe75Pu/QRdhEmw+GCK3IER1oGJVPs9CZusvsLJLQnvkUkBUIVxnE51CSNQOUQS6oBXwFT/MP9+NsdVVZuVmwhhfrpkcal7BR++2WOcWlkriEw7UZjnFKfTR9wkSA0dvAccsjX vhjiwHye ctfxUCDJxziGsAZ5XwgEmYSOcNr0cD4udPi5b4E9jaFX9WrfFMe0MbyCHJGqQUrAdfwT9PnyoAz5pD13Pe9nBCllsD8gUpKbQdNJswjY3P3B2XJF3PWdUdhFuN6MhxFN5z/MmJbbZFVsmL2cnGZaClIihA6VLousgA1mn3Fx+BEzhDtgWC8kVUu8tSmY0PsrJaf/OA525tiwsWoS28W3ce7aEn4xT7yHS/9WP53UWBT4jnR4CKdTw1uM2iup2vuxhc/CKypIC30CMOlVIB0TyRMd8t1G4h3+zr9LWHsu4wDNXf6b2jZwz+AYpV+479c32UW3h3dD7HO0ovWbbU60s74M0GNrKuN8s4EqHljWdmLvYXRNNwEJJ7Euu/GrPT1Ul5ZiiMM5e8XYEPivGsBo3VRhCkSBoehszY7JMQafTl2UWH83yI1a6ejIq+QRE5CreZQQq64qeVoeXT4u80poyNcCILpK5mFZTRe2t3Pbadk2o3vSXhLJLwaampA== 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: Zi Yan As multi-size THP support is added, not all THPs are PMD-mapped, thus during a huge page split, there is no need to always split PMD mapping in unmap_folio(). Make it conditional. Signed-off-by: Zi Yan Reviewed-by: David Hildenbrand --- mm/huge_memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 28341a5067fb..b20e535e874c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2727,11 +2727,14 @@ void vma_adjust_trans_huge(struct vm_area_struct *vma, static void unmap_folio(struct folio *folio) { - enum ttu_flags ttu_flags = TTU_RMAP_LOCKED | TTU_SPLIT_HUGE_PMD | - TTU_SYNC | TTU_BATCH_FLUSH; + enum ttu_flags ttu_flags = TTU_RMAP_LOCKED | TTU_SYNC | + TTU_BATCH_FLUSH; VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); + if (folio_test_pmd_mappable(folio)) + ttu_flags |= TTU_SPLIT_HUGE_PMD; + /* * Anon pages need migration entries to preserve them, but file * pages can simply be left unmapped, then faulted back on demand. From patchwork Mon Feb 26 20:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13572834 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 7B738C54E49 for ; Mon, 26 Feb 2024 20:56:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D71B74401BD; Mon, 26 Feb 2024 15:56:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D219444017F; Mon, 26 Feb 2024 15:56:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B71904401BD; Mon, 26 Feb 2024 15:56:13 -0500 (EST) 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 9E6AA44017F for ; Mon, 26 Feb 2024 15:56:13 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 58EE01409FA for ; Mon, 26 Feb 2024 20:56:13 +0000 (UTC) X-FDA: 81835162626.19.77FA258 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by imf28.hostedemail.com (Postfix) with ESMTP id 78E96C000E for ; Mon, 26 Feb 2024 20:56:11 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=T5xeqRqY; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=bp4JhDO6; spf=pass (imf28.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708980971; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ODE0ROICHsjD0yZP7iLxwoRZvmdJZzbZs1wZ6FX7X9k=; b=RpfN6LDV31cOZcImJNLtUj2PN8SSidd+HmbI+12M8fmqwmOSCBTrXo9RVFARGRG8aRwLTl F0pf7q6SqS+XglA7iufcX/UsjrbPJ2pz/shHe/zZKdsEoaSXeoAcjdfCRo1oeuuE6Bvfwk A0xgipzJ2yoGR6aYwrDDTQXZqsX3R18= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708980971; a=rsa-sha256; cv=none; b=Gcs9qfIoz8IEyPjGwmvdqvpmWbU2H46us7rKRaQXck7Eymq6TqxvcmKfHZNI6mDPeTDAlE 2rMfDdnNH/0fB3f8aL4gkJ5tYEsMqqZ+I7em3cusrBOD4JhJGG44M0KA1oSNHEqac3knG4 4YQJl4pBRiM6DorVrw9+3fU+8rUs0p0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=T5xeqRqY; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=bp4JhDO6; spf=pass (imf28.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id CE54C5C00A4; Mon, 26 Feb 2024 15:56:10 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 26 Feb 2024 15:56:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm1; t= 1708980970; x=1709067370; bh=ODE0ROICHsjD0yZP7iLxwoRZvmdJZzbZs1w Z6FX7X9k=; b=T5xeqRqYOCyBPMLYOa3Br+G8KABMxRYqzZHOqItB1AZrzBWc5++ v+Y7er2Z+fEtOY1M/UnNBzfbkuRk6ewQ6+GDS0M+g8TVhKmRbqYnUvTSSYENgpdl 12S7nVi060wPvZWE00vlxyzNriF+sFFCE/S+KC5feMd22qZNmgdU3fy5tMtsHfvV HT2RBYHADtA7sl/kk2Myd4K/s/xtjY5JP3jJkKGHEW4wIWZnQzJzlBw4hVValEJI pF1ogC001UIVIud1NFAAmMHBXEFLAMxinZXdOZVBdBQDgReZA/38hv+a2tRczoQt LOte/EUa97kieD8yiSWrp9rgQ2oOOQERj3A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1708980970; x=1709067370; bh=ODE0ROICHsjD0yZP7iLxwoRZvmdJZzbZs1w Z6FX7X9k=; b=bp4JhDO6+sHuaMDjp3R19HRVAcTJ3cT1Z+YMXxBHek2OtVWeSIe bSoGWccfFZxHU/vp1hRV/Wx+/NGe2Nwi5VqPnD17ZmX+OO0h9nYYxtd5cYNsJpSZ k6g2gwk3TgcZZC/YqlkL5NwFr75VwxrFdHv/h4jJiey1C3KamfbEuZhqUTmIB1gT VqM+UEkjuQX2hgvT083qH5JYaQ5FeWxw3SNFXooaEzMoAAkw/w+VQ0Z7HSqLEbl8 wYgwWMCVwHlAZFQ5egIrbRKFj6xvh9Sln31XLTY/XDq2FTFETb5D5nn822mnX2BK oyJKkW5yKnszzEI9XSdKRE0NE9iNtLkdlEA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgedvgddugedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucdnrfhurhgthhgrshgvucdluddtmdenucfjughrpe fhvfevufffkffojghfrhggtgfgsehtkeertdertdejnecuhfhrohhmpegkihcujggrnhcu oeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeettdekjeffke ejudelhfeuteekieejieehjeefvdefiefhteevgeejheegkefggfenucffohhmrghinhep khgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepiihirdihrghnsehsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 26 Feb 2024 15:56:10 -0500 (EST) From: Zi Yan To: "Pankaj Raghav (Samsung)" , linux-mm@kvack.org Cc: Zi Yan , "Matthew Wilcox (Oracle)" , David Hildenbrand , Yang Shi , Yu Zhao , "Kirill A . Shutemov" , Ryan Roberts , =?utf-8?q?Michal_Koutn=C3=BD?= , Roman Gushchin , "Zach O'Keefe" , Hugh Dickins , Luis Chamberlain , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v5 2/8] mm: Support order-1 folios in the page cache Date: Mon, 26 Feb 2024 15:55:28 -0500 Message-ID: <20240226205534.1603748-3-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226205534.1603748-1-zi.yan@sent.com> References: <20240226205534.1603748-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 78E96C000E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: wbuodgd7is5zbgx4pomp9apxdx3t6ix9 X-HE-Tag: 1708980971-77284 X-HE-Meta: U2FsdGVkX18aWbvpGyGP0rQAGZD6jPtJaeMXAkp29EYYvNGFi9Wkn/YccttmC5JcVa33GiXPOKLTaOmgR1/AZQwR0SybdFeTOCUW7pj3hSCyPC4qQvkEeM+aa6Cbax2CeVwEWZYdoXKHHatGHuTErQtfZj3QTQugK9Odr/ArBkKuFj7HGsxhNGraDjag3WqKa+WNlNi0ntz01jXv4kcZubmbZp8cFCzjiNg6WbAg0seKqnTjfxt8JikEDw5SR4jnYxzSjZAA1sdSwvZowK0Cvu3Fi+AfWIJhz+3zsVysSsV9BtOQdfhdG5Ntt1LCHMV51rEwk7gpBwegDQWFddHwWfPs6EFBxiHHm+ifOyzTUZ2K8aveIKpjkjJrmSQ03ZDEeCH6+zWMIfS4uVCAKe91ZeVhwV8AAQ0uohiz2rIkMRFlFkmgxnAfJyiVF+oAd6fI/Y9M7jZqtQnY3ylNqAz124TsjSxFeweTyMSKB6NgrMVqBdd09sd+Ide97MlITHCZtmnOe+5BD5IAAg6WyIR3orPjyZBRr3TCpkTvSRlNS++wV3f9hdKfcQA5IP+CaGvK01DCftsh+H/JDw2KCRgEwJi+vaGkBrB3qWa8jouUly92nO3gPCG7/0NN5XNhOvCB6YyQ6Af1uRHE3fwp6PEncazeysHeVadkHKM3NKxQTkSUSrwf6cbRxRaOtuFzdUGrbeLzYh1RXj60BQ97FpKAazL9oEfO48j278udc4GaEXWA8Aq/cPEV+2bTDFWo8oYi30jYL9dmH07t6NxAezPObVTLsckrdk2DrGiiX5dxmdqUkgit+O6ieCYjZ3zqayKG6kNwU71N4T7+3AJHJ3BS/Q2/YptDWQLWnaN6KICGQVTZG3oHx0S9al5VG3OKZfEiwUMFyL6So7tVyl8nZcsDyy0xRmDhECAbasqduZyDJKvB3AZ7ebUb6pSBv7npyg6V2ppdK5ZhXnCFD2E3pdW ELfAYcwE xu4IRMjoytu6xZfte4HX7qLbeH2N3aXTChIlAOAWiO5ocdZSS+45QhWODktWTZAkHMraYu0wf114UzHGbIjMhdwE3wy2B3dlB0rSjOJ9Yso/3QTM= 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: "Matthew Wilcox (Oracle)" Folios of order 1 have no space to store the deferred list. This is not a problem for the page cache as file-backed folios are never placed on the deferred list. All we need to do is prevent the core MM from touching the deferred list for order 1 folios and remove the code which prevented us from allocating order 1 folios. Link: https://lore.kernel.org/linux-mm/90344ea7-4eec-47ee-5996-0c22f42d6a6a@google.com/ Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Zi Yan --- mm/filemap.c | 2 -- mm/huge_memory.c | 19 +++++++++++++++---- mm/internal.h | 3 +-- mm/readahead.c | 3 --- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index b7a21551fbc7..b4858d89f1b1 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1912,8 +1912,6 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, gfp_t alloc_gfp = gfp; err = -ENOMEM; - if (order == 1) - order = 0; if (order > 0) alloc_gfp |= __GFP_NORETRY | __GFP_NOWARN; folio = filemap_alloc_folio(alloc_gfp, order); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index b20e535e874c..9840f312c08f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -790,8 +790,10 @@ struct deferred_split *get_deferred_split_queue(struct folio *folio) void folio_prep_large_rmappable(struct folio *folio) { - VM_BUG_ON_FOLIO(folio_order(folio) < 2, folio); - INIT_LIST_HEAD(&folio->_deferred_list); + if (!folio || !folio_test_large(folio)) + return; + if (folio_order(folio) > 1) + INIT_LIST_HEAD(&folio->_deferred_list); folio_set_large_rmappable(folio); } @@ -3114,7 +3116,8 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) /* Prevent deferred_split_scan() touching ->_refcount */ spin_lock(&ds_queue->split_queue_lock); if (folio_ref_freeze(folio, 1 + extra_pins)) { - if (!list_empty(&folio->_deferred_list)) { + if (folio_order(folio) > 1 && + !list_empty(&folio->_deferred_list)) { ds_queue->split_queue_len--; list_del(&folio->_deferred_list); } @@ -3165,6 +3168,9 @@ void folio_undo_large_rmappable(struct folio *folio) struct deferred_split *ds_queue; unsigned long flags; + if (folio_order(folio) <= 1) + return; + /* * At this point, there is no one trying to add the folio to * deferred_list. If folio is not in deferred_list, it's safe @@ -3190,7 +3196,12 @@ void deferred_split_folio(struct folio *folio) #endif unsigned long flags; - VM_BUG_ON_FOLIO(folio_order(folio) < 2, folio); + /* + * Order 1 folios have no space for a deferred list, but we also + * won't waste much memory by not adding them to the deferred list. + */ + if (folio_order(folio) <= 1) + return; /* * The try_to_unmap() in page reclaim path might reach here too, diff --git a/mm/internal.h b/mm/internal.h index 2b7efffbe4d7..c4853ebfa030 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -420,8 +420,7 @@ static inline struct folio *page_rmappable_folio(struct page *page) { struct folio *folio = (struct folio *)page; - if (folio && folio_order(folio) > 1) - folio_prep_large_rmappable(folio); + folio_prep_large_rmappable(folio); return folio; } diff --git a/mm/readahead.c b/mm/readahead.c index 1e74455f908e..130c0e7df99f 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -514,9 +514,6 @@ void page_cache_ra_order(struct readahead_control *ractl, /* Don't allocate pages past EOF */ while (index + (1UL << order) - 1 > limit) order--; - /* THP machinery does not support order-1 */ - if (order == 1) - order = 0; err = ra_alloc_folio(ractl, index, mark, order, gfp); if (err) break; From patchwork Mon Feb 26 20:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13572835 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 3B022C48BF6 for ; Mon, 26 Feb 2024 20:56:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB0344401BE; Mon, 26 Feb 2024 15:56:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A614E44017F; Mon, 26 Feb 2024 15:56:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C2B44401BE; Mon, 26 Feb 2024 15:56:14 -0500 (EST) 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 6FA3644017F for ; Mon, 26 Feb 2024 15:56:14 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 42F3A1C024F for ; Mon, 26 Feb 2024 20:56:14 +0000 (UTC) X-FDA: 81835162668.19.7D32008 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by imf30.hostedemail.com (Postfix) with ESMTP id 58A4080010 for ; Mon, 26 Feb 2024 20:56:12 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=YuhI4fCt; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=glx5DJxV; spf=pass (imf30.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708980972; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=M9xzwbyGsmIoI4XohAUvU/zFDUrkDEXSepsOn39+bAw=; b=eNH51IeF20SksVnfUini1Xn4w3SNwYtX+ddu5q24crytC1+m+3lcASCYIJmxvoH6kc8cbk F7OVLQgiiCJXfKy7flxHdSty7CpgoSsRBUjouSzmYuZ98YGtj0x7t7GlyAC4lC+mozofKh 9enocIKenJ14D84dpkFw4nKei4ejWl8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708980972; a=rsa-sha256; cv=none; b=Y7+jHcAQsX/D5k0E0ct6Tdw/mrR/zfyn00s8Tm5TZlhIRoQcOlrl01qLsbobNh7jx565TU OkJg+1jh69fE67Prg7/MPv5mjkL2T5/bJ8tzPUvy4Kdrx2hnwLpwE7XAGhYrtSYmee5/e+ GK2TKbZEsTBynxXnEgPXyZqd23FyPgo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=YuhI4fCt; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=glx5DJxV; spf=pass (imf30.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id B3D865C0048; Mon, 26 Feb 2024 15:56:11 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 26 Feb 2024 15:56:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm1; t= 1708980971; x=1709067371; bh=M9xzwbyGsmIoI4XohAUvU/zFDUrkDEXSeps On39+bAw=; b=YuhI4fCtxyT7k5hVmSOEXMQbymAhui8JNegspEpvv/VYXQL41Ft pj6ydaFD0U8iL9cudlW457UYRQv8fEQ15V4gtUgJTlULXYCw1W+oHH7tpowniDfd 72lYDV66Ftv8Dihhg5hNlSrvNKyVSES3im67x3NJFo9TOSe5pkEVgSN0kxnXz9iS a2jmX5OXUupg8j2TZ0Wn/rQuxuqFPctJ3PsIQ2HiU53bTckPiZG5ROcg/fK+r2rp J4N6AHpbL4atGUiQ8tXxdfMqi+gal2Qc5fnKvro8o51nEGdfoFOOE+iuAKvvsSRv 7s4EaXf/bQ1fq/pkTQTq+ZndUEfxw8ypyqw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1708980971; x=1709067371; bh=M9xzwbyGsmIoI4XohAUvU/zFDUrkDEXSeps On39+bAw=; b=glx5DJxVZIKumkxaIHAXIDP5YXKd5Im2fQ/t9CFv2OmBqMUwTJS SnpR5h2I0Ej/cY1kh6BRa4tCtDUgFzifVy7a/5qEul1MiRrxi9sq7VEewBj2bGwE dl13XHV1xbfKMBo+3KRdI7QlYUMK59X0qZ9IVut7HFp7dV5/IoM/cAxgFwQFdVgm Z77LLs9kJU8sYOmfV9Zm8ZvyR7hriEWUq3flyWvA0MM8r3mveLfT/qRIzqOHuvau llFl9HkR6kH1cToAl2JyeQsEJvO7f92ZErYrt3vo0FlHbsQmiSfga0yHN7qGhXbd lq6rkbeM3LiWAQWYeyS6T1JVDO69Ksg7fzw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgedvgddugedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 26 Feb 2024 15:56:10 -0500 (EST) From: Zi Yan To: "Pankaj Raghav (Samsung)" , linux-mm@kvack.org Cc: Zi Yan , "Matthew Wilcox (Oracle)" , David Hildenbrand , Yang Shi , Yu Zhao , "Kirill A . Shutemov" , Ryan Roberts , =?utf-8?q?Michal_Koutn=C3=BD?= , Roman Gushchin , "Zach O'Keefe" , Hugh Dickins , Luis Chamberlain , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v5 3/8] mm/memcg: use order instead of nr in split_page_memcg() Date: Mon, 26 Feb 2024 15:55:29 -0500 Message-ID: <20240226205534.1603748-4-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226205534.1603748-1-zi.yan@sent.com> References: <20240226205534.1603748-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Stat-Signature: gw3fybai3nup7xxb7atjug877kk3subo X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 58A4080010 X-Rspam-User: X-HE-Tag: 1708980972-884357 X-HE-Meta: U2FsdGVkX1/6UoFjiWDRLkc8D4NtrM7e1Y4KiEkOxn6rf5h2buuSiPMeBBYfYr1KqEsYzMSRsvm1WGbI04dSrIjqe9D+iGbWx8i5XVT6TxLoxFnPXck25W2XRh06JQr17gFtt74iPrO+qfSPjTcgDWDW6BGQb0Ir9q4SdjDbfNzhuhtJ7wX57G6Lt8XtP+EpDN778t+ois/6kovuuvbm/64eduPVH+UPYyye2RpQp3h1zHuFI9hcqEn3cb29owywTNAPY+iYI2uwe9jUBRewu5E+nluZLervtkQrUt0rr2QTEDqHCBajw0ckaG0/2mcRdw2RxOorwC2hj9Q4IQVfrQdHpRQLB6agqd1vmcT24EjudLKZCsjhkuCBqRFd5Th3BQuqbpKkIkYBapjTJ7hgY3qBDiwu8a1hVJAhGrl6g34xDiPzTnEt2Jab+WxD+4zbRtr+AJHJWvxdOs4FzMq+6lQzRk1fpah1+fu/tqz5yt6Nlwl0u8/O/bIQPY5oqs3lMH9SHRz8YbErkB5z48x7TFkhe9ql+7LpcDA66v2zRo5gCydre/PuYvCTyUuMrJo0yqbsxtWNJDbOt31s6ArKZ3k8Pi39pQrzwypSppaNEs0L7fHl9VLo48YVp4s0cx8vIjvNa9z9QVtu8I6XXi1B5yjruk9N/ozL+Gx6KlULZvBBPHmryP+ohDaH766EwqgZMHVJf6ym2oXm2tw4KidSOSJVhWc4iOvEU12brPEEv4pBufyfyugMy+q3zSTjgSX3of9eJ5TOyzd2A5DJvGU0KHrJVyTgaYinswAidhZAEK5icdCDlJzKiia4ZgQUvO0gc3OIIWMYTf7w7F/ApkqSPmdw95rEJ5OipQOnAA8Rx2FayOCmMUoGZufJQ14KNhPZaw39dhpSxkQFZwhSzSq41PnALD0L1ezawOD7xaVcnRFrAvjCTrGCrF5m3e7jSFZemoyS/49HFS9j8F0tyX0 F2ryZW0l ZxgW0vEu+aVYoySuVvGgbH85emBPQ4f49/ermrJao+Vd65fZLVgSZMMlpUqAik2Tqq//dvKizJcQgHsAJB+L2BV9FqtCceOBe7pIW9qYQl8djwDV+KyWHB/JS+XOpPlDxzVK7cg7ZZPPxIdTSk8XTeEUIxg== 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: Zi Yan We do not have non power of two pages, using nr is error prone if nr is not power-of-two. Use page order instead. Signed-off-by: Zi Yan Acked-by: David Hildenbrand --- include/linux/memcontrol.h | 4 ++-- mm/huge_memory.c | 5 +++-- mm/memcontrol.c | 3 ++- mm/page_alloc.c | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 4e4caeaea404..173bbb53c1ec 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1163,7 +1163,7 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm, rcu_read_unlock(); } -void split_page_memcg(struct page *head, unsigned int nr); +void split_page_memcg(struct page *head, int order); unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, gfp_t gfp_mask, @@ -1621,7 +1621,7 @@ void count_memcg_event_mm(struct mm_struct *mm, enum vm_event_item idx) { } -static inline void split_page_memcg(struct page *head, unsigned int nr) +static inline void split_page_memcg(struct page *head, int order) { } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9840f312c08f..96ac7c62c375 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2889,11 +2889,12 @@ static void __split_huge_page(struct page *page, struct list_head *list, struct lruvec *lruvec; struct address_space *swap_cache = NULL; unsigned long offset = 0; - unsigned int nr = thp_nr_pages(head); int i, nr_dropped = 0; + int order = folio_order(folio); + unsigned int nr = 1 << order; /* complete memcg works before add pages to LRU */ - split_page_memcg(head, nr); + split_page_memcg(head, order); if (folio_test_anon(folio) && folio_test_swapcache(folio)) { offset = swp_offset(folio->swap); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 95c3fccb321b..1a09f0e77c44 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3608,11 +3608,12 @@ void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size) /* * Because page_memcg(head) is not set on tails, set it now. */ -void split_page_memcg(struct page *head, unsigned int nr) +void split_page_memcg(struct page *head, int order) { struct folio *folio = page_folio(head); struct mem_cgroup *memcg = folio_memcg(folio); int i; + unsigned int nr = 1 << order; if (mem_cgroup_disabled() || !memcg) return; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 96839b210abe..a7a96bc97e0b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2653,7 +2653,7 @@ void split_page(struct page *page, unsigned int order) for (i = 1; i < (1 << order); i++) set_page_refcounted(page + i); split_page_owner(page, 1 << order); - split_page_memcg(page, 1 << order); + split_page_memcg(page, order); } EXPORT_SYMBOL_GPL(split_page); @@ -4840,7 +4840,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order, struct page *last = page + nr; split_page_owner(page, 1 << order); - split_page_memcg(page, 1 << order); + split_page_memcg(page, order); while (page < --last) set_page_refcounted(last); From patchwork Mon Feb 26 20:55:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13572836 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 641DCC5478C for ; Mon, 26 Feb 2024 20:56:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BB354401BF; Mon, 26 Feb 2024 15:56:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 57FB444017F; Mon, 26 Feb 2024 15:56:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F81F4401BF; Mon, 26 Feb 2024 15:56:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 22D4844017F for ; Mon, 26 Feb 2024 15:56:15 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 02DE4160888 for ; Mon, 26 Feb 2024 20:56:14 +0000 (UTC) X-FDA: 81835162710.10.8F6B354 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by imf05.hostedemail.com (Postfix) with ESMTP id 29FEA100008 for ; Mon, 26 Feb 2024 20:56:12 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=PsGtgEud; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=MXQaLIK2; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf05.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708980973; a=rsa-sha256; cv=none; b=J/AWXy+98xo55ddtCLV6wYxURejMMZl4AQ4CScbHDeOQse58qFnnCdxSD1bpKKJQnvp8+F t3eeqJcIuRF0FN1Kz7Fn3/1IsBh5w2WO1mmRvRrS6PotnGJzIx0qrEnYWG2E86T/YpxI/s qYJ7wps/SmAXhp6AE6p++9i3Zmb5buc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=PsGtgEud; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=MXQaLIK2; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf05.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708980973; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=k4tW1Ix2BuSNkN1WHXYSmN5X0ZeSMgYeZ0gG0yp9vIY=; b=ef+HYr9yCVeHw+TrpVqbcf5pfgXgz8wNMyAk2qtw9bNbBsQ5fDujRBdqF/2PvC0grTfjUo IpN+zJk3uJOhCXeI8ZFnXpV8F1KZUVu3VZxywMe4K+QPU9UopzG/FDviUIRLY9eqU/C7+M mPlrYMe9M67Eh6+UU3h6E2t5h7CsxzI= Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 845035C0083; Mon, 26 Feb 2024 15:56:12 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 26 Feb 2024 15:56:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm1; t= 1708980972; x=1709067372; bh=k4tW1Ix2BuSNkN1WHXYSmN5X0ZeSMgYeZ0g G0yp9vIY=; b=PsGtgEudtl5OWZIMN/QmYcFTzFIwskYJv2SShnXgHjfbIBRHd6c tLFxkANerh0TDSw0aIJ+BRFw3TtwrtnEWmHqtjReaka5XRT4kCVu+/JxTHJUARVP TTaS/ervzETdMoGvlOvQkGU5Vr8k5tDe2HWq4O22UqWyxXceqtEs8oF4xp6w3ILj E+Nn7cDMv2KP+WObR1wfXgZt4SVjLn62IgkbUTVyraMDgD4LC0tnPeSgCrhiQXlI dpijTzey8JMArvsD76watmwYOLbgBoLoa6lmS0djEggreXdhpxLkoa+zAeqDTiVh XpV3/H7xUFtWwTsw2W+RLI8tAthTa0kVP7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1708980972; x=1709067372; bh=k4tW1Ix2BuSNkN1WHXYSmN5X0ZeSMgYeZ0g G0yp9vIY=; b=MXQaLIK2tOLWX7tSDG9quAtyz0XtE5uEWLvjXAt6WWz4fuCtIq+ iW5V2mlkR6XtmBDh4IXp0NZH4C8YwuqKervIeM/9EVpHBYcPoWcIkSre/3nQS4z4 deN9QC9eqGj98qO7roEFIt9SV8tO7akXARi4gsDw06jxzAwz5zubvukbV7i4gDO/ zRNBPrfZQzljXqj9vbHt0+V2dLDxewtoVWSQgxCBKRL013TC1g1nj0dxzgkun57/ ZLz8/iUoCZO+anVVQtkHxMUVyw526I4oYS5ikt412Vg+KTvUHxFRAI9uUJp+t7bp th0cOJ+ulQTE92LtOYFZ9c3xS3VyDo9UjLA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgedvgddugedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 26 Feb 2024 15:56:11 -0500 (EST) From: Zi Yan To: "Pankaj Raghav (Samsung)" , linux-mm@kvack.org Cc: Zi Yan , "Matthew Wilcox (Oracle)" , David Hildenbrand , Yang Shi , Yu Zhao , "Kirill A . Shutemov" , Ryan Roberts , =?utf-8?q?Michal_Koutn=C3=BD?= , Roman Gushchin , "Zach O'Keefe" , Hugh Dickins , Luis Chamberlain , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v5 4/8] mm/page_owner: use order instead of nr in split_page_owner() Date: Mon, 26 Feb 2024 15:55:30 -0500 Message-ID: <20240226205534.1603748-5-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226205534.1603748-1-zi.yan@sent.com> References: <20240226205534.1603748-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 29FEA100008 X-Stat-Signature: kzxeowgaouspis8dq8mjziedtb48dx9z X-HE-Tag: 1708980972-573880 X-HE-Meta: U2FsdGVkX1/oc6UZ2vLKWNERDxoAzHLw2M85FjYAPL+SGXYhynITepM0TARHzGNPKoIr31Tntb0ODrsV6VG9tjUEwhl64NmymHwF8mY+ZHfQO0hmSXez81lZkBt3w/BARYgAzArECRMmRl3UPUHMa3XIl4/mQ0T9ypN3h0Lwu88GGnC5MgKybXdL1Lj08t/kJQ7zTDkyRfQEmAtwNOOWSZCfmeCJePORlFf1iiTSgMkJosInQZdTw79KNY3zb/wrqhVhmFlcMv1+IMu0axzJeKEE0ReKLMbojkhNxj75VCeic/Qp2KPzkY1uYppkDJqsyW3c82FJ+9mfKbGDLrgr04OKMhW3BhOKLBoxDv0gE+fD7hIeeenl5sDodgcZhzscZ+9aDDBICKRntCBtLTLzGrC10BPGICR6KdHh2hdo//D/CV/uAw5RCty3LTCyqfxv8V7SrsKhIprm9cauwgKqpDqJjtHnJDzVrQ2Usn15yUSKE2N12q0EIWyv9pI/gdBm6uZEbWfd0v1G/BAEap02RHMkm7H57w1pIGvvVNHcm1PE/4kJPUcp0ewu29ki53gYgm5V7e/jH/1GT1mJ3/kATen/gFod/X2dhvahiCoQ+4lnphEX6BNFC70xOW49qFquvtgCxXb7JAvGWqoZpQi/dAsb7gdwaUFONcjp1h7NUSR58eNggfA2yPDL89TZI5ygEU3Evr+8YCcBbMAv2YwCI5zkWQ5EcAl7CM6K0g/ku38uLNDTXr7Pw8I58WtP0txQsZh0IyFxz1n6uK4qafA3xeAmiqKT8wB/yf4E5Oq5m6jcBiKMHjxqc/9H0HFdT/WWfeEJDoZSSEwiprTXV3HbVdNfSoKpcf78Gj1tzjti1Mor4v//yaRmUohLSjmKiw+pEsgFtS9UsqRkzo8Nc/fRwxG1oth6ExZKHSAe0YsCxL1YzW9agvPuqKzOph44fsiRQZfDBFju7DmrsuMBZnb F1dlvU9o RLmas8EmJ+tQXOSabHRL0sUnVO0LeuHJpESk+WfSQVCRMlRRPsrlu0gJsqG/GaWqzTwUVG6cujGAFY7e27P9ulDdSNlNAzH1DRwDbSW4vm2FSQzuA8dzQq/5oOHR/BxJExP6oTsXhuxev8LYhfHvjSDiQsw== 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: Zi Yan We do not have non power of two pages, using nr is error prone if nr is not power-of-two. Use page order instead. Signed-off-by: Zi Yan Acked-by: David Hildenbrand --- include/linux/page_owner.h | 9 ++++----- mm/huge_memory.c | 2 +- mm/page_alloc.c | 4 ++-- mm/page_owner.c | 3 ++- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/page_owner.h b/include/linux/page_owner.h index 119a0c9d2a8b..2b39c8e19d98 100644 --- a/include/linux/page_owner.h +++ b/include/linux/page_owner.h @@ -11,7 +11,7 @@ extern struct page_ext_operations page_owner_ops; extern void __reset_page_owner(struct page *page, unsigned short order); extern void __set_page_owner(struct page *page, unsigned short order, gfp_t gfp_mask); -extern void __split_page_owner(struct page *page, unsigned int nr); +extern void __split_page_owner(struct page *page, int order); extern void __folio_copy_owner(struct folio *newfolio, struct folio *old); extern void __set_page_owner_migrate_reason(struct page *page, int reason); extern void __dump_page_owner(const struct page *page); @@ -31,10 +31,10 @@ static inline void set_page_owner(struct page *page, __set_page_owner(page, order, gfp_mask); } -static inline void split_page_owner(struct page *page, unsigned int nr) +static inline void split_page_owner(struct page *page, int order) { if (static_branch_unlikely(&page_owner_inited)) - __split_page_owner(page, nr); + __split_page_owner(page, order); } static inline void folio_copy_owner(struct folio *newfolio, struct folio *old) { @@ -59,8 +59,7 @@ static inline void set_page_owner(struct page *page, unsigned int order, gfp_t gfp_mask) { } -static inline void split_page_owner(struct page *page, - unsigned short order) +static inline void split_page_owner(struct page *page, int order) { } static inline void folio_copy_owner(struct folio *newfolio, struct folio *folio) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 96ac7c62c375..2b95dbc95fae 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2933,7 +2933,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, unlock_page_lruvec(lruvec); /* Caller disabled irqs, so they are still disabled here */ - split_page_owner(head, nr); + split_page_owner(head, order); /* See comment in __split_huge_page_tail() */ if (PageAnon(head)) { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a7a96bc97e0b..eae77e76a671 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2652,7 +2652,7 @@ void split_page(struct page *page, unsigned int order) for (i = 1; i < (1 << order); i++) set_page_refcounted(page + i); - split_page_owner(page, 1 << order); + split_page_owner(page, order); split_page_memcg(page, order); } EXPORT_SYMBOL_GPL(split_page); @@ -4839,7 +4839,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order, struct page *page = virt_to_page((void *)addr); struct page *last = page + nr; - split_page_owner(page, 1 << order); + split_page_owner(page, order); split_page_memcg(page, order); while (page < --last) set_page_refcounted(last); diff --git a/mm/page_owner.c b/mm/page_owner.c index e56c1e92eccf..b678f7a6e702 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -306,11 +306,12 @@ void __set_page_owner_migrate_reason(struct page *page, int reason) page_ext_put(page_ext); } -void __split_page_owner(struct page *page, unsigned int nr) +void __split_page_owner(struct page *page, int order) { int i; struct page_ext *page_ext = page_ext_get(page); struct page_owner *page_owner; + unsigned int nr = 1 << order; if (unlikely(!page_ext)) return; From patchwork Mon Feb 26 20:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13572837 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 D89ECC54E49 for ; Mon, 26 Feb 2024 20:56:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46E844401C0; Mon, 26 Feb 2024 15:56:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AD7244017F; Mon, 26 Feb 2024 15:56:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 160D34401C0; Mon, 26 Feb 2024 15:56:16 -0500 (EST) 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 EC51E44017F for ; Mon, 26 Feb 2024 15:56:15 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C797AA07A5 for ; Mon, 26 Feb 2024 20:56:15 +0000 (UTC) X-FDA: 81835162710.04.DFDDBC5 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by imf16.hostedemail.com (Postfix) with ESMTP id E768D180013 for ; Mon, 26 Feb 2024 20:56:13 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=G0xdGaA+; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="pUr2/5uN"; spf=pass (imf16.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708980974; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7C1YvLv3wVMtcqo8/X9e6+Vvqy6Z7pLbOms0IX3NOhM=; b=I9K9vkg4XcXi+51WMwY+E/5ldYOhYfpeKZoYU+KTKw+U+IGndlcg//eHtnih6veGPmV6CU uknEStC34GD2KKPxp8JrrSUH5W++9K9jd7AB+ApZIGUD0stfJ0yVh9fg7KpMfkDTy6Rpa6 CH1lMKDmkmtgKaQGHrRN/BdIvnBsIIs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708980974; a=rsa-sha256; cv=none; b=4qRPgm3IpZtRhUFriIuzWTk6ulEORacekU3JgGSa03Sb/dtnZfiW1u3/esBCRq0IlLG1N3 0iDTF1oMIjs3+G9p1qZnx/rC0JU3LR1JAIfwTs4FcE1WdyAOyUyN8vpbTNtYJ3Q5QBhCYt wJUjdWdeO5647Fi/R8Akd7SIyNnsSOY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=G0xdGaA+; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="pUr2/5uN"; spf=pass (imf16.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id 5D5415C00A6; Mon, 26 Feb 2024 15:56:13 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 26 Feb 2024 15:56:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm1; t= 1708980973; x=1709067373; bh=7C1YvLv3wVMtcqo8/X9e6+Vvqy6Z7pLbOms 0IX3NOhM=; b=G0xdGaA+uEkADF+wiXa48pt3PQhHb+De9LVKL4DkWp2f+BkyswB Xn0t6TOeQSMlGCZdWmNVwylDGYEGktrxuMzFQ6HjOK0MgYNC/7rkylv7Zf+1m5hz WNatQYLZu4uE3JehluNE2U1hIC66n0giMdDi9+Dw1BhO1Ndg1P82kkDw8ZleMrtm U8A4n7JXXdSwUD4c4a3Ujlj5O3YEjmLM9MAPwBym1VgjGgJyWjEtFDOot+p3UklT HD4LQVHaNLIlmjhmMVr1SI/xsVtZ7vCbEiu6KIwctGI9/rAX38UwjVN8OY/1io20 RqLO8O8vhG7XRsTaPZjD+bm5Fgt+VbrLghw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1708980973; x=1709067373; bh=7C1YvLv3wVMtcqo8/X9e6+Vvqy6Z7pLbOms 0IX3NOhM=; b=pUr2/5uN/u4JfGEQtK5c/fXMKwAQ1WngoArkr9zDevWWHLryFC2 +D9ry22gMXo9f5eRO4YyqaeFMMZHFj84Cv6cgMhfxiQIi0/0XSQ83NhjHGbF+CXm PZvsiMitxw6gqKPR62nWCTs/I1sLcl0aUjVClavOJ5CWyDFz8+YcmtJY6+oz5ZcU 7j8/Tzrq/ObfcsJ5RuinS2fSzLBOVEeBxv2iiDl0uOxuXBrstQHXJW2+3iu9Kf0H uf8RzWoc+ZGH9l3aKlRJFL6qKLp0Omq0O/7Lv6QvdzHaBH7ziXbcBJ09Ee3iI4fc qLjBZ3qTLfgOzj1Afn7XMInHh76ed8My0/A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgedvgddugedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 26 Feb 2024 15:56:12 -0500 (EST) From: Zi Yan To: "Pankaj Raghav (Samsung)" , linux-mm@kvack.org Cc: Zi Yan , "Matthew Wilcox (Oracle)" , David Hildenbrand , Yang Shi , Yu Zhao , "Kirill A . Shutemov" , Ryan Roberts , =?utf-8?q?Michal_Koutn=C3=BD?= , Roman Gushchin , "Zach O'Keefe" , Hugh Dickins , Luis Chamberlain , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v5 5/8] mm: memcg: make memcg huge page split support any order split. Date: Mon, 26 Feb 2024 15:55:31 -0500 Message-ID: <20240226205534.1603748-6-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226205534.1603748-1-zi.yan@sent.com> References: <20240226205534.1603748-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Stat-Signature: d1t7nzzigadq96ehxitecuc8983q5cbg X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: E768D180013 X-Rspam-User: X-HE-Tag: 1708980973-563147 X-HE-Meta: U2FsdGVkX1++awubJtHekgtIIOt9khOWCjSZkPrIHMOCCW1fQwdLOfOtx7imWpO2Kr88aAfxLnuYnxouIJOjW6fXSKoKBTJR8tx6oA1Xx1I7jyPSqlzmlmMtCKnyxYa0IAnsevpcCQPnUBpZC602UQnmIY3UhndSD1PxR7lyTpKD9j7e77kTzadon2CL/OSX9upg0McKp9X6CJMAtWnGR+/aI4YeT3JxqaS21nf2PKQrssnVX8efKcmouiBwYJPmPRr23pYlj3SVPH+LykiCpoDBoZtrkuJsE2rMbT3ekT/H9ihzHnq3XT55703DJQRgvcBfpm0Pn+LELFwBsbFqnUlzpLl+NzDkSFqx8XXzwPViVIyLJY5zUBx0yQJV/rc/JIiTERzmCNqki3ZMyiZjn6rbasNDgNL+rLYo04q/L9+Le0QITUT9XpV88G7T7/E29M/Sx/SgUjOlIvJWKV0u4w94jP8NKaJL0SCGIHc5n9YPlcrO++xIopr/rZZq2NjFsx7+t3uSHCVJ5C9CjVKoscDEY+jPohZfwQZ2goC4h2LxyA82tP4DLiaWxtkY8vhhRM2G6vYhv7c0LNX7/HC9mzO5t8FiS+133oRA4jT40WzFMIHbxnWlDPCcyeaxOXs5+rFcCHWzP3/19IGds6SXoA8igcYb1viIE9xK9sXXw2tTVj9EEuo4KgTZGho3EOowHQwf4NmXjux+Kio/xnbBGuIiafF+pqnOSVU4JYxBJP4mKJ9ufRcp9s55qcz687AzWuenX8sbLR4DFILD2ZaB7paZWMCt6grfAp/vqZU1k8mNU2/4MjqEvXEz1p8IZ7761HICZ+kn8n42GavTSS+aUkBIc3PJNmsfCPuFymqUuqUF/QM8tjgkxUOLJaUOnKMwZQZ2czJLNflakXObcaP73fW+QVGshOP4BNCubesh9XVEInAB38J5FWk5tJkM0jZ9gv3du0OG9EVzUKkt28b ObZPOciJ s/iZHDy/vw0BDiloq73ZPAAru/5BC2ejpZAvcXkh4AJmHUu4XO5V2cN8m6Na4sxakbXIJ1dHjvdOkr3G0aVyzuvOXcK/vA97MnjNxiAn9hB7C1zg= 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: Zi Yan It sets memcg information for the pages after the split. A new parameter new_order is added to tell the order of subpages in the new page, always 0 for now. It prepares for upcoming changes to support split huge page to any lower order. Signed-off-by: Zi Yan Acked-by: David Hildenbrand --- include/linux/memcontrol.h | 4 ++-- mm/huge_memory.c | 2 +- mm/memcontrol.c | 11 ++++++----- mm/page_alloc.c | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 173bbb53c1ec..9a2dea92be0e 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1163,7 +1163,7 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm, rcu_read_unlock(); } -void split_page_memcg(struct page *head, int order); +void split_page_memcg(struct page *head, int old_order, int new_order); unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, gfp_t gfp_mask, @@ -1621,7 +1621,7 @@ void count_memcg_event_mm(struct mm_struct *mm, enum vm_event_item idx) { } -static inline void split_page_memcg(struct page *head, int order) +static inline void split_page_memcg(struct page *head, int old_order, int new_order) { } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 2b95dbc95fae..5d4b7c17b9bc 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2894,7 +2894,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, unsigned int nr = 1 << order; /* complete memcg works before add pages to LRU */ - split_page_memcg(head, order); + split_page_memcg(head, order, 0); if (folio_test_anon(folio) && folio_test_swapcache(folio)) { offset = swp_offset(folio->swap); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1a09f0e77c44..669bc8de3780 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3608,23 +3608,24 @@ void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size) /* * Because page_memcg(head) is not set on tails, set it now. */ -void split_page_memcg(struct page *head, int order) +void split_page_memcg(struct page *head, int old_order, int new_order) { struct folio *folio = page_folio(head); struct mem_cgroup *memcg = folio_memcg(folio); int i; - unsigned int nr = 1 << order; + unsigned int old_nr = 1 << old_order; + unsigned int new_nr = 1 << new_order; if (mem_cgroup_disabled() || !memcg) return; - for (i = 1; i < nr; i++) + for (i = new_nr; i < old_nr; i += new_nr) folio_page(folio, i)->memcg_data = folio->memcg_data; if (folio_memcg_kmem(folio)) - obj_cgroup_get_many(__folio_objcg(folio), nr - 1); + obj_cgroup_get_many(__folio_objcg(folio), old_nr / new_nr - 1); else - css_get_many(&memcg->css, nr - 1); + css_get_many(&memcg->css, old_nr / new_nr - 1); } #ifdef CONFIG_SWAP diff --git a/mm/page_alloc.c b/mm/page_alloc.c index eae77e76a671..c31a468fe317 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2653,7 +2653,7 @@ void split_page(struct page *page, unsigned int order) for (i = 1; i < (1 << order); i++) set_page_refcounted(page + i); split_page_owner(page, order); - split_page_memcg(page, order); + split_page_memcg(page, order, 0); } EXPORT_SYMBOL_GPL(split_page); @@ -4840,7 +4840,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order, struct page *last = page + nr; split_page_owner(page, order); - split_page_memcg(page, order); + split_page_memcg(page, order, 0); while (page < --last) set_page_refcounted(last); From patchwork Mon Feb 26 20:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13572838 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 67F68C5478C for ; Mon, 26 Feb 2024 20:56:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D1774401C1; Mon, 26 Feb 2024 15:56:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 556A644017F; Mon, 26 Feb 2024 15:56:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 385CF4401C1; Mon, 26 Feb 2024 15:56:17 -0500 (EST) 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 2333C44017F for ; Mon, 26 Feb 2024 15:56:17 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EFA4FC070C for ; Mon, 26 Feb 2024 20:56:16 +0000 (UTC) X-FDA: 81835162752.23.8EDB032 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by imf18.hostedemail.com (Postfix) with ESMTP id DAC101C0007 for ; Mon, 26 Feb 2024 20:56:14 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=iQ1P+dj1; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=RCNXSmar; spf=pass (imf18.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708980974; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=364J4ng7aCg7Ddk79ejWdMNIz/yxFIeeqLKxisnieh8=; b=JkgFBXqvz8kI6VxKSyBlvk6qoKYQVvj7UYSsbshES2AFcBYl+irfKknnT7EgYeHEYM7PV+ T53AI0WeEdPiCyIdJSUZSgdV1PQwjHFkNrbj6PZMv/nWsozw/qEZmFb4WNN/j/XcqHJOYx ZiJ+Ai90JcJhLL0zjS9l88ztcwJq6bk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708980975; a=rsa-sha256; cv=none; b=dBkJZvdEsRuvu7fduY1TWAqtV+poJ3CQA+8Z43gf+d2hHHcmYa8NaX9b5jZx9KGoCbgjmN wp6x65Ar+DUGg3bRPne3ZhanAKWXll1kMYlEjO31C5SR6OoCD6DsIESpBHfntq13Y6K45a jYWaAZK7WuzTbawMuRQNJdW9YQlX0RQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=iQ1P+dj1; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=RCNXSmar; spf=pass (imf18.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 3360F5C00A7; Mon, 26 Feb 2024 15:56:14 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 26 Feb 2024 15:56:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm1; t= 1708980974; x=1709067374; bh=364J4ng7aCg7Ddk79ejWdMNIz/yxFIeeqLK xisnieh8=; b=iQ1P+dj1L5/s3YJc1AKNrz35Mc/c79OX4NJp+G2orPz4GZ+6LiT Xl80k8xN21LpRMCUqHw/bricLLciGXJIDhrpnfKRnRXASyRj/2JSFN4K2fnQmLx4 FrzLW8FJUFxwuspkQ+PUdlePmPKJMPJKJuOxU18xO+9IBaOUczy0YQ501H9uXZF7 yx+zV3HFZazJhvZBqCxEJGTRstJ62E0PRnmswRs//ZJfMZigtnVa05ZfTxNl99hp F8TOxc0B9R/IzTp9ciw0z9o7/Obsa81fnnA9hPtSqKwfaqlQoIevp1JrNLQSMGyV UresGBjCtv29Vl3UPpQRa8D52ukRMbrzjZg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1708980974; x=1709067374; bh=364J4ng7aCg7Ddk79ejWdMNIz/yxFIeeqLK xisnieh8=; b=RCNXSmarRVqb3zv0tke5KZ3fUqf35Wlyl/Cana7FlGKAfeYU0Ni dojnphIkoCOr6OVG+Q2G4sxIQUcSOXY83fToHjB7zmqXFd61QY9M76vppmNyHcUA 9iRsIYi4cifrC6kHwcuTkhhUeeBeNkoqREbH4PP5nNsVc/FJnHFzqwxsASyU0Z2D HqAU3Xz/RIx9Bl7KKQpGkXgXg6PAao9Uas+FDGZcTWJf1E/Itn0q00daT+qTAJAu ZoaTWwAZ7CXgZECYTmPAYAFxhLwBEF3hFD3Oj9PeW2CChuj8fy8S6k1KaqtO/+md TCQZPteVnqHYenzMsDE7tB8TNyNqb2EoIsA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgedvgddugedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 26 Feb 2024 15:56:13 -0500 (EST) From: Zi Yan To: "Pankaj Raghav (Samsung)" , linux-mm@kvack.org Cc: Zi Yan , "Matthew Wilcox (Oracle)" , David Hildenbrand , Yang Shi , Yu Zhao , "Kirill A . Shutemov" , Ryan Roberts , =?utf-8?q?Michal_Koutn=C3=BD?= , Roman Gushchin , "Zach O'Keefe" , Hugh Dickins , Luis Chamberlain , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v5 6/8] mm: page_owner: add support for splitting to any order in split page_owner. Date: Mon, 26 Feb 2024 15:55:32 -0500 Message-ID: <20240226205534.1603748-7-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226205534.1603748-1-zi.yan@sent.com> References: <20240226205534.1603748-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Stat-Signature: fr9qxki71641os48mwy6gypjcur51u5b X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DAC101C0007 X-Rspam-User: X-HE-Tag: 1708980974-762690 X-HE-Meta: U2FsdGVkX1/XQPeHB4yNIxxJDdnX9wOmyUx/uXsU9ZHc1W9dRQ+sVyb10Jypisi0IxVCzJcC76UjI+jt33gd33F/wylXlOgfajSlEHThwp9zUUS+sspYeH/OiFOSEHawwp3RbNeNBe8HDXZMupa60694qZJkTo6sjBbwhueANRrWeI+SPwsSvF697CyA7goUYN3CIGJvMWpdKxZuCyuwaHJAFzdhp3lMnG8JozzCjg5fEY/YlsYXI28J3aiLuxCE5DLPoq7siCEmKVGYL5WmoL/nVkfyvxSCPNsu29nh7wHfnLBcZPRUuDWCxAsWmqTXSlbnFZXoTSMQmtX4co9bIjBoDhed3tBpXwpNuO5MDtlub4BjvoTk/Bafx07XTfcmi6Q5N9NqGtE4pbIN7Nd9if5woCy7fSyJ4d+jfNRDFfFhC0JkNZKjhU15HB2Dy5V1+YKoPFTWaohppmc6VD17KH5wbTAVjCNpahVq/FrYdZGkITPc1ZZE7ynTuty8vMwlnwa9UhgttrDYOdDM5tkCOdrVPS593qyCd4NtKVpdw/le12kH/FBURcZtz+73YzXLPbo91foLDcVYQx5Bb3GEMRqqK8ROHXf1r5mn6tfBibaKGLwIc/mb+pbcEj5QswxGd8U42tEfVP01HZCKbDM0BOzhbXKoxtMJctNrPZ3ldm9iXtR3LiGcm5sdwmPKHSjqFGPrDaj4+iMGB5+tZU/L0wpTwgyn7+m89Eq8+1cWtkhSvoWHWacONg7jY3QWiwprNCNNX3i1bBlv2I1oxLP5xe/59TtWWPX4qlY9gwtww/oJWtnSmn4bTRkUBSsAPLN/rtCSVpyAuJRiaWlH1e8YJHf+iShPpaWXrHe7C+jACabSu2RcCItxXOKJNHeLK8g89mVbejz/o2zzQYSsJekmXmxfo8b/cR/5N/qQcKzgdJuKnnp4lopD3oZsNonz9JWXoWBBoZvXP6rjsAOzOoa 69JP7n9b sj8K1yawuiYL04agMaqLQGrhc0boDgNRxaNOa9O0ugkiFIXVYyJVVZKj9IG3EVX+XkEf/+WJuODzZvd3HNzuVJNqJ2cOdPRLXVczz3xjCsmhD3durvTunppnNQDrriU0LkEkt4ixQyxeyPjscYU7yyARHAN/LajoY/yIrWN+6EPJkTl3IzBtmtt2vF2XKe3//uHwnFkLbSkoJgDFBgTTCdx6qjlFG7MM2urfKMba+2A2xHjFhP5thqMj+qdNv53S5TkZwMPx3zReyo+Hk1Gfju0IP37+s49rDbzrgEz9Dn4FP4mngOQ7J7HvXjYT5f21U8vyyWcrI6upsLxX2zwQ9kUVfC2vrdirPWGoH5EZSSk0rDhUd+LZvEA1Gqdh2BBmt0XC8iCzuKmAeOu95qCPM38YBAZ4BzsIeJIPHUELGf5wqTlMQ/NVE9Je7nMx7riA35GlZtYyoT7N4O7g/lM9hJlF2cdSVg1kOykA3JWWIGCIL8eL79LHc+YIrUl3lRBT6GCz6kd9LHC1tf7QcJQ2SkfQNWw== 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: Zi Yan It adds a new_order parameter to set new page order in page owner. It prepares for upcoming changes to support split huge page to any lower order. Signed-off-by: Zi Yan Acked-by: David Hildenbrand --- include/linux/page_owner.h | 13 ++++++++----- mm/huge_memory.c | 2 +- mm/page_alloc.c | 4 ++-- mm/page_owner.c | 7 +++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/linux/page_owner.h b/include/linux/page_owner.h index 2b39c8e19d98..debdc25f08b9 100644 --- a/include/linux/page_owner.h +++ b/include/linux/page_owner.h @@ -11,7 +11,8 @@ extern struct page_ext_operations page_owner_ops; extern void __reset_page_owner(struct page *page, unsigned short order); extern void __set_page_owner(struct page *page, unsigned short order, gfp_t gfp_mask); -extern void __split_page_owner(struct page *page, int order); +extern void __split_page_owner(struct page *page, int old_order, + int new_order); extern void __folio_copy_owner(struct folio *newfolio, struct folio *old); extern void __set_page_owner_migrate_reason(struct page *page, int reason); extern void __dump_page_owner(const struct page *page); @@ -31,10 +32,11 @@ static inline void set_page_owner(struct page *page, __set_page_owner(page, order, gfp_mask); } -static inline void split_page_owner(struct page *page, int order) +static inline void split_page_owner(struct page *page, int old_order, + int new_order) { if (static_branch_unlikely(&page_owner_inited)) - __split_page_owner(page, order); + __split_page_owner(page, old_order, new_order); } static inline void folio_copy_owner(struct folio *newfolio, struct folio *old) { @@ -56,10 +58,11 @@ static inline void reset_page_owner(struct page *page, unsigned short order) { } static inline void set_page_owner(struct page *page, - unsigned int order, gfp_t gfp_mask) + unsigned short order, gfp_t gfp_mask) { } -static inline void split_page_owner(struct page *page, int order) +static inline void split_page_owner(struct page *page, int old_order, + int new_order) { } static inline void folio_copy_owner(struct folio *newfolio, struct folio *folio) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 5d4b7c17b9bc..b2df788c11fa 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2933,7 +2933,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, unlock_page_lruvec(lruvec); /* Caller disabled irqs, so they are still disabled here */ - split_page_owner(head, order); + split_page_owner(head, order, 0); /* See comment in __split_huge_page_tail() */ if (PageAnon(head)) { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c31a468fe317..cc41341c08f4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2652,7 +2652,7 @@ void split_page(struct page *page, unsigned int order) for (i = 1; i < (1 << order); i++) set_page_refcounted(page + i); - split_page_owner(page, order); + split_page_owner(page, order, 0); split_page_memcg(page, order, 0); } EXPORT_SYMBOL_GPL(split_page); @@ -4839,7 +4839,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order, struct page *page = virt_to_page((void *)addr); struct page *last = page + nr; - split_page_owner(page, order); + split_page_owner(page, order, 0); split_page_memcg(page, order, 0); while (page < --last) set_page_refcounted(last); diff --git a/mm/page_owner.c b/mm/page_owner.c index b678f7a6e702..033e349f6479 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -306,19 +306,18 @@ void __set_page_owner_migrate_reason(struct page *page, int reason) page_ext_put(page_ext); } -void __split_page_owner(struct page *page, int order) +void __split_page_owner(struct page *page, int old_order, int new_order) { int i; struct page_ext *page_ext = page_ext_get(page); struct page_owner *page_owner; - unsigned int nr = 1 << order; if (unlikely(!page_ext)) return; - for (i = 0; i < nr; i++) { + for (i = 0; i < (1 << old_order); i++) { page_owner = get_page_owner(page_ext); - page_owner->order = 0; + page_owner->order = new_order; page_ext = page_ext_next(page_ext); } page_ext_put(page_ext); From patchwork Mon Feb 26 20:55:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13572839 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 00B1BC54E49 for ; Mon, 26 Feb 2024 20:56:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F3BA4401C2; Mon, 26 Feb 2024 15:56:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 752A044017F; Mon, 26 Feb 2024 15:56:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 558924401C2; Mon, 26 Feb 2024 15:56:18 -0500 (EST) 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 3D1E144017F for ; Mon, 26 Feb 2024 15:56:18 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 14BC71C03DE for ; Mon, 26 Feb 2024 20:56:18 +0000 (UTC) X-FDA: 81835162836.19.997B291 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by imf24.hostedemail.com (Postfix) with ESMTP id 21088180026 for ; Mon, 26 Feb 2024 20:56:15 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=Gn40UuZA; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=S45x2fml; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf24.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708980976; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GUAsk26iYl7MhG3zj5r2ZNKBhryTNauvcp1OLHy1WRg=; b=Ro/+UV9uzhzi/RNfQLSdzeEm9hYRPzPj74kiW75y1i+CWYYUd1LJmdMVN13TCOGx6s6Kii 3/40Ws9bmZG5WCGA+CSpD8TSQx+dwfP87tBVBMXwOfzeexdVWA77vlbPE9dfa849zHxe+i QqkUYkzM4kcscTjsKewudxY+f0lQ7yQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=Gn40UuZA; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=S45x2fml; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf24.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708980976; a=rsa-sha256; cv=none; b=ElYINTH4GJd/1Rfkseb0d5wG6VePc1v5Qha3SOO4kkqhVHIDW3E3fFOONRfWC0ezegDw24 xbRisyeqKuIGayj4mFwqfUf1+qL4yuUKKKfn091lUgH+xAYU2ymE+gRje+lzu+n4SVJZ+D +VPrgktz9ZnDg10TwR9XkyXut9g34BU= Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 604935C00AB; Mon, 26 Feb 2024 15:56:15 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 26 Feb 2024 15:56:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm1; t= 1708980975; x=1709067375; bh=GUAsk26iYl7MhG3zj5r2ZNKBhryTNauvcp1 OLHy1WRg=; b=Gn40UuZAhb5ftJv5LRfJMIhXiq3QdWSx1my35TaUWUEu5ycpFVl IS1nKksLaE2+5rqFt9FR61yW0wY7XwvHpf+SUo6qhQhShH+A+FcTOS9wAX2fsPau QoKk6zAp8765ulvAvY4C71FS+BcIRJdBJRNnNSQD4waUHzdg8UlfzS/xhYVMLy2p dkB2jOv9CG5Z5h42xNOoWRnOU4RvVZVDRLQzoiAfcAOXfCUnRv2mdsFTxDwlh33U gUD26EzxwbG+UnchZ/ABk3WgslLi3yyVXLaovONMbYb0pPySoO/QTltve1MhUD/X gI4tSKb+k2mm4W8u+DOD7nRY3ZYLSQfV//Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1708980975; x=1709067375; bh=GUAsk26iYl7MhG3zj5r2ZNKBhryTNauvcp1 OLHy1WRg=; b=S45x2fml7gmhnMQ2+nlEIwKLi14mFfBfranhr0+4tnF/Zhmlgn4 v0LkmfYJ3ECXF2pAUUe9H3JchTGeWe490haeAxfAt3SlvZhZlHfM1A7oTcxhBtep gsNUSoNiP4Rcf//o9VuNy1gCeFikjL4vGqD66vb/XXztiiuSW+gBQMDMJFSmiaas CUM3gCOiUd8fO8BTNnOWhbwjaAl7dGTRqMum3DwmP2exFekMylhIgyMrK/Rsq3HK CvpHvOvZtc/1ICI47XPcP9xuVAj+cXKgYn3fVBO+C40csgJ7gEAsz1vTC5idS+4F reG2E0mSnFLt4C9LVmZTuCWggrywN5smi5Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgedvgddugedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 26 Feb 2024 15:56:14 -0500 (EST) From: Zi Yan To: "Pankaj Raghav (Samsung)" , linux-mm@kvack.org Cc: Zi Yan , "Matthew Wilcox (Oracle)" , David Hildenbrand , Yang Shi , Yu Zhao , "Kirill A . Shutemov" , Ryan Roberts , =?utf-8?q?Michal_Koutn=C3=BD?= , Roman Gushchin , "Zach O'Keefe" , Hugh Dickins , Luis Chamberlain , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v5 7/8] mm: thp: split huge page to any lower order pages Date: Mon, 26 Feb 2024 15:55:33 -0500 Message-ID: <20240226205534.1603748-8-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226205534.1603748-1-zi.yan@sent.com> References: <20240226205534.1603748-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 21088180026 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 947oza89u4nrac7ri1o7gtoozai6iuzy X-HE-Tag: 1708980975-159033 X-HE-Meta: U2FsdGVkX1/kZCdyeehcNcTk4dxC6CmPf7lxoF3AE5etGijtvEcDv3h+udFrcjJZDtjmjKXdV/VVDK8n8VvnvCkkZ40qmZsViXfiSMMHRXwgfYYfmD7NzOgMDEBcRHIVRsU5a+Ld3BOisQEoJdZccdWX2SkuwOJKTaNI5m1NMSKo4Eie8gc8mustwf3jO45R7r8Jb4iTSTo8X0G91SEHwhL1qODB2BN5h501Vtxddo3j/JrXO0fVdHPCn0dzLz+xkSCbJx8eAsw0y/IZhq1mo9Kf3MBN1/X+TwBG884mNNCVrBBCedVFtQeVv8UaEWDfx1FMEuL9PcgFxe3tH4zZ7YIg3JBC6WVYJWvnAjQ0zKqXIE0/kP3SN9LuCeqvWiILkCppriliNpXMGe9hcOFHU+MXPxrvdVt0+tRq5+A9k/r8ArqvxGySI/LAUNxC9Lw5ywxCsEN9A0ISJLyG7XwGAyfjK3wn6bkXVnpUB8ujcVzisPmnHZk328KXYPwK5LNpA4iVktnzOsZ9csI8KcVZfDEI+8s6nuXVD933Gi2TO8ZEehVNN1NxkONcE9lZPHdvqvRtGWdeKpJql5ECibDtEj53LVCi+pomXAan5TJTH+AEWFz+tE7zbh8QrDtJ7QzaM5etTAOos2OpsFOwPm2lrKxvQLJmDKmX8IeDB4mtGLM3ZSRJC1WSqCOXTz1ZP8CJMjMNayp3K86A8J1tgiITuJhRAdmnSiV39TbVrEwniSu+tLizp2uYG398Qctm00Jzkzy+z95sKHG9wvbaHrZptBX0Ko3V0GTABYgvumZmzgl634GsluoZ39pMcyITWQ+2Oos1POHmWnMSKjdMSA8lAKOZaOZf1YlI/E/tbuhbMoSKU5KT+3qs5zTIKVl+kAeHbqWvP43MnDpLXgit7aK+LXAk9xuIrs8aXzUaQ8lAFPmLG9/64FkOvT7om8pCipkCc87rn/Rwip9By6XRTHO ZdDRzrSr +9siSfPyzd8B9uXC0x9Z8NGMBECaz0ZFKupbnXoCAo9KQpuLFp/eN0KBu2y1ej6wT62AxVGRCZ77lVjStVTHvwwGT7thWiZ4hbuWRWBpSPPdoKUg= 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: Zi Yan To split a THP to any lower order pages, we need to reform THPs on subpages at given order and add page refcount based on the new page order. Also we need to reinitialize page_deferred_list after removing the page from the split_queue, otherwise a subsequent split will see list corruption when checking the page_deferred_list again. Note: Anonymous order-1 folio is not supported because _deferred_list, which is used by partially mapped folios, is stored in subpage 2 and an order-1 folio only has subpage 0 and 1. File-backed order-1 folios are fine, since they do not use _deferred_list. Signed-off-by: Zi Yan --- include/linux/huge_mm.h | 21 +++++--- mm/huge_memory.c | 110 +++++++++++++++++++++++++++++++--------- 2 files changed, 99 insertions(+), 32 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 5adb86af35fc..de0c89105076 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -265,10 +265,11 @@ unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, void folio_prep_large_rmappable(struct folio *folio); bool can_split_folio(struct folio *folio, int *pextra_pins); -int split_huge_page_to_list(struct page *page, struct list_head *list); +int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, + unsigned int new_order); static inline int split_huge_page(struct page *page) { - return split_huge_page_to_list(page, NULL); + return split_huge_page_to_list_to_order(page, NULL, 0); } void deferred_split_folio(struct folio *folio); @@ -422,7 +423,8 @@ can_split_folio(struct folio *folio, int *pextra_pins) return false; } static inline int -split_huge_page_to_list(struct page *page, struct list_head *list) +split_huge_page_to_list_to_order(struct page *page, struct list_head *list, + unsigned int new_order) { return 0; } @@ -519,17 +521,20 @@ static inline bool thp_migration_supported(void) } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -static inline int split_folio_to_list(struct folio *folio, - struct list_head *list) +static inline int split_folio_to_list_to_order(struct folio *folio, + struct list_head *list, int new_order) { - return split_huge_page_to_list(&folio->page, list); + return split_huge_page_to_list_to_order(&folio->page, list, new_order); } -static inline int split_folio(struct folio *folio) +static inline int split_folio_to_order(struct folio *folio, int new_order) { - return split_folio_to_list(folio, NULL); + return split_folio_to_list_to_order(folio, NULL, new_order); } +#define split_folio_to_list(f, l) split_folio_to_list_to_order(f, l, 0) +#define split_folio(f) split_folio_to_order(f, 0) + /* * archs that select ARCH_WANTS_THP_SWAP but don't support THP_SWP due to * limitations in the implementation like arm64 MTE can override this to diff --git a/mm/huge_memory.c b/mm/huge_memory.c index b2df788c11fa..8b47a96a28f9 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2770,7 +2770,6 @@ static void lru_add_page_tail(struct page *head, struct page *tail, struct lruvec *lruvec, struct list_head *list) { VM_BUG_ON_PAGE(!PageHead(head), head); - VM_BUG_ON_PAGE(PageCompound(tail), head); VM_BUG_ON_PAGE(PageLRU(tail), head); lockdep_assert_held(&lruvec->lru_lock); @@ -2791,7 +2790,8 @@ static void lru_add_page_tail(struct page *head, struct page *tail, } static void __split_huge_page_tail(struct folio *folio, int tail, - struct lruvec *lruvec, struct list_head *list) + struct lruvec *lruvec, struct list_head *list, + unsigned int new_order) { struct page *head = &folio->page; struct page *page_tail = head + tail; @@ -2861,10 +2861,15 @@ static void __split_huge_page_tail(struct folio *folio, int tail, * which needs correct compound_head(). */ clear_compound_head(page_tail); + if (new_order) { + prep_compound_page(page_tail, new_order); + folio_prep_large_rmappable(new_folio); + } /* Finally unfreeze refcount. Additional reference from page cache. */ - page_ref_unfreeze(page_tail, 1 + (!folio_test_anon(folio) || - folio_test_swapcache(folio))); + page_ref_unfreeze(page_tail, + 1 + ((!folio_test_anon(folio) || folio_test_swapcache(folio)) ? + folio_nr_pages(new_folio) : 0)); if (folio_test_young(folio)) folio_set_young(new_folio); @@ -2882,7 +2887,7 @@ static void __split_huge_page_tail(struct folio *folio, int tail, } static void __split_huge_page(struct page *page, struct list_head *list, - pgoff_t end) + pgoff_t end, unsigned int new_order) { struct folio *folio = page_folio(page); struct page *head = &folio->page; @@ -2890,11 +2895,12 @@ static void __split_huge_page(struct page *page, struct list_head *list, struct address_space *swap_cache = NULL; unsigned long offset = 0; int i, nr_dropped = 0; + unsigned int new_nr = 1 << new_order; int order = folio_order(folio); unsigned int nr = 1 << order; /* complete memcg works before add pages to LRU */ - split_page_memcg(head, order, 0); + split_page_memcg(head, order, new_order); if (folio_test_anon(folio) && folio_test_swapcache(folio)) { offset = swp_offset(folio->swap); @@ -2907,8 +2913,8 @@ static void __split_huge_page(struct page *page, struct list_head *list, ClearPageHasHWPoisoned(head); - for (i = nr - 1; i >= 1; i--) { - __split_huge_page_tail(folio, i, lruvec, list); + for (i = nr - new_nr; i >= new_nr; i -= new_nr) { + __split_huge_page_tail(folio, i, lruvec, list, new_order); /* Some pages can be beyond EOF: drop them from page cache */ if (head[i].index >= end) { struct folio *tail = page_folio(head + i); @@ -2929,24 +2935,30 @@ static void __split_huge_page(struct page *page, struct list_head *list, } } - ClearPageCompound(head); + if (!new_order) + ClearPageCompound(head); + else { + struct folio *new_folio = (struct folio *)head; + + folio_set_order(new_folio, new_order); + } unlock_page_lruvec(lruvec); /* Caller disabled irqs, so they are still disabled here */ - split_page_owner(head, order, 0); + split_page_owner(head, order, new_order); /* See comment in __split_huge_page_tail() */ if (PageAnon(head)) { /* Additional pin to swap cache */ if (PageSwapCache(head)) { - page_ref_add(head, 2); + page_ref_add(head, 1 + new_nr); xa_unlock(&swap_cache->i_pages); } else { page_ref_inc(head); } } else { /* Additional pin to page cache */ - page_ref_add(head, 2); + page_ref_add(head, 1 + new_nr); xa_unlock(&head->mapping->i_pages); } local_irq_enable(); @@ -2958,7 +2970,15 @@ static void __split_huge_page(struct page *page, struct list_head *list, if (folio_test_swapcache(folio)) split_swap_cluster(folio->swap); - for (i = 0; i < nr; i++) { + /* + * set page to its compound_head when split to non order-0 pages, so + * we can skip unlocking it below, since PG_locked is transferred to + * the compound_head of the page and the caller will unlock it. + */ + if (new_order) + page = compound_head(page); + + for (i = 0; i < nr; i += new_nr) { struct page *subpage = head + i; if (subpage == page) continue; @@ -2992,29 +3012,36 @@ bool can_split_folio(struct folio *folio, int *pextra_pins) } /* - * This function splits huge page into normal pages. @page can point to any - * subpage of huge page to split. Split doesn't change the position of @page. + * This function splits huge page into pages in @new_order. @page can point to + * any subpage of huge page to split. Split doesn't change the position of + * @page. + * + * NOTE: order-1 anonymous folio is not supported because _deferred_list, + * which is used by partially mapped folios, is stored in subpage 2 and an + * order-1 folio only has subpage 0 and 1. File-backed order-1 folios are OK, + * since they do not use _deferred_list. * * Only caller must hold pin on the @page, otherwise split fails with -EBUSY. * The huge page must be locked. * * If @list is null, tail pages will be added to LRU list, otherwise, to @list. * - * Both head page and tail pages will inherit mapping, flags, and so on from - * the hugepage. + * Pages in new_order will inherit mapping, flags, and so on from the hugepage. * - * GUP pin and PG_locked transferred to @page. Rest subpages can be freed if - * they are not mapped. + * GUP pin and PG_locked transferred to @page or the compound page @page belongs + * to. Rest subpages can be freed if they are not mapped. * * Returns 0 if the hugepage is split successfully. * Returns -EBUSY if the page is pinned or if anon_vma disappeared from under * us. */ -int split_huge_page_to_list(struct page *page, struct list_head *list) +int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, + unsigned int new_order) { struct folio *folio = page_folio(page); struct deferred_split *ds_queue = get_deferred_split_queue(folio); - XA_STATE(xas, &folio->mapping->i_pages, folio->index); + /* reset xarray order to new order after split */ + XA_STATE_ORDER(xas, &folio->mapping->i_pages, folio->index, new_order); struct anon_vma *anon_vma = NULL; struct address_space *mapping = NULL; int extra_pins, ret; @@ -3024,6 +3051,34 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); + /* Cannot split anonymous THP to order-1 */ + if (new_order == 1 && folio_test_anon(folio)) { + VM_WARN_ONCE(1, "Cannot split to order-1 folio"); + return -EINVAL; + } + + if (new_order) { + /* Only swapping a whole PMD-mapped folio is supported */ + if (folio_test_swapcache(folio)) { + VM_WARN_ONCE(1, + "Cannot split swap-cached folio to non-0 order"); + return -EINVAL; + } + /* Split shmem folio to non-zero order not supported */ + if (shmem_mapping(folio->mapping)) { + VM_WARN_ONCE(1, + "Cannot split shmem folio to non-0 order"); + return -EINVAL; + } + /* No split if the file system does not support large folio */ + if (!mapping_large_folio_support(folio->mapping)) { + VM_WARN_ONCE(1, + "Cannot split file folio to non-0 order"); + return -EINVAL; + } + } + + is_hzp = is_huge_zero_page(&folio->page); if (is_hzp) { pr_warn_ratelimited("Called split_huge_page for huge zero page\n"); @@ -3120,14 +3175,21 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) if (folio_order(folio) > 1 && !list_empty(&folio->_deferred_list)) { ds_queue->split_queue_len--; - list_del(&folio->_deferred_list); + /* + * Reinitialize page_deferred_list after removing the + * page from the split_queue, otherwise a subsequent + * split will see list corruption when checking the + * page_deferred_list. + */ + list_del_init(&folio->_deferred_list); } spin_unlock(&ds_queue->split_queue_lock); if (mapping) { int nr = folio_nr_pages(folio); xas_split(&xas, folio, folio_order(folio)); - if (folio_test_pmd_mappable(folio)) { + if (folio_test_pmd_mappable(folio) && + new_order < HPAGE_PMD_ORDER) { if (folio_test_swapbacked(folio)) { __lruvec_stat_mod_folio(folio, NR_SHMEM_THPS, -nr); @@ -3139,7 +3201,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) } } - __split_huge_page(page, list, end); + __split_huge_page(page, list, end, new_order); ret = 0; } else { spin_unlock(&ds_queue->split_queue_lock); From patchwork Mon Feb 26 20:55:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13572840 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 EBF26C5478C for ; Mon, 26 Feb 2024 20:56:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50A464401C3; Mon, 26 Feb 2024 15:56:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 492B444017F; Mon, 26 Feb 2024 15:56:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2715E4401C3; Mon, 26 Feb 2024 15:56:19 -0500 (EST) 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 12B3B44017F for ; Mon, 26 Feb 2024 15:56:19 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E38A0803BC for ; Mon, 26 Feb 2024 20:56:18 +0000 (UTC) X-FDA: 81835162836.12.2D54E19 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by imf07.hostedemail.com (Postfix) with ESMTP id D1D3B4000B for ; Mon, 26 Feb 2024 20:56:16 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=OhmXJsbj; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=HkcqTlDi; spf=pass (imf07.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708980976; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eBpC8nLmV3t+tILOOyF9MHkmmffIcEidaEQ0IucvPX4=; b=MptsMWgB65gWM+NwE/tdfOaB8I5Gyzij1RT7j6+7c/wOIDNtPuRiGczEqZGlcVn9A1oEjN bl5OiX9J5YgiE5Kx+1rdITfMDoW/inRT1Dj/woAKUSU1goQSUgL7gkSxI24OjnQECACJSh 3qbpDvhmEEEf3s7Mn+V9Cpbip3JfzTY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708980976; a=rsa-sha256; cv=none; b=Q4nZ78Wr+AqK0BMluVPaivL/rKPnM54DveCMwdAeCl1bRVWxNHkCU1SxShuZwe8G1+7ZnP T/6sOxbRjx8jxDaphAXe53cggyR/9ixoiu6+Fu8qSo3qiEDVQoClfnPqxLXknTzbrC1JdI oQlSsk1QhKMwyonN47nz8gH3yFr+sOw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=OhmXJsbj; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=HkcqTlDi; spf=pass (imf07.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 3F4E95C00A8; Mon, 26 Feb 2024 15:56:16 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 26 Feb 2024 15:56:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm1; t= 1708980976; x=1709067376; bh=eBpC8nLmV3t+tILOOyF9MHkmmffIcEidaEQ 0IucvPX4=; b=OhmXJsbjvWBU33DO8vx9Sxyp+wXJmzSpaj6+LDBZDG49O+6ffyx ZSUltZ/7nhkEFqVsCc3a2BUJ4ZoVi67suV+jcrt7L2a41KVnXgGz7u5C2OQ4vK7Q qe5mbw7Dyw200uoLqf7Y25BxkdETjX2nq02CXm4lZAplslb24g51eTMqbeA1CC0j JE5a5N7H2DfGnr/RAYJJKK13TFEmJ+gq91rNp8+BSLK9z/0fwejQT7dLIWMMKkFA 9cIxCDfrLy93emdUnHrFQdAslKi55y1LFDxW3rqJjzeiJY6ZHYZX2EqCL80oxiim 9LB/ULPPKQBWQm0HacSUH3o3KmmnjeUpoiQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1708980976; x=1709067376; bh=eBpC8nLmV3t+tILOOyF9MHkmmffIcEidaEQ 0IucvPX4=; b=HkcqTlDiLWonV5rP8T2a91tyNh3gzcRKAFCXLT+izkUiGmAM2tV EqGPzyq9qIzXV+qS6IOEglz7RnR9WR0gQ+/KQDzJjaLsW2j4MS2zASpXMwSEtkeE /8IPpT7yvoXVSdApLjEfvcMxPf2UTtOX04hE40u5hQntCFfKyfCsyZmmoUrsP2gC 1RSn1NOuSDsx9lVkwKOeusqYV2xuixW1d+E8Q1YSZQULNpCZYWHCxKKwFicO2vyo FllPcUGrYbTwUOhkLuvDr0qN88nRM6skelfHLgdoJ30SY7ohg5V9/inmL0zv/t1S 4yDU6cQaB100xO5B1Ub2UmNrWOYZKr6DWPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgedvgddugedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 26 Feb 2024 15:56:15 -0500 (EST) From: Zi Yan To: "Pankaj Raghav (Samsung)" , linux-mm@kvack.org Cc: Zi Yan , "Matthew Wilcox (Oracle)" , David Hildenbrand , Yang Shi , Yu Zhao , "Kirill A . Shutemov" , Ryan Roberts , =?utf-8?q?Michal_Koutn=C3=BD?= , Roman Gushchin , "Zach O'Keefe" , Hugh Dickins , Luis Chamberlain , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v5 8/8] mm: huge_memory: enable debugfs to split huge pages to any order. Date: Mon, 26 Feb 2024 15:55:34 -0500 Message-ID: <20240226205534.1603748-9-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226205534.1603748-1-zi.yan@sent.com> References: <20240226205534.1603748-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: D1D3B4000B X-Rspam-User: X-Stat-Signature: cmeczdetuu5gnzb8p8xidswa6u3tby81 X-Rspamd-Server: rspam03 X-HE-Tag: 1708980976-315769 X-HE-Meta: U2FsdGVkX1/969WJmsLhkUMOndr5l4Thi6Mnllf9pRTz4IRryXMMgTGKmCHDc/eT7G50R+vG6RiOICf4pgSmQrI9MHjpA7f1tfZXnQSqU0P2UG9NG6+tecG98LiLqbuWpkW98rkZt2qxcM+SV7FA9WDoJHFfmolqU9U7Z533uQZNKFy+MniYUK21G3EelD1/dFtdimmbmyB0m34mMuxntj9vnxDt+o0lcHfJVl5F1ti2ISC9m6dVmYqlxvbvokXjj5a7CRvXt1hpdWCychTVROt4L2cPQ9AGgIhlviQAJSNZSwuLA3XE4HB/oaT0UmisdUiqPqCsvMO5xPPJQTCVy3b1y/Ihv+WhSFLHPTUDFf+IK51JAJ2WB/lXVbtBzjx1ebtJMFyj2W9q2vLHc2Hc2IQAHjhNetXgSVJc92Z5F7U2erqgqa9mL5PXkh/KgWkivvT6RH7WWHnx+1lDl8/zxrCgNVR8k94/RGdFGrKG6nJ5tuV4UIOhGJVCkujaBloWgJPTVUAzMoG2xPhFs8xqpVliMziKqe3+N9Ltaq9cakpy6yVdO8AWtrjOPXjYeQ+xiuh3fYFMO5HaAo4WcS1OpREs9LZ3cLVg/KNIGYXurUfzrooBHBhssBoacDIDwPv+K4dZQFdX5P0F5qtYks2chtiG+zZc6aXKV/AIjo8ofcKfYvxYuCPPdQQjFpVDmuTfG0xlTbHjr8l3OqlzRwl7YMBD3WsvWbT+0aYGgOwXJJhjLXSkeowDai4mq1vjVyCk/QtR+zDzqB338iECrRUZgh44aQpeGdvcte4N3tMhfM2XOrJcE3GDoKxDofytBmC5lhqeGxspZ2eYFCu/VBWhFxNQXfWGMfKlfNelmZnC1l0P5M4nSinYdzAaXwS3Lb3rYJ/uSpDYiuU+Umm2Zk6yVUhFDv8VrLE2SFuXsslL2aoVxYelrqTkMBNtDWX4+LDcYUAf73AeGPrULd0yD8e CP+vsGG/ AX4WsIdP87AW2xMNpRRyA5BeZ3QBn26JUbDmcH17SBw7M0i9+wUxInyuj6V6XP4h+7V143l41+PKuHcmy1Aj4I4/xOZAf8MK5z8wWP2A8tO0E6TD3StbH1JDOxjY+FQ66LngcitOH6CI18dIbMNiYLQmaesicKGVtVYMFWODOld3FdSyM2YTQ1jLXaqzsszZfLUODyyVHfaNtCut3OuCzVcG90lh6T2saVxJQvHU4FQ0sdT/FLJPBEa8ugjhHEemeA2mJz+98z2v87nDsvUGi5xpxIltoISX8EB0QTypM/HnGIM4EX04IhVFD10NAMOp7JReZ4+I+yv4pCI8ZM6QrTjcAcOktGG0b1BXbQ6mmmrEp1AWZlEGNHHMo6QVaZmmAhODFzMS38O0XpN+kxAQ+xbyUysgNgAmWWN/WG/M/7P0zBZLgQzsjbwpcSSSWcGZkqQxQCk+RpRYrRANYN9wH2rCBd4X3CdValKV8EIlguCBT4ni0B0SiBP29SA== 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: Zi Yan It is used to test split_huge_page_to_list_to_order for pagecache THPs. Also add test cases for split_huge_page_to_list_to_order via both debugfs. Signed-off-by: Zi Yan --- mm/huge_memory.c | 34 ++++-- .../selftests/mm/split_huge_page_test.c | 115 +++++++++++++++++- 2 files changed, 131 insertions(+), 18 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 8b47a96a28f9..50d146eb248f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3422,7 +3422,7 @@ static inline bool vma_not_suitable_for_thp_split(struct vm_area_struct *vma) } static int split_huge_pages_pid(int pid, unsigned long vaddr_start, - unsigned long vaddr_end) + unsigned long vaddr_end, unsigned int new_order) { int ret = 0; struct task_struct *task; @@ -3486,13 +3486,19 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, goto next; total++; - if (!can_split_folio(folio, NULL)) + /* + * For folios with private, split_huge_page_to_list_to_order() + * will try to drop it before split and then check if the folio + * can be split or not. So skip the check here. + */ + if (!folio_test_private(folio) && + !can_split_folio(folio, NULL)) goto next; if (!folio_trylock(folio)) goto next; - if (!split_folio(folio)) + if (!split_folio_to_order(folio, new_order)) split++; folio_unlock(folio); @@ -3510,7 +3516,7 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, } static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, - pgoff_t off_end) + pgoff_t off_end, unsigned int new_order) { struct filename *file; struct file *candidate; @@ -3549,7 +3555,7 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, if (!folio_trylock(folio)) goto next; - if (!split_folio(folio)) + if (!split_folio_to_order(folio, new_order)) split++; folio_unlock(folio); @@ -3574,10 +3580,14 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, { static DEFINE_MUTEX(split_debug_mutex); ssize_t ret; - /* hold pid, start_vaddr, end_vaddr or file_path, off_start, off_end */ + /* + * hold pid, start_vaddr, end_vaddr, new_order or + * file_path, off_start, off_end, new_order + */ char input_buf[MAX_INPUT_BUF_SZ]; int pid; unsigned long vaddr_start, vaddr_end; + unsigned int new_order = 0; ret = mutex_lock_interruptible(&split_debug_mutex); if (ret) @@ -3606,29 +3616,29 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, goto out; } - ret = sscanf(buf, "0x%lx,0x%lx", &off_start, &off_end); - if (ret != 2) { + ret = sscanf(buf, "0x%lx,0x%lx,%d", &off_start, &off_end, &new_order); + if (ret != 2 && ret != 3) { ret = -EINVAL; goto out; } - ret = split_huge_pages_in_file(file_path, off_start, off_end); + ret = split_huge_pages_in_file(file_path, off_start, off_end, new_order); if (!ret) ret = input_len; goto out; } - ret = sscanf(input_buf, "%d,0x%lx,0x%lx", &pid, &vaddr_start, &vaddr_end); + ret = sscanf(input_buf, "%d,0x%lx,0x%lx,%d", &pid, &vaddr_start, &vaddr_end, &new_order); if (ret == 1 && pid == 1) { split_huge_pages_all(); ret = strlen(input_buf); goto out; - } else if (ret != 3) { + } else if (ret != 3 && ret != 4) { ret = -EINVAL; goto out; } - ret = split_huge_pages_pid(pid, vaddr_start, vaddr_end); + ret = split_huge_pages_pid(pid, vaddr_start, vaddr_end, new_order); if (!ret) ret = strlen(input_buf); out: diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index 7b698a848bab..cf09fdc9ef22 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "vm_util.h" #include "../kselftest.h" @@ -24,10 +25,12 @@ unsigned int pageshift; uint64_t pmd_pagesize; #define SPLIT_DEBUGFS "/sys/kernel/debug/split_huge_pages" +#define SMAP_PATH "/proc/self/smaps" +#define THP_FS_PATH "/mnt/thp_fs" #define INPUT_MAX 80 -#define PID_FMT "%d,0x%lx,0x%lx" -#define PATH_FMT "%s,0x%lx,0x%lx" +#define PID_FMT "%d,0x%lx,0x%lx,%d" +#define PATH_FMT "%s,0x%lx,0x%lx,%d" #define PFN_MASK ((1UL<<55)-1) #define KPF_THP (1UL<<22) @@ -102,7 +105,7 @@ void split_pmd_thp(void) /* split all THPs */ write_debugfs(PID_FMT, getpid(), (uint64_t)one_page, - (uint64_t)one_page + len); + (uint64_t)one_page + len, 0); for (i = 0; i < len; i++) if (one_page[i] != (char)i) @@ -177,7 +180,7 @@ void split_pte_mapped_thp(void) /* split all remapped THPs */ write_debugfs(PID_FMT, getpid(), (uint64_t)pte_mapped, - (uint64_t)pte_mapped + pagesize * 4); + (uint64_t)pte_mapped + pagesize * 4, 0); /* smap does not show THPs after mremap, use kpageflags instead */ thp_size = 0; @@ -237,7 +240,7 @@ void split_file_backed_thp(void) } /* split the file-backed THP */ - write_debugfs(PATH_FMT, testfile, pgoff_start, pgoff_end); + write_debugfs(PATH_FMT, testfile, pgoff_start, pgoff_end, 0); status = unlink(testfile); if (status) { @@ -265,8 +268,101 @@ void split_file_backed_thp(void) ksft_exit_fail_msg("Error occurred\n"); } +void create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd, char **addr) +{ + size_t i; + int dummy; + + srand(time(NULL)); + + *fd = open(testfile, O_CREAT | O_RDWR, 0664); + if (*fd == -1) + ksft_exit_fail_msg("Failed to create a file at "THP_FS_PATH); + + for (i = 0; i < fd_size; i++) { + unsigned char byte = (unsigned char)i; + + write(*fd, &byte, sizeof(byte)); + } + close(*fd); + sync(); + *fd = open("/proc/sys/vm/drop_caches", O_WRONLY); + if (*fd == -1) { + ksft_perror("open drop_caches"); + goto err_out_unlink; + } + if (write(*fd, "3", 1) != 1) { + ksft_perror("write to drop_caches"); + goto err_out_unlink; + } + close(*fd); + + *fd = open(testfile, O_RDWR); + if (*fd == -1) { + ksft_perror("Failed to open a file at "THP_FS_PATH); + goto err_out_unlink; + } + + *addr = mmap(NULL, fd_size, PROT_READ|PROT_WRITE, MAP_SHARED, *fd, 0); + if (*addr == (char *)-1) { + ksft_perror("cannot mmap"); + goto err_out_close; + } + madvise(*addr, fd_size, MADV_HUGEPAGE); + + for (size_t i = 0; i < fd_size; i++) + dummy += *(*addr + i); + + if (!check_huge_file(*addr, fd_size / pmd_pagesize, pmd_pagesize)) { + ksft_print_msg("No large pagecache folio generated, please mount a filesystem supporting large folio at "THP_FS_PATH"\n"); + goto err_out_close; + } + return; +err_out_close: + close(*fd); +err_out_unlink: + unlink(testfile); + ksft_exit_fail_msg("Failed to create large pagecache folios\n"); +} + +void split_thp_in_pagecache_to_order(size_t fd_size, int order) +{ + int fd; + char *addr; + size_t i; + const char testfile[] = THP_FS_PATH "/test"; + int err = 0; + + create_pagecache_thp_and_fd(testfile, fd_size, &fd, &addr); + + write_debugfs(PID_FMT, getpid(), (uint64_t)addr, (uint64_t)addr + fd_size, order); + + for (i = 0; i < fd_size; i++) + if (*(addr + i) != (char)i) { + ksft_print_msg("%lu byte corrupted in the file\n", i); + err = EXIT_FAILURE; + goto out; + } + + if (!check_huge_file(addr, 0, pmd_pagesize)) { + ksft_print_msg("Still FilePmdMapped not split\n"); + err = EXIT_FAILURE; + goto out; + } + +out: + close(fd); + unlink(testfile); + if (err) + ksft_exit_fail_msg("Split PMD-mapped pagecache folio to order %d failed\n", order); + ksft_test_result_pass("Split PMD-mapped pagecache folio to order %d passed\n", order); +} + int main(int argc, char **argv) { + int i; + size_t fd_size; + ksft_print_header(); if (geteuid() != 0) { @@ -274,7 +370,7 @@ int main(int argc, char **argv) ksft_finished(); } - ksft_set_plan(3); + ksft_set_plan(3+9); pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; @@ -282,9 +378,16 @@ int main(int argc, char **argv) if (!pmd_pagesize) ksft_exit_fail_msg("Reading PMD pagesize failed\n"); + fd_size = 2 * pmd_pagesize; + split_pmd_thp(); split_pte_mapped_thp(); split_file_backed_thp(); + for (i = 8; i >= 0; i--) + split_thp_in_pagecache_to_order(fd_size, i); + ksft_finished(); + + return 0; }