Skip to content

Commit ba98828

Browse files
kiryltorvalds
authored andcommitted
thp: add option to setup migration entries during PMD split
We are going to use migration PTE entries to stabilize page counts. If the page is mapped with PMDs we need to split the PMD and setup migration entries. It's reasonable to combine these operations to avoid double-scanning over the page table. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Tested-by: Sasha Levin <sasha.levin@oracle.com> Tested-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Jerome Marchand <jmarchan@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Rik van Riel <riel@redhat.com> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Steve Capper <steve.capper@linaro.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.cz> Cc: Christoph Lameter <cl@linux.com> Cc: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent eef1b3b commit ba98828

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎mm/huge_memory.c‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,7 @@ static void __split_huge_zero_page_pmd(struct vm_area_struct *vma,
26952695
}
26962696

26972697
static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
2698-
unsigned long haddr)
2698+
unsigned long haddr, bool freeze)
26992699
{
27002700
struct mm_struct *mm = vma->vm_mm;
27012701
struct page *page;
@@ -2739,12 +2739,18 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
27392739
* transferred to avoid any possibility of altering
27402740
* permissions across VMAs.
27412741
*/
2742-
entry = mk_pte(page + i, vma->vm_page_prot);
2743-
entry = maybe_mkwrite(pte_mkdirty(entry), vma);
2744-
if (!write)
2745-
entry = pte_wrprotect(entry);
2746-
if (!young)
2747-
entry = pte_mkold(entry);
2742+
if (freeze) {
2743+
swp_entry_t swp_entry;
2744+
swp_entry = make_migration_entry(page + i, write);
2745+
entry = swp_entry_to_pte(swp_entry);
2746+
} else {
2747+
entry = mk_pte(page + i, vma->vm_page_prot);
2748+
entry = maybe_mkwrite(pte_mkdirty(entry), vma);
2749+
if (!write)
2750+
entry = pte_wrprotect(entry);
2751+
if (!young)
2752+
entry = pte_mkold(entry);
2753+
}
27482754
pte = pte_offset_map(&_pmd, haddr);
27492755
BUG_ON(!pte_none(*pte));
27502756
set_pte_at(mm, haddr, pte, entry);
@@ -2785,7 +2791,7 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
27852791
mmu_notifier_invalidate_range_start(mm, haddr, haddr + HPAGE_PMD_SIZE);
27862792
ptl = pmd_lock(mm, pmd);
27872793
if (likely(pmd_trans_huge(*pmd)))
2788-
__split_huge_pmd_locked(vma, pmd, haddr);
2794+
__split_huge_pmd_locked(vma, pmd, haddr, false);
27892795
spin_unlock(ptl);
27902796
mmu_notifier_invalidate_range_end(mm, haddr, haddr + HPAGE_PMD_SIZE);
27912797
}

0 commit comments

Comments
 (0)