Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1389291lqd; Thu, 25 Apr 2024 14:12:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVjneL6QxbWNxr4cnOrvTMRNNchYLmjquN5uGNqRmi29VkDwBgn/pnUsKvmd/VZOd9TJSlQlvrlLWRMWlCdSEjVM3ZGJa+D4e+XDnP1ug== X-Google-Smtp-Source: AGHT+IGENChf9CWNQTq0cz8EIZb5HPfP252PGoC2xTUVPBN8HT64EBEdMXO8/fX2czdUBLOg2BS1 X-Received: by 2002:a17:906:eb49:b0:a46:3ce4:5acb with SMTP id mc9-20020a170906eb4900b00a463ce45acbmr529332ejb.75.1714079520792; Thu, 25 Apr 2024 14:12:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714079520; cv=pass; d=google.com; s=arc-20160816; b=QT1AV90OaAGwObWHhHV1y7j4GIUoBk0NqWvQMwgyae/4OusBqzX7xhOBT8rYyG8SbI uDBvnNaIy3vjkPNIQ/6FdgdcfHeQGfRtWFL1dOAYz45agmsDgxt94CEAsQOJWubNlT6f ib+3OlyaCkYR703cNegLwPTFaPRGffXj4jQKLoWAVd/ILmKqzF1qZV35+EoPMdB5QvwB JArPHwn0p2xDNlYVbIObJG6nHvOuirq7i8PnYJnF9DNg5hqjZ/YqG/D/5s4rdxROGxI+ UCKWpJRZcbV/O7X1Alx7jEuxQqvJVdwO7Qt6xO/HNCCl5GECmy0ZsivU8n0/tP62fe8z IFjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:reply-to:message-id:date:subject :cc:to:from:feedback-id:dkim-signature:dkim-signature; bh=iGwfXom4e7yCPiqRGg7li8EHLijwecEGUquGPFC+5WI=; fh=YIqGBVwXZaeMqaX8A5smNE3oIQIBJzetkW1azT9BmJg=; b=X5biVg58slpNEtgYhNeguuQjZyzlkar+T5tashvOVAK8cnKOBOORt+jSaEq8A6Pxiw WBBkH7DCT5J8zXOsTDwlxNHaf09wtE+cwpOXdKE3eIwQdLnuKeJfj3rYseqtWJ7jT4fc fZzGlhTjihtHHa63GLxsG0AZRA7jn2vaNfVGB8oG5qlvJH/PZbOIvas+UzVUYovFZ0CY iFH5CRpQyJ8kHUpAVyehtbTvWh0XcIp3YunQ5Y+ncK3dSOd7QWk4DO4+h5mLPAWLG+vH FJN0GhRBUm37jJ5UnH29RZNV8VvfF5qrdMmuObJJQB136qOet13NzVoAkvqaYlIKEd7f mm8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=Qz4mbo7F; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=E6SjiYRr; arc=pass (i=1 spf=pass spfdomain=sent.com dkim=pass dkdomain=sent.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sent.com); spf=pass (google.com: domain of linux-kernel+bounces-159190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f2-20020a17090624c200b00a525d60efb6si10262569ejb.844.2024.04.25.14.12.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 14:12:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=Qz4mbo7F; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=E6SjiYRr; arc=pass (i=1 spf=pass spfdomain=sent.com dkim=pass dkdomain=sent.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sent.com); spf=pass (google.com: domain of linux-kernel+bounces-159190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 91C591F21FEF for ; Thu, 25 Apr 2024 21:11:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F6761553A0; Thu, 25 Apr 2024 21:11:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="Qz4mbo7F"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="E6SjiYRr" Received: from wfhigh8-smtp.messagingengine.com (wfhigh8-smtp.messagingengine.com [64.147.123.159]) (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 C56EA37143 for ; Thu, 25 Apr 2024 21:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.159 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714079504; cv=none; b=D4d535RXPpAazMFRymni4U55qPJDXcMErzThXJaIDKUOwnEhJYqfN8Ombic9Z5BdP3jWzWTnU/huc3EEiHrDK2jp0upwUMy4/SSwRXoUyWNilOcdHJLzxknxj2FSSp48duoawPsmvl1kBfAQj9MzRd/PbtxS0f3cTuFXrXiDr3g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714079504; c=relaxed/simple; bh=GyqMvJXAfaiti7K97yMzFKkzr6iZHTZA68RRpahYJX4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=aYP97yBHLGQef4SilG+MmLhtK/G3l2ODwBHydhr+z2lg6PPk3zjQ6Ro7+Tv4MVvAJDvNVfijsccvjwj4h9y6RNZLWkys6VJMVMiwiSf2tdZ4FVPpCLURgzAkr2NsGMSfI0jup3igtifNfJEfR1gBhGRXIqI0RoUbdYbR3tLh/tk= 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=Qz4mbo7F; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=E6SjiYRr; arc=none smtp.client-ip=64.147.123.159 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 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id 1C804180010A; Thu, 25 Apr 2024 17:11:41 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 25 Apr 2024 17:11:42 -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=1714079500; x=1714165900; bh=iGwfXom4e7 yCPiqRGg7li8EHLijwecEGUquGPFC+5WI=; b=Qz4mbo7FRm3b3kQ6kdzfBqIyIB ZUSMsl012WSYgD353Z6ow2o+nGTIfmDa/Kpnj1jrdVNIBZW7cOzc5rFk4OLQd9Kc sSdw10UyXSDdqm3qpJV3eloNEmOJC1Jzu7ic51yxZiTK2ccMisHf5O0Z8KFI+Wzz l4TwGnAyLXx77B6eTgABlblfbwCdFH6dbWhdbsl/Lg9CDnmJwqQXIBqD5VSneYuk opmuH6RxlTO+/snV4v4HvkdE7t0YutQMeY0gUg1vxCUFADgcwRnLbtFynKDP1OyL znKzrn8Ac1mCsD2ZGGu/BcVH7OR1jq9AO5LlJLJT3KSTmAGkpGU3UPdBQ87Q== 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=1714079500; x=1714165900; bh=iGwfXom4e7yCP iqRGg7li8EHLijwecEGUquGPFC+5WI=; b=E6SjiYRrFB34PrHMNhJYrxrZXCMFj JeG1NC9YAjvWrJmrlxkMwUGpaBEjHEyYdOHJ37Mj2GKEmd0jgYBglVtZRSf9GRdy 6uO0QxGQLxuGA9T82gythsIbEtuLfwfGQM1ZUFt3EWfdvp8chADb5rLjTp+AK8bD Z+pBm1kHZ5z5v5dx119Ph4qKixzha5rZvN4ltGwJqEI6ivWKQgCPLJwCZpufGoN4 X6j+cxfviwe95dWJ+S2vni6W4rnZgJPiEioAppz5CSlM2++rtJh41L+b1yH5NuYJ Y8QnIWoz+IxfzX22nFmx5Ttf5fGN2zhvFOeh+IhY1NJWLCS8zngpz5xLg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeljedgudehlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkfforhgggfestdekredtredttdenucfhrhhomhepkghiucgj rghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepffejue eifeejudejudfgiedtfeeltdfgueffhfdulefgtdekteekfeejheekhedtnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnsehsvg hnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 Apr 2024 17:11:39 -0400 (EDT) From: Zi Yan To: Andrew Morton , linux-mm@kvack.org Cc: Zi Yan , "Matthew Wilcox (Oracle)" , Yang Shi , Ryan Roberts , Barry Song <21cnbao@gmail.com>, David Hildenbrand , Lance Yang , linux-kernel@vger.kernel.org Subject: [PATCH v4] mm/rmap: do not add fully unmapped large folio to deferred split list Date: Thu, 25 Apr 2024 17:11:36 -0400 Message-ID: <20240425211136.486184-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: 8bit 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. But it is possible that the folio is fully unmapped and adding it to deferred split list is unnecessary. For PMD-mapped THPs, that was not really an issue, because removing the last PMD mapping in the absence of PTE mappings would not have added the folio to the deferred split queue. However, for PTE-mapped THPs, which are now more prominent due to mTHP, they are always added to the deferred split queue. One side effect is that the THP_DEFERRED_SPLIT_PAGE stat for a PTE-mapped folio can be unintentionally increased, making it look like there are many partially mapped folios -- although the whole folio is fully unmapped stepwise. Core-mm now tries batch-unmapping consecutive PTEs of PTE-mapped THPs where possible starting from commit b06dc281aa99 ("mm/rmap: introduce folio_remove_rmap_[pte|ptes|pmd]()"). When it happens, a whole PTE-mapped folio is unmapped in one go and can avoid being added to deferred split list, reducing the THP_DEFERRED_SPLIT_PAGE noise. But there will still be noise when we cannot batch-unmap a complete PTE-mapped folio in one go -- or where this type of batching is not implemented yet, e.g., migration. To avoid the unnecessary addition, folio->_nr_pages_mapped is checked to tell if the whole folio is unmapped. If the folio is already on deferred split list, it will be skipped, too. Note: 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(). Signed-off-by: Zi Yan Reviewed-by: Yang Shi --- mm/rmap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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); } /* base-commit: 66313c66dd90e8711a8b63fc047ddfc69c53636a -- 2.43.0