Skip to content

Commit 4daae3b

Browse files
author
Mel Gorman
committed
mm: mempolicy: Use _PAGE_NUMA to migrate pages
Note: Based on "mm/mpol: Use special PROT_NONE to migrate pages" but sufficiently different that the signed-off-bys were dropped Combine our previous _PAGE_NUMA, mpol_misplaced and migrate_misplaced_page() pieces into an effective migrate on fault scheme. Note that (on x86) we rely on PROT_NONE pages being !present and avoid the TLB flush from try_to_unmap(TTU_MIGRATION). This greatly improves the page-migration performance. Based-on-work-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Mel Gorman <mgorman@suse.de>
1 parent 149c33e commit 4daae3b

3 files changed

Lines changed: 60 additions & 12 deletions

File tree

‎include/linux/huge_mm.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ static inline struct page *compound_trans_head(struct page *page)
160160
return page;
161161
}
162162

163-
extern int do_huge_pmd_numa_page(struct mm_struct *mm, unsigned long addr,
164-
pmd_t pmd, pmd_t *pmdp);
163+
extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
164+
unsigned long addr, pmd_t pmd, pmd_t *pmdp);
165165

166166
#else /* CONFIG_TRANSPARENT_HUGEPAGE */
167167
#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
@@ -200,9 +200,10 @@ static inline int pmd_trans_huge_lock(pmd_t *pmd,
200200
return 0;
201201
}
202202

203-
static inline int do_huge_pmd_numa_page(struct mm_struct *mm, unsigned long addr,
204-
pmd_t pmd, pmd_t *pmdp)
203+
static inline int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
204+
unsigned long addr, pmd_t pmd, pmd_t *pmdp)
205205
{
206+
return 0;
206207
}
207208

208209
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */

‎mm/huge_memory.c‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/freezer.h>
1919
#include <linux/mman.h>
2020
#include <linux/pagemap.h>
21+
#include <linux/migrate.h>
2122
#include <asm/tlb.h>
2223
#include <asm/pgalloc.h>
2324
#include "internal.h"
@@ -1019,24 +1020,48 @@ struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,
10191020
}
10201021

10211022
/* NUMA hinting page fault entry point for trans huge pmds */
1022-
int do_huge_pmd_numa_page(struct mm_struct *mm, unsigned long addr,
1023-
pmd_t pmd, pmd_t *pmdp)
1023+
int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
1024+
unsigned long addr, pmd_t pmd, pmd_t *pmdp)
10241025
{
1025-
struct page *page;
1026+
struct page *page = NULL;
10261027
unsigned long haddr = addr & HPAGE_PMD_MASK;
1028+
int target_nid;
10271029

10281030
spin_lock(&mm->page_table_lock);
10291031
if (unlikely(!pmd_same(pmd, *pmdp)))
10301032
goto out_unlock;
10311033

10321034
page = pmd_page(pmd);
1035+
get_page(page);
1036+
spin_unlock(&mm->page_table_lock);
1037+
1038+
target_nid = mpol_misplaced(page, vma, haddr);
1039+
if (target_nid == -1)
1040+
goto clear_pmdnuma;
1041+
1042+
/*
1043+
* Due to lacking code to migrate thp pages, we'll split
1044+
* (which preserves the special PROT_NONE) and re-take the
1045+
* fault on the normal pages.
1046+
*/
1047+
split_huge_page(page);
1048+
put_page(page);
1049+
return 0;
1050+
1051+
clear_pmdnuma:
1052+
spin_lock(&mm->page_table_lock);
1053+
if (unlikely(!pmd_same(pmd, *pmdp)))
1054+
goto out_unlock;
1055+
10331056
pmd = pmd_mknonnuma(pmd);
10341057
set_pmd_at(mm, haddr, pmdp, pmd);
10351058
VM_BUG_ON(pmd_numa(*pmdp));
10361059
update_mmu_cache_pmd(vma, addr, pmdp);
10371060

10381061
out_unlock:
10391062
spin_unlock(&mm->page_table_lock);
1063+
if (page)
1064+
put_page(page);
10401065
return 0;
10411066
}
10421067

‎mm/memory.c‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <linux/swapops.h>
5858
#include <linux/elf.h>
5959
#include <linux/gfp.h>
60+
#include <linux/migrate.h>
6061

6162
#include <asm/io.h>
6263
#include <asm/pgalloc.h>
@@ -3451,8 +3452,9 @@ static int do_nonlinear_fault(struct mm_struct *mm, struct vm_area_struct *vma,
34513452
int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
34523453
unsigned long addr, pte_t pte, pte_t *ptep, pmd_t *pmd)
34533454
{
3454-
struct page *page;
3455+
struct page *page = NULL;
34553456
spinlock_t *ptl;
3457+
int current_nid, target_nid;
34563458

34573459
/*
34583460
* The "pte" at this point cannot be used safely without
@@ -3465,8 +3467,11 @@ int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
34653467
*/
34663468
ptl = pte_lockptr(mm, pmd);
34673469
spin_lock(ptl);
3468-
if (unlikely(!pte_same(*ptep, pte)))
3469-
goto out_unlock;
3470+
if (unlikely(!pte_same(*ptep, pte))) {
3471+
pte_unmap_unlock(ptep, ptl);
3472+
goto out;
3473+
}
3474+
34703475
pte = pte_mknonnuma(pte);
34713476
set_pte_at(mm, addr, ptep, pte);
34723477
update_mmu_cache(vma, addr, ptep);
@@ -3477,8 +3482,25 @@ int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
34773482
return 0;
34783483
}
34793484

3480-
out_unlock:
3485+
get_page(page);
3486+
current_nid = page_to_nid(page);
3487+
target_nid = mpol_misplaced(page, vma, addr);
34813488
pte_unmap_unlock(ptep, ptl);
3489+
if (target_nid == -1) {
3490+
/*
3491+
* Account for the fault against the current node if it not
3492+
* being replaced regardless of where the page is located.
3493+
*/
3494+
current_nid = numa_node_id();
3495+
put_page(page);
3496+
goto out;
3497+
}
3498+
3499+
/* Migrate to the requested node */
3500+
if (migrate_misplaced_page(page, target_nid))
3501+
current_nid = target_nid;
3502+
3503+
out:
34823504
return 0;
34833505
}
34843506

@@ -3655,7 +3677,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
36553677
barrier();
36563678
if (pmd_trans_huge(orig_pmd)) {
36573679
if (pmd_numa(*pmd))
3658-
return do_huge_pmd_numa_page(mm, address,
3680+
return do_huge_pmd_numa_page(mm, vma, address,
36593681
orig_pmd, pmd);
36603682

36613683
if ((flags & FAULT_FLAG_WRITE) && !pmd_write(orig_pmd)) {

0 commit comments

Comments
 (0)