Skip to content

Commit ec4858e

Browse files
author
Matthew Wilcox (Oracle)
committed
mm/mempolicy: Use vma_alloc_folio() in new_page()
Simplify new_page() by unifying the THP and base page cases, and handle orders other than 0 and HPAGE_PMD_ORDER correctly. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Zi Yan <[email protected]> Reviewed-by: William Kucharski <[email protected]>
1 parent f584b68 commit ec4858e

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

mm/mempolicy.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,10 @@ int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
11911191
*/
11921192
static struct page *new_page(struct page *page, unsigned long start)
11931193
{
1194+
struct folio *dst, *src = page_folio(page);
11941195
struct vm_area_struct *vma;
11951196
unsigned long address;
1197+
gfp_t gfp = GFP_HIGHUSER_MOVABLE | __GFP_RETRY_MAYFAIL;
11961198

11971199
vma = find_vma(current->mm, start);
11981200
while (vma) {
@@ -1202,24 +1204,19 @@ static struct page *new_page(struct page *page, unsigned long start)
12021204
vma = vma->vm_next;
12031205
}
12041206

1205-
if (PageHuge(page)) {
1206-
return alloc_huge_page_vma(page_hstate(compound_head(page)),
1207+
if (folio_test_hugetlb(src))
1208+
return alloc_huge_page_vma(page_hstate(&src->page),
12071209
vma, address);
1208-
} else if (PageTransHuge(page)) {
1209-
struct page *thp;
12101210

1211-
thp = alloc_hugepage_vma(GFP_TRANSHUGE, vma, address,
1212-
HPAGE_PMD_ORDER);
1213-
if (!thp)
1214-
return NULL;
1215-
prep_transhuge_page(thp);
1216-
return thp;
1217-
}
1211+
if (folio_test_large(src))
1212+
gfp = GFP_TRANSHUGE;
1213+
12181214
/*
1219-
* if !vma, alloc_page_vma() will use task or system default policy
1215+
* if !vma, vma_alloc_folio() will use task or system default policy
12201216
*/
1221-
return alloc_page_vma(GFP_HIGHUSER_MOVABLE | __GFP_RETRY_MAYFAIL,
1222-
vma, address);
1217+
dst = vma_alloc_folio(gfp, folio_order(src), vma, address,
1218+
folio_test_large(src));
1219+
return &dst->page;
12231220
}
12241221
#else
12251222

0 commit comments

Comments
 (0)