Commit 86b562b6 authored by Kirill A. Shutemov's avatar Kirill A. Shutemov Committed by Linus Torvalds

mm/huge_memory: fix total_mapcount assumption of page size

File THPs may now be of arbitrary order.
Signed-off-by: default avatarKirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarSeongJae Park <sjpark@amazon.de>
Cc: Huang Ying <ying.huang@intel.com>
Link: https://lkml.kernel.org/r/20200908195539.25896-5-willy@infradead.orgSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8fb156c9
...@@ -2494,7 +2494,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, ...@@ -2494,7 +2494,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,
int total_mapcount(struct page *page) int total_mapcount(struct page *page)
{ {
int i, compound, ret; int i, compound, nr, ret;
VM_BUG_ON_PAGE(PageTail(page), page); VM_BUG_ON_PAGE(PageTail(page), page);
...@@ -2502,16 +2502,17 @@ int total_mapcount(struct page *page) ...@@ -2502,16 +2502,17 @@ int total_mapcount(struct page *page)
return atomic_read(&page->_mapcount) + 1; return atomic_read(&page->_mapcount) + 1;
compound = compound_mapcount(page); compound = compound_mapcount(page);
nr = compound_nr(page);
if (PageHuge(page)) if (PageHuge(page))
return compound; return compound;
ret = compound; ret = compound;
for (i = 0; i < HPAGE_PMD_NR; i++) for (i = 0; i < nr; i++)
ret += atomic_read(&page[i]._mapcount) + 1; ret += atomic_read(&page[i]._mapcount) + 1;
/* File pages has compound_mapcount included in _mapcount */ /* File pages has compound_mapcount included in _mapcount */
if (!PageAnon(page)) if (!PageAnon(page))
return ret - compound * HPAGE_PMD_NR; return ret - compound * nr;
if (PageDoubleMap(page)) if (PageDoubleMap(page))
ret -= HPAGE_PMD_NR; ret -= nr;
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment