Skip to content

Commit

Permalink
mm: migrate: move_pages() supports thp migration
Browse files Browse the repository at this point in the history
This patch enables thp migration for move_pages(2).

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Naoya Horiguchi <[email protected]>
Signed-off-by: Zi Yan <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Anshuman Khandual <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: David Nellans <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Michal Hocko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Naoya Horiguchi authored and torvalds committed Sep 9, 2017
1 parent c863379 commit e8db67e
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions mm/migrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ void putback_movable_pages(struct list_head *l)
unlock_page(page);
put_page(page);
} else {
dec_node_page_state(page, NR_ISOLATED_ANON +
page_is_file_cache(page));
mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON +
page_is_file_cache(page), -hpage_nr_pages(page));
putback_lru_page(page);
}
}
Expand Down Expand Up @@ -1146,8 +1146,8 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page,
* as __PageMovable
*/
if (likely(!__PageMovable(page)))
dec_node_page_state(page, NR_ISOLATED_ANON +
page_is_file_cache(page));
mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON +
page_is_file_cache(page), -hpage_nr_pages(page));
}

/*
Expand Down Expand Up @@ -1421,7 +1421,17 @@ static struct page *new_page_node(struct page *p, unsigned long private,
if (PageHuge(p))
return alloc_huge_page_node(page_hstate(compound_head(p)),
pm->node);
else
else if (thp_migration_supported() && PageTransHuge(p)) {
struct page *thp;

thp = alloc_pages_node(pm->node,
(GFP_TRANSHUGE | __GFP_THISNODE) & ~__GFP_RECLAIM,
HPAGE_PMD_ORDER);
if (!thp)
return NULL;
prep_transhuge_page(thp);
return thp;
} else
return __alloc_pages_node(pm->node,
GFP_HIGHUSER_MOVABLE | __GFP_THISNODE, 0);
}
Expand All @@ -1448,15 +1458,19 @@ static int do_move_page_to_node_array(struct mm_struct *mm,
for (pp = pm; pp->node != MAX_NUMNODES; pp++) {
struct vm_area_struct *vma;
struct page *page;
struct page *head;
unsigned int follflags;

err = -EFAULT;
vma = find_vma(mm, pp->addr);
if (!vma || pp->addr < vma->vm_start || !vma_migratable(vma))
goto set_status;

/* FOLL_DUMP to ignore special (like zero) pages */
page = follow_page(vma, pp->addr,
FOLL_GET | FOLL_SPLIT | FOLL_DUMP);
follflags = FOLL_GET | FOLL_DUMP;
if (!thp_migration_supported())
follflags |= FOLL_SPLIT;
page = follow_page(vma, pp->addr, follflags);

err = PTR_ERR(page);
if (IS_ERR(page))
Expand All @@ -1466,7 +1480,6 @@ static int do_move_page_to_node_array(struct mm_struct *mm,
if (!page)
goto set_status;

pp->page = page;
err = page_to_nid(page);

if (err == pp->node)
Expand All @@ -1481,16 +1494,22 @@ static int do_move_page_to_node_array(struct mm_struct *mm,
goto put_and_set;

if (PageHuge(page)) {
if (PageHead(page))
if (PageHead(page)) {
isolate_huge_page(page, &pagelist);
err = 0;
pp->page = page;
}
goto put_and_set;
}

err = isolate_lru_page(page);
pp->page = compound_head(page);
head = compound_head(page);
err = isolate_lru_page(head);
if (!err) {
list_add_tail(&page->lru, &pagelist);
inc_node_page_state(page, NR_ISOLATED_ANON +
page_is_file_cache(page));
list_add_tail(&head->lru, &pagelist);
mod_node_page_state(page_pgdat(head),
NR_ISOLATED_ANON + page_is_file_cache(head),
hpage_nr_pages(head));
}
put_and_set:
/*
Expand Down

0 comments on commit e8db67e

Please sign in to comment.