Commit 8cce5475 authored by Kirill A. Shutemov's avatar Kirill A. Shutemov Committed by Linus Torvalds

mm/huge_memory: fix split assumption of page size

File THPs may now be of arbitrary size, and we can't rely on that size
after doing the split so remember the number of pages before we start the
split.
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-6-willy@infradead.orgSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 86b562b6
...@@ -2335,13 +2335,13 @@ static void unmap_page(struct page *page) ...@@ -2335,13 +2335,13 @@ static void unmap_page(struct page *page)
VM_BUG_ON_PAGE(!unmap_success, page); VM_BUG_ON_PAGE(!unmap_success, page);
} }
static void remap_page(struct page *page) static void remap_page(struct page *page, unsigned int nr)
{ {
int i; int i;
if (PageTransHuge(page)) { if (PageTransHuge(page)) {
remove_migration_ptes(page, page, true); remove_migration_ptes(page, page, true);
} else { } else {
for (i = 0; i < HPAGE_PMD_NR; i++) for (i = 0; i < nr; i++)
remove_migration_ptes(page + i, page + i, true); remove_migration_ptes(page + i, page + i, true);
} }
} }
...@@ -2419,6 +2419,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, ...@@ -2419,6 +2419,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,
struct lruvec *lruvec; struct lruvec *lruvec;
struct address_space *swap_cache = NULL; struct address_space *swap_cache = NULL;
unsigned long offset = 0; unsigned long offset = 0;
unsigned int nr = thp_nr_pages(head);
int i; int i;
lruvec = mem_cgroup_page_lruvec(head, pgdat); lruvec = mem_cgroup_page_lruvec(head, pgdat);
...@@ -2434,7 +2435,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, ...@@ -2434,7 +2435,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,
xa_lock(&swap_cache->i_pages); xa_lock(&swap_cache->i_pages);
} }
for (i = HPAGE_PMD_NR - 1; i >= 1; i--) { for (i = nr - 1; i >= 1; i--) {
__split_huge_page_tail(head, i, lruvec, list); __split_huge_page_tail(head, i, lruvec, list);
/* Some pages can be beyond i_size: drop them from page cache */ /* Some pages can be beyond i_size: drop them from page cache */
if (head[i].index >= end) { if (head[i].index >= end) {
...@@ -2454,7 +2455,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, ...@@ -2454,7 +2455,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,
ClearPageCompound(head); ClearPageCompound(head);
split_page_owner(head, HPAGE_PMD_NR); split_page_owner(head, nr);
/* See comment in __split_huge_page_tail() */ /* See comment in __split_huge_page_tail() */
if (PageAnon(head)) { if (PageAnon(head)) {
...@@ -2473,9 +2474,9 @@ static void __split_huge_page(struct page *page, struct list_head *list, ...@@ -2473,9 +2474,9 @@ static void __split_huge_page(struct page *page, struct list_head *list,
spin_unlock_irqrestore(&pgdat->lru_lock, flags); spin_unlock_irqrestore(&pgdat->lru_lock, flags);
remap_page(head); remap_page(head, nr);
for (i = 0; i < HPAGE_PMD_NR; i++) { for (i = 0; i < nr; i++) {
struct page *subpage = head + i; struct page *subpage = head + i;
if (subpage == page) if (subpage == page)
continue; continue;
...@@ -2729,7 +2730,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) ...@@ -2729,7 +2730,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
fail: if (mapping) fail: if (mapping)
xa_unlock(&mapping->i_pages); xa_unlock(&mapping->i_pages);
spin_unlock_irqrestore(&pgdata->lru_lock, flags); spin_unlock_irqrestore(&pgdata->lru_lock, flags);
remap_page(head); remap_page(head, thp_nr_pages(head));
ret = -EBUSY; ret = -EBUSY;
} }
......
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