Skip to content

Commit 327e9fd

Browse files
committed
mm: Split huge pages on write-notify or COW
The functions wp_huge_pmd() and wp_huge_pud() currently relies on the huge_fault() callback to split huge page table entries if needed. However for module users that requires export of the split_huge_xxx() functionality which may be undesired. Instead split pre-existing huge page-table entries on VM_FAULT_FALLBACK return. We currently only do COW and write-notify on the PTE level, so if the huge_fault() handler returns VM_FAULT_FALLBACK on wp faults, split the huge pages and page-table entries. Also do this for huge PUDs if there is no huge_fault() handler and the vma is not anonymous, similar to how it's done for PMDs. Note that fs/dax.c still does the splitting in the huge_fault() handler, but as huge_fault() A follow-up patch can remove the dax.c split_huge_pmd() if needed. Cc: Andrew Morton <[email protected]> Cc: Michal Hocko <[email protected]> Cc: "Matthew Wilcox (Oracle)" <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Ralph Campbell <[email protected]> Cc: "Jérôme Glisse" <[email protected]> Cc: "Christian König" <[email protected]> Cc: Dan Williams <[email protected]> Signed-off-by: Thomas Hellstrom (VMware) <[email protected]> Acked-by: Christian König <[email protected]> Acked-by: Andrew Morton <[email protected]>
1 parent 2484ca9 commit 327e9fd

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

mm/memory.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,11 +3951,14 @@ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf, pmd_t orig_pmd)
39513951
{
39523952
if (vma_is_anonymous(vmf->vma))
39533953
return do_huge_pmd_wp_page(vmf, orig_pmd);
3954-
if (vmf->vma->vm_ops->huge_fault)
3955-
return vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PMD);
3954+
if (vmf->vma->vm_ops->huge_fault) {
3955+
vm_fault_t ret = vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PMD);
39563956

3957-
/* COW handled on pte level: split pmd */
3958-
VM_BUG_ON_VMA(vmf->vma->vm_flags & VM_SHARED, vmf->vma);
3957+
if (!(ret & VM_FAULT_FALLBACK))
3958+
return ret;
3959+
}
3960+
3961+
/* COW or write-notify handled on pte level: split pmd. */
39593962
__split_huge_pmd(vmf->vma, vmf->pmd, vmf->address, false, NULL);
39603963

39613964
return VM_FAULT_FALLBACK;
@@ -3968,12 +3971,20 @@ static inline bool vma_is_accessible(struct vm_area_struct *vma)
39683971

39693972
static vm_fault_t create_huge_pud(struct vm_fault *vmf)
39703973
{
3971-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
3974+
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \
3975+
defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)
39723976
/* No support for anonymous transparent PUD pages yet */
39733977
if (vma_is_anonymous(vmf->vma))
3974-
return VM_FAULT_FALLBACK;
3975-
if (vmf->vma->vm_ops->huge_fault)
3976-
return vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD);
3978+
goto split;
3979+
if (vmf->vma->vm_ops->huge_fault) {
3980+
vm_fault_t ret = vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD);
3981+
3982+
if (!(ret & VM_FAULT_FALLBACK))
3983+
return ret;
3984+
}
3985+
split:
3986+
/* COW or write-notify not handled on PUD level: split pud.*/
3987+
__split_huge_pud(vmf->vma, vmf->pud, vmf->address);
39773988
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
39783989
return VM_FAULT_FALLBACK;
39793990
}

0 commit comments

Comments
 (0)