From patchwork Wed Apr 24 22:46:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13642587 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 821F1C4345F for ; Wed, 24 Apr 2024 22:46:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F14736B007B; Wed, 24 Apr 2024 18:46:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC55E6B0088; Wed, 24 Apr 2024 18:46:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D64EC6B0098; Wed, 24 Apr 2024 18:46:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B979C6B007B for ; Wed, 24 Apr 2024 18:46:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 371321C146B for ; Wed, 24 Apr 2024 22:46:25 +0000 (UTC) X-FDA: 82045910730.19.40CFFC6 Received: from wfout8-smtp.messagingengine.com (wfout8-smtp.messagingengine.com [64.147.123.151]) by imf10.hostedemail.com (Postfix) with ESMTP id 13483C0013 for ; Wed, 24 Apr 2024 22:46:22 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=WcN84l6Q; dkim=pass header.d=messagingengine.com header.s=fm3 header.b="QS77Cz/3"; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf10.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.151 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=1713998783; 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=qiywAs5hIZVDAA1bE5nB42rMvHU8KwAHDhD7k65/QJg=; b=uKu51ZMUurg/ijJnEuTRYZhtZ+bnAj4FTe8bp77Dra56/3D09XiAYMHs7NZNSJHd0GH3+P LrircphgSwobb5zT2ljyTeVo9S7B6QLGtajzJhCkgQBTWyml+f3A/lIlq0MtY+y4nrhpQK McONcCtZ3IUh3WNSFRfbRT3ewVsYsyY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=WcN84l6Q; dkim=pass header.d=messagingengine.com header.s=fm3 header.b="QS77Cz/3"; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf10.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.151 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713998783; a=rsa-sha256; cv=none; b=to3D+pBvGznxH5NzYA7Vp5F3ScTz3v7Sdt2Too+D4BUaMJULAPDp0Knrq+98DXR30zV8S/ 9JUsdxnT8GqX4eoBLAFl1DtIN0Bkp0nqSgLuoDjez+lgavHhfq6qhpUwXLPfYAcv9VJQHb woowVi7koWLMHIKEHt1fcmRyUMlejxM= Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 747171C000B1; Wed, 24 Apr 2024 18:46:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 24 Apr 2024 18:46:18 -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=1713998776; x=1714085176; bh=qiywAs5hIZ VDAA1bE5nB42rMvHU8KwAHDhD7k65/QJg=; b=WcN84l6Qu8p3lJjAlR3XpsLG0Z nilPUeXyqxmJrVGYgtueVwL3KvtMWjVow+wydOkwq1Y/qSbOgqza8d00Qh2TFRUw CqmqkZUwCkjGSmFWiuH9X226gVJuiVQ7qyzqakiy/Jt8mRwo2PcwMgJHNcLGmdAI U13Bh8+VEOOIZME2pikyPa//RB9KgoUjfP+b9HtzL0OtJMhuZGf6Sk47bffB84xw bz3EHcQvBq89PWQNg0I0PrVwggAfGLokZZzvQ2SBMgb4CsAWvqnHnKbau5LVJGMm zJ33DETgVtV5AeDpJjUEl+D7wHbEY2pnDsP92u9Edp7JzrzmN02GYh3Cs9qQ== 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=1713998776; x=1714085176; bh=qiywAs5hIZVDA A1bE5nB42rMvHU8KwAHDhD7k65/QJg=; b=QS77Cz/3d2JacPLVmzr7R7fTijrMu uBAe86oC+7GUW1D6p3IarpZ41hTvufb+funKYbeQ33cqO7XFSCHZgpinrCcqltrq tm66kvrGaIqY8TBmTIh0AkTk8FRKmFJrIfbHMARUNe24OF4wfS2SOJO5nS9bz8xY S8C10MIl/qxYa44Xe/zBJy8wTVnGmPPGEHLAqDPzLc8IbIvwpf4OMNVbxkjqAUW/ fodTu1oA+vI1nRbP9C12LdZ+xqS+EkVvy0Fh4TyEMH6J8StETSEBy6oABR1zAp8/ wtS40UwpQ4yPZd7zgDR2deJ3U6kXqmUqgtGzef/umvZgevBBIfYE36WhQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeliedgudegucetufdoteggodetrfdotf 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 18:46:16 -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 , Lance Yang , linux-kernel@vger.kernel.org Subject: [PATCH v3] mm/rmap: do not add fully unmapped large folio to deferred split list Date: Wed, 24 Apr 2024 18:46:14 -0400 Message-ID: <20240424224614.477221-1-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 13483C0013 X-Stat-Signature: 4igh6xsb481rbqje57eu3t51p4jek544 X-HE-Tag: 1713998782-258936 X-HE-Meta: U2FsdGVkX189WZG8zk8MW0mGGoKwOGQuVwgHVdlVCiY8GsCGdiU7i96nZ2KVRZk7n+C5QAk5xDitpcYB26wqCFO42gcnHtfzXfAxBYUY5hCQRv20e0lPWN3Ew634Xi+ykrDpFa3Hi3+YeB3lGx1rfLrJ3VUu87wioVquduFAHzB0CstN9w8z7YLbNO5htaDem9j7q1vjAw+x+Zgg8Npk7EYDJjILepl7akddtEhTj1ff5s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OvjccwFacc1y7gswoChsisBrT4rfvRomU9c+qTPRtyAC6qP2wn9tO7FHFMuxFysd6kyQPJi+l8EXukVrxTCwBFSL2ELhQg/dhdJkr+Qk0xXQtqcBlFus9LR4BDemIF15iFSVPKkTVqfg== 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. This issue applies to both PTE-mapped THP and mTHP. 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 the above issue. A fully unmapped PTE-mapped order-9 THP was still 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 Reviewed-by: Yang Shi --- mm/rmap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) base-commit: 2541ee5668b019c486dd3e815114130e35c1495d diff --git a/mm/rmap.c b/mm/rmap.c index a7913a454028..2809348add7b 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1553,9 +1553,10 @@ 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) && + ((level == RMAP_LEVEL_PTE && atomic_read(mapped)) || + (level == RMAP_LEVEL_PMD && nr < nr_pmdmapped))) + deferred_split_folio(folio); } /*