From nobody Mon Feb 9 20:30:37 2026 Received: from wfout8-smtp.messagingengine.com (wfout8-smtp.messagingengine.com [64.147.123.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49782142E6F for ; Wed, 24 Apr 2024 22:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713998781; cv=none; b=Cej+jJXbUJPAlBg7oRANLxp+aeFLRoASuog43IiMsJTdZQyYpabDud90Tgp/I3OV0/2JhQ1wiYtvkTZK+4d4DT7Ekp902XLmbhOdK6NXHlb/q7bmgzGHBI4jSQG/987FD/DVydd1C+j4Sg4WMlJuJ1GIzRNXUJtsJ3mAMZHI1z8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713998781; c=relaxed/simple; bh=PWMEcifnbOBNb9cFqvl7nyAKQSwJWVOg4tHQ66KBVo4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kKGEc8xMYWAuDYKqRq4vP7QDtgc9+9ehcciwg6QfyrPH6TlWbRy3paMsy4FpmVDmg/aED/DatMtKiJ5fSObgj9ztxLswcSDmcmxO2RL4av69E1RW6JLmRHG+oyxIcaXNqPkh8jgUhpABDEjtBaWaj6LV1W3hRe5EvfYD4j7rm+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sent.com; spf=pass smtp.mailfrom=sent.com; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b=WcN84l6Q; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QS77Cz/3; arc=none smtp.client-ip=64.147.123.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sent.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sent.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="WcN84l6Q"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QS77Cz/3" 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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(-) 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(stru= ct 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 =3D=3D RMAP_LEVEL_PTE || nr < nr_pmdmapped) - deferred_split_folio(folio); + if (folio_test_large(folio) && folio_test_anon(folio) && + ((level =3D=3D RMAP_LEVEL_PTE && atomic_read(mapped)) || + (level =3D=3D RMAP_LEVEL_PMD && nr < nr_pmdmapped))) + deferred_split_folio(folio); } =20 /* base-commit: 2541ee5668b019c486dd3e815114130e35c1495d --=20 2.43.0