linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: thp: check total_mapcount instead of page_mapcount
@ 2021-04-30 21:07 Yang Shi
  2021-04-30 21:30 ` Zi Yan
  0 siblings, 1 reply; 6+ messages in thread
From: Yang Shi @ 2021-04-30 21:07 UTC (permalink / raw)
  To: kirill.shutemov, wangyugui, ziy, hughd, akpm
  Cc: shy828301, linux-mm, linux-kernel

When debugging the bug reported by Wang Yugui [1], try_to_unmap() may
return false positive for PTE-mapped THP since page_mapcount() is used
to check if the THP is unmapped, but it just checks compound mapount and
head page's mapcount.  If the THP is PTE-mapped and head page is not
mapped, it may return false positive.

Use total_mapcount() instead of page_mapcount() and do so for the
VM_BUG_ON_PAGE in split_huge_page_to_list as well.

[1] https://lore.kernel.org/linux-mm/20210412180659.B9E3.409509F4@e16-tech.com/

Signed-off-by: Yang Shi <shy828301@gmail.com>
---
 mm/huge_memory.c | 2 +-
 mm/rmap.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 63ed6b25deaa..2122c3e853b9 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2718,7 +2718,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
 	}
 
 	unmap_page(head);
-	VM_BUG_ON_PAGE(compound_mapcount(head), head);
+	VM_BUG_ON_PAGE(total_mapcount(head), head);
 
 	/* block interrupt reentry in xa_lock and spinlock */
 	local_irq_disable();
diff --git a/mm/rmap.c b/mm/rmap.c
index 693a610e181d..2e547378ab5f 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1777,7 +1777,7 @@ bool try_to_unmap(struct page *page, enum ttu_flags flags)
 	else
 		rmap_walk(page, &rwc);
 
-	return !page_mapcount(page) ? true : false;
+	return !total_mapcount(page) ? true : false;
 }
 
 /**
-- 
2.26.2


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

end of thread, other threads:[~2021-04-30 23:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-30 21:07 [PATCH] mm: thp: check total_mapcount instead of page_mapcount Yang Shi
2021-04-30 21:30 ` Zi Yan
2021-04-30 21:56   ` Yang Shi
2021-04-30 22:30     ` Zi Yan
2021-04-30 22:55       ` Yang Shi
2021-04-30 23:02         ` Zi Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).