Skip to content

Commit

Permalink
mm: migrate: add hugepage migration code to move_pages()
Browse files Browse the repository at this point in the history
Extend move_pages() to handle vma with VM_HUGETLB set.  We will be able to
migrate hugepage with move_pages(2) after applying the enablement patch
which comes later in this series.

We avoid getting refcount on tail pages of hugepage, because unlike thp,
hugepage is not split and we need not care about races with splitting.

And migration of larger (1GB for x86_64) hugepage are not enabled.

Signed-off-by: Naoya Horiguchi <[email protected]>
Acked-by: Andi Kleen <[email protected]>
Reviewed-by: Wanpeng Li <[email protected]>
Cc: Hillf Danton <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: KOSAKI Motohiro <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: "Aneesh Kumar K.V" <[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 11, 2013
1 parent e2d8cf4 commit e632a93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
17 changes: 15 additions & 2 deletions mm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,8 @@ struct page *follow_page_mask(struct vm_area_struct *vma,
if (pud_none(*pud))
goto no_page_table;
if (pud_huge(*pud) && vma->vm_flags & VM_HUGETLB) {
BUG_ON(flags & FOLL_GET);
if (flags & FOLL_GET)
goto out;
page = follow_huge_pud(mm, address, pud, flags & FOLL_WRITE);
goto out;
}
Expand All @@ -1492,8 +1493,20 @@ struct page *follow_page_mask(struct vm_area_struct *vma,
if (pmd_none(*pmd))
goto no_page_table;
if (pmd_huge(*pmd) && vma->vm_flags & VM_HUGETLB) {
BUG_ON(flags & FOLL_GET);
page = follow_huge_pmd(mm, address, pmd, flags & FOLL_WRITE);
if (flags & FOLL_GET) {
/*
* Refcount on tail pages are not well-defined and
* shouldn't be taken. The caller should handle a NULL
* return when trying to follow tail pages.
*/
if (PageHead(page))
get_page(page);
else {
page = NULL;
goto out;
}
}
goto out;
}
if ((flags & FOLL_NUMA) && pmd_numa(*pmd))
Expand Down
13 changes: 11 additions & 2 deletions mm/migrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,11 @@ static struct page *new_page_node(struct page *p, unsigned long private,

*result = &pm->status;

return alloc_pages_exact_node(pm->node,
if (PageHuge(p))
return alloc_huge_page_node(page_hstate(compound_head(p)),
pm->node);
else
return alloc_pages_exact_node(pm->node,
GFP_HIGHUSER_MOVABLE | GFP_THISNODE, 0);
}

Expand Down Expand Up @@ -1152,6 +1156,11 @@ static int do_move_page_to_node_array(struct mm_struct *mm,
!migrate_all)
goto put_and_set;

if (PageHuge(page)) {
isolate_huge_page(page, &pagelist);
goto put_and_set;
}

err = isolate_lru_page(page);
if (!err) {
list_add_tail(&page->lru, &pagelist);
Expand All @@ -1174,7 +1183,7 @@ static int do_move_page_to_node_array(struct mm_struct *mm,
err = migrate_pages(&pagelist, new_page_node,
(unsigned long)pm, MIGRATE_SYNC, MR_SYSCALL);
if (err)
putback_lru_pages(&pagelist);
putback_movable_pages(&pagelist);
}

up_read(&mm->mmap_sem);
Expand Down

0 comments on commit e632a93

Please sign in to comment.