Skip to content

Commit e8db67e

Browse files
Naoya Horiguchitorvalds
authored andcommitted
mm: migrate: move_pages() supports thp migration
This patch enables thp migration for move_pages(2). Link: http://lkml.kernel.org/r/20170717193955.20207-10-zi.yan@sent.com Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Signed-off-by: Zi Yan <zi.yan@cs.rutgers.edu> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Anshuman Khandual <khandual@linux.vnet.ibm.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: David Nellans <dnellans@nvidia.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Minchan Kim <minchan@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Michal Hocko <mhocko@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c863379 commit e8db67e

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

mm/migrate.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ void putback_movable_pages(struct list_head *l)
185185
unlock_page(page);
186186
put_page(page);
187187
} else {
188-
dec_node_page_state(page, NR_ISOLATED_ANON +
189-
page_is_file_cache(page));
188+
mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON +
189+
page_is_file_cache(page), -hpage_nr_pages(page));
190190
putback_lru_page(page);
191191
}
192192
}
@@ -1146,8 +1146,8 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page,
11461146
* as __PageMovable
11471147
*/
11481148
if (likely(!__PageMovable(page)))
1149-
dec_node_page_state(page, NR_ISOLATED_ANON +
1150-
page_is_file_cache(page));
1149+
mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON +
1150+
page_is_file_cache(page), -hpage_nr_pages(page));
11511151
}
11521152

11531153
/*
@@ -1421,7 +1421,17 @@ static struct page *new_page_node(struct page *p, unsigned long private,
14211421
if (PageHuge(p))
14221422
return alloc_huge_page_node(page_hstate(compound_head(p)),
14231423
pm->node);
1424-
else
1424+
else if (thp_migration_supported() && PageTransHuge(p)) {
1425+
struct page *thp;
1426+
1427+
thp = alloc_pages_node(pm->node,
1428+
(GFP_TRANSHUGE | __GFP_THISNODE) & ~__GFP_RECLAIM,
1429+
HPAGE_PMD_ORDER);
1430+
if (!thp)
1431+
return NULL;
1432+
prep_transhuge_page(thp);
1433+
return thp;
1434+
} else
14251435
return __alloc_pages_node(pm->node,
14261436
GFP_HIGHUSER_MOVABLE | __GFP_THISNODE, 0);
14271437
}
@@ -1448,15 +1458,19 @@ static int do_move_page_to_node_array(struct mm_struct *mm,
14481458
for (pp = pm; pp->node != MAX_NUMNODES; pp++) {
14491459
struct vm_area_struct *vma;
14501460
struct page *page;
1461+
struct page *head;
1462+
unsigned int follflags;
14511463

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

14571469
/* FOLL_DUMP to ignore special (like zero) pages */
1458-
page = follow_page(vma, pp->addr,
1459-
FOLL_GET | FOLL_SPLIT | FOLL_DUMP);
1470+
follflags = FOLL_GET | FOLL_DUMP;
1471+
if (!thp_migration_supported())
1472+
follflags |= FOLL_SPLIT;
1473+
page = follow_page(vma, pp->addr, follflags);
14601474

14611475
err = PTR_ERR(page);
14621476
if (IS_ERR(page))
@@ -1466,7 +1480,6 @@ static int do_move_page_to_node_array(struct mm_struct *mm,
14661480
if (!page)
14671481
goto set_status;
14681482

1469-
pp->page = page;
14701483
err = page_to_nid(page);
14711484

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

14831496
if (PageHuge(page)) {
1484-
if (PageHead(page))
1497+
if (PageHead(page)) {
14851498
isolate_huge_page(page, &pagelist);
1499+
err = 0;
1500+
pp->page = page;
1501+
}
14861502
goto put_and_set;
14871503
}
14881504

1489-
err = isolate_lru_page(page);
1505+
pp->page = compound_head(page);
1506+
head = compound_head(page);
1507+
err = isolate_lru_page(head);
14901508
if (!err) {
1491-
list_add_tail(&page->lru, &pagelist);
1492-
inc_node_page_state(page, NR_ISOLATED_ANON +
1493-
page_is_file_cache(page));
1509+
list_add_tail(&head->lru, &pagelist);
1510+
mod_node_page_state(page_pgdat(head),
1511+
NR_ISOLATED_ANON + page_is_file_cache(head),
1512+
hpage_nr_pages(head));
14941513
}
14951514
put_and_set:
14961515
/*

0 commit comments

Comments
 (0)