linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/rmap: do not add fully unmapped large folio to deferred split list
@ 2024-04-11 15:32 Zi Yan
  2024-04-11 15:46 ` David Hildenbrand
  0 siblings, 1 reply; 24+ messages in thread
From: Zi Yan @ 2024-04-11 15:32 UTC (permalink / raw)
  To: linux-mm
  Cc: Zi Yan, Andrew Morton, Matthew Wilcox (Oracle),
	Yang Shi, Ryan Roberts, Barry Song, David Hildenbrand,
	linux-kernel

From: Zi Yan <ziy@nvidia.com>

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 mapcount before
adding a folio to deferred split list.

Signed-off-by: Zi Yan <ziy@nvidia.com>
---
 mm/rmap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/mm/rmap.c b/mm/rmap.c
index 2608c40dffad..d599a772e282 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1494,7 +1494,7 @@ static __always_inline void __folio_remove_rmap(struct folio *folio,
 		enum rmap_level level)
 {
 	atomic_t *mapped = &folio->_nr_pages_mapped;
-	int last, nr = 0, nr_pmdmapped = 0;
+	int last, nr = 0, nr_pmdmapped = 0, mapcount = 0;
 	enum node_stat_item idx;
 
 	__folio_rmap_sanity_checks(folio, page, nr_pages, level);
@@ -1506,7 +1506,8 @@ static __always_inline void __folio_remove_rmap(struct folio *folio,
 			break;
 		}
 
-		atomic_sub(nr_pages, &folio->_large_mapcount);
+		mapcount = atomic_sub_return(nr_pages,
+					     &folio->_large_mapcount) + 1;
 		do {
 			last = atomic_add_negative(-1, &page->_mapcount);
 			if (last) {
@@ -1554,7 +1555,9 @@ static __always_inline void __folio_remove_rmap(struct folio *folio,
 		 * is still mapped.
 		 */
 		if (folio_test_large(folio) && folio_test_anon(folio))
-			if (level == RMAP_LEVEL_PTE || nr < nr_pmdmapped)
+			if ((level == RMAP_LEVEL_PTE &&
+			     mapcount != 0) ||
+			    (level == RMAP_LEVEL_PMD && nr < nr_pmdmapped))
 				deferred_split_folio(folio);
 	}
 

base-commit: ed7c95c95397baff9b40ba9b0919933eee2d7960
-- 
2.43.0



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2024-04-15 21:16 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-11 15:32 [PATCH] mm/rmap: do not add fully unmapped large folio to deferred split list Zi Yan
2024-04-11 15:46 ` David Hildenbrand
2024-04-11 19:01   ` Yang Shi
2024-04-11 21:15     ` David Hildenbrand
2024-04-11 21:59       ` Yang Shi
2024-04-12 14:21         ` Zi Yan
2024-04-12 14:31           ` Zi Yan
2024-04-12 18:29             ` Yang Shi
2024-04-12 19:36               ` David Hildenbrand
2024-04-12 20:21                 ` Yang Shi
2024-04-12 19:06             ` David Hildenbrand
2024-04-12 14:35   ` Zi Yan
2024-04-12 19:32     ` David Hildenbrand
2024-04-12 20:35       ` Yang Shi
2024-04-15 15:43         ` David Hildenbrand
2024-04-12 21:06       ` Zi Yan
2024-04-12 22:29         ` Yang Shi
2024-04-12 22:59           ` Zi Yan
2024-04-13  0:50             ` Yang Shi
2024-04-15 15:40           ` David Hildenbrand
2024-04-15 17:54             ` Yang Shi
2024-04-15 19:19               ` David Hildenbrand
2024-04-15 21:16                 ` Yang Shi
2024-04-15 15:13         ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox