Skip to content

Commit

Permalink
mm/huge_memory: fix total_mapcount assumption of page size
Browse files Browse the repository at this point in the history
File THPs may now be of arbitrary order.

Signed-off-by: Kirill A. Shutemov <[email protected]>
Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: SeongJae Park <[email protected]>
Cc: Huang Ying <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kiryl authored and torvalds committed Oct 16, 2020
1 parent 8fb156c commit 86b562b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mm/huge_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2494,24 +2494,25 @@ 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);

if (likely(!PageCompound(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;
}

Expand Down

0 comments on commit 86b562b

Please sign in to comment.