From patchwork Wed Apr 24 21:10: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: 13642525 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 6C0ADC4345F for ; Wed, 24 Apr 2024 21:10:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 027706B030D; Wed, 24 Apr 2024 17:10:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1BA06B030E; Wed, 24 Apr 2024 17:10:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE1356B030F; Wed, 24 Apr 2024 17:10:39 -0400 (EDT) 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 C095C6B030D for ; Wed, 24 Apr 2024 17:10:39 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 725B9A13C4 for ; Wed, 24 Apr 2024 21:10:39 +0000 (UTC) X-FDA: 82045669398.02.7664395 Received: from wfout7-smtp.messagingengine.com (wfout7-smtp.messagingengine.com [64.147.123.150]) by imf12.hostedemail.com (Postfix) with ESMTP id 6C70C4001E for ; Wed, 24 Apr 2024 21:10:37 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=IsZyCOxu; dkim=pass header.d=messagingengine.com header.s=fm3 header.b="iKH/4OFZ"; spf=pass (imf12.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.150 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=1713993037; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=DNcr3ISM3zeCbWjs6xD/+8e+IXLwFKS7Mr3PFm4E1FE=; b=x94ryTwnSuNPEMH4zNkvdWA+pAL6F+qpqdkoLSSjlrEUO9CtkJRbnxHCyoZUaFFffg1iAn 9onFMydEJbInEDVpeIktBuQip0wsM8h2/e2Tji7u+SPKzpV2h6AwiYOkHqi1jTki8dah94 ahVQBtG705Ec0z6Iso9QSI73E865dLw= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=IsZyCOxu; dkim=pass header.d=messagingengine.com header.s=fm3 header.b="iKH/4OFZ"; spf=pass (imf12.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.150 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713993037; a=rsa-sha256; cv=none; b=K7ufbI1ACGHfgw3tO5Rtq69YJ/riwWSQKe0wzugex3TV35RfohaIwdbKeklSl19NTXh0O0 z7TSZSpm/oWKc0J/+7jzQ0t1v0mRdbTAT3HuSophwXk6bC0U17gUxRXXLAVLnjhNxoMYzC 7j0mJE3i2fzhgk7ct3r/1LZGVPAEqC4= Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 38CA91C00138; Wed, 24 Apr 2024 17:10:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 24 Apr 2024 17:10:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:reply-to:subject :subject:to:to; s=fm3; t=1713993034; x=1714079434; bh=DNcr3ISM3z eCbWjs6xD/+8e+IXLwFKS7Mr3PFm4E1FE=; b=IsZyCOxuIpfFsk5m74SJCu8tgN +7B3k/EuxM6yFDk1dmDLxCrkqjx1tSVM0Fjks74eIPWH0X2lTnh2rCHGXaytj7CA hDVdboMCuazTzWsDe6TFZBUkVkpqyNiL/BYWteeJy4Y3N9jsDVF/fur0xwMGbU/h eGg1c2DpmkwL10xJIoItkGnfK6sEdBZ2fP1TCgi7w8a8v47Q8qPAwfqRITTlvcXq +jnquupDMmP8QHw99kdtRJgvkkDS+7yA6DBqmFtlArpfAfPawa4WIbf9nomXqsQs XSgyPmQy2AqeWIJZf4xN8/8q1p/Pm/noG4E3TkPqELSUPZX+YzOom9vgejRQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:reply-to:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1713993034; x=1714079434; bh=DNcr3ISM3zeCb Wjs6xD/+8e+IXLwFKS7Mr3PFm4E1FE=; b=iKH/4OFZZ/2H5crujtjTCVp/YhPCj ikXyqvR8lpN0jxmaDyeVpfadwDAJjKYhRGnr26jULLXZPBfJjFXfhBZKSVmInbaM 9fMWfFrVtkCWP/xKcsZDPp0cCt0O3tFJLZvW/qwZBOVBYSzmJVzCEVRmtUnVRBTi Q0nCLl//YZYjZz/NS/iQpIbJPHkdjcn5SSBzu6IobN2CVtVEwa03I1wb0tuYqbZZ ujtcHOY+FKTWRSMevioi0m89xJtMm7bR1MeK0wnOxjeaYHqUvq25X0Za9+Meb5hF RTwtedvJdDCJ6Bn8pypWsDyso1TibFGrTTjEq9ZAvLOTYp2iblaaV/EDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudelhedgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofhrggfgsedtkeertdertddtnecuhfhrohhmpegkihcujggr nhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeffjeeuie efjedujedugfeitdefledtgfeufffhudelgfdtkeetkeefjeehkeehtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeiiihdrhigrnhesshgvnh htrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 24 Apr 2024 17:10:33 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org Cc: Zi Yan , Andrew Morton , "Matthew Wilcox (Oracle)" , Yang Shi , Ryan Roberts , Barry Song <21cnbao@gmail.com>, David Hildenbrand , linux-kernel@vger.kernel.org Subject: [PATCH v2] mm/rmap: do not add fully unmapped large folio to deferred split list Date: Wed, 24 Apr 2024 17:10:31 -0400 Message-ID: <20240424211031.475756-1-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 6C70C4001E X-Stat-Signature: m9yuujg1y3btpbd6199ydnzcjqzrqf4y X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1713993037-295926 X-HE-Meta: U2FsdGVkX19Wb/k7MTUM2PNBGxf8PFSAPCK3lSWJSABQE9W9KmyILa3zdUYHbQu07ALgtJzKGu8DOMx4DyhQGIiOmjbovbeiOri18aO6FxEI2uH+fcpMxrdK6VOggM7j2Fy0oRNOC915nAhDXQsMCeoxW1gKxhr9ehf8raxe9Bnp8eEkgge8ZgRNRIX/B4mgCJNlyb6qRcSL3eeSbPY/LjWZY2bdmmeMVIMEhXohBSaMQdcMs/dc0rpG8ji4du9XloAvfPOdQxd2RCbeeZ29s3vZptwD5jPT/Dzgx1t0sInS3CLym4b4rAyyHo3YpcJR/8JwP+n2T9TbFhNdyiKpNKuu0cYdFecKnvsSxFtVAxaPuBkaggvpVnhBvpiB6RdhZwa7kHY/qHN8JSF7hbDOV3MyUjtyKTmtNv3FFX0RHv/vHdIU8xY4NDbWwkzMtA/fgOllBpbeWeLe9iyabr6jaxAi/BiSys8wJNgItuqcZV7Kb9wllu9MVnKHEsRAsJvFpP2DFM+ugJUZUIIS/4WsoC6K+qNxkAokUN7JhzQdawGuyR8nUVRtsEUv+YthvgsApWgyEZNbvVMyOavD+AU12365eR/C7MjcuWGPAKHH7Jtz0WAHg+7+ExT1jUe2jcsqi3UmOu96dBuLHkaxNcoWwasx8UxdHC63W2OyRhslMGlvtyl5agEkgrbvU3ul4UxNWvj2498yvE1KUS1MlelSMAVWuIWdJA6DTUPWbibr6z7dTneHzmlI60i6AtRBd+E1Tv0TvWTP7ODwp5/et9OtEqqYQIIybxbvbM/7Fmbdh/29Cej45DVq3lb/SjKX9lqAgqxZhpSWIswtoREGah1/DPEIlagadbSoubPMhV8Yu0ggE1U/vpibcAm1ZgdTzBRSxhl3yoYpfFU92HppZfQkWfIhuvrSI9VN86LbuCzXQWRCVxnZvWLFXboU+lxX6tqsDiG3zaH+NKdK7HAXgcH HzHYYAB1 p9GEYe8S8sRjV4cn6absstMLBhYs3XTJwe/7K8LzmnX8kIRv9gWHbDlPUnQ1w2pjNmD131zL8KO5HCNFuOXLmcb6fzkWWcn6RJiZHq2NhBTNlC5ZBBdU7H0KM1dvpjpRm6U/m0NTO29hIMCo8eNnWGz0mGw== 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 In __folio_remove_rmap(), a large folio is added to deferred split list if any page in a folio loses its final mapping. It is possible that the folio is unmapped fully, but it is unnecessary to add the folio to deferred split list at all. Fix it by checking folio->_nr_pages_mapped before adding a folio to deferred split list. If the folio is already on the deferred split list, it will be skipped. Commit 98046944a159 ("mm: huge_memory: add the missing folio_test_pmd_mappable() for THP split statistics") tried to exclude mTHP deferred split stats from THP_DEFERRED_SPLIT_PAGE, but it does not fix everything. A fully unmapped PTE-mapped order-9 THP was also added to deferred split list and counted as THP_DEFERRED_SPLIT_PAGE, since nr is 512 (non zero), level is RMAP_LEVEL_PTE, and inside deferred_split_folio() the order-9 folio is folio_test_pmd_mappable(). However, this miscount was present even earlier due to implementation, since PTEs are unmapped individually and first PTE unmapping adds the THP into the deferred split list. With commit b06dc281aa99 ("mm/rmap: introduce folio_remove_rmap_[pte|ptes|pmd]()"), kernel is able to unmap PTE-mapped folios in one shot without causing the miscount, hence this patch. Signed-off-by: Zi Yan --- mm/rmap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) base-commit: 2541ee5668b019c486dd3e815114130e35c1495d diff --git a/mm/rmap.c b/mm/rmap.c index a7913a454028..220ad8a83589 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1553,9 +1553,11 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, * page of the folio is unmapped and at least one page * is still mapped. */ - if (folio_test_large(folio) && folio_test_anon(folio)) - if (level == RMAP_LEVEL_PTE || nr < nr_pmdmapped) - deferred_split_folio(folio); + if (folio_test_large(folio) && folio_test_anon(folio) && + list_empty(&folio->_deferred_list) && + ((level == RMAP_LEVEL_PTE && atomic_read(mapped)) || + (level == RMAP_LEVEL_PMD && nr < nr_pmdmapped))) + deferred_split_folio(folio); } /*