diff mbox series

[04/11] mm/huge_memory: Fix total_mapcount assumption of page size

Message ID 20200908195539.25896-5-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Remove assumptions of THP size | expand

Commit Message

Matthew Wilcox Sept. 8, 2020, 7:55 p.m. UTC
From: "Kirill A. Shutemov" <kirill@shutemov.name>

File THPs may now be of arbitrary order.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/huge_memory.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

SeongJae Park Sept. 15, 2020, 7:21 a.m. UTC | #1
On Tue,  8 Sep 2020 20:55:31 +0100 "Matthew Wilcox (Oracle)" <willy@infradead.org> wrote:

> From: "Kirill A. Shutemov" <kirill@shutemov.name>
> 
> File THPs may now be of arbitrary order.
> 
> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Reviewed-by: SeongJae Park <sjpark@amazon.de>


Thanks,
SeongJae Park
diff mbox series

Patch

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index adc5a91d8fd4..a882d770a812 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2458,7 +2458,7 @@  static void __split_huge_page(struct page *page, struct list_head *list,
 
 int total_mapcount(struct page *page)
 {
-	int i, compound, ret;
+	int i, compound, nr, ret;
 
 	VM_BUG_ON_PAGE(PageTail(page), page);
 
@@ -2466,16 +2466,17 @@  int total_mapcount(struct page *page)
 		return atomic_read(&page->_mapcount) + 1;
 
 	compound = compound_mapcount(page);
+	nr = compound_nr(page);
 	if (PageHuge(page))
 		return compound;
 	ret = compound;
-	for (i = 0; i < HPAGE_PMD_NR; i++)
+	for (i = 0; i < nr; i++)
 		ret += atomic_read(&page[i]._mapcount) + 1;
 	/* File pages has compound_mapcount included in _mapcount */
 	if (!PageAnon(page))
-		return ret - compound * HPAGE_PMD_NR;
+		return ret - compound * nr;
 	if (PageDoubleMap(page))
-		ret -= HPAGE_PMD_NR;
+		ret -= nr;
 	return ret;
 }