Skip to content

Commit e7a00c4

Browse files
aarcange-rhtorvalds
authored andcommitted
thp: add pmd_huge_pte to mm_struct
This increase the size of the mm struct a bit but it is needed to preallocate one pte for each hugepage so that split_huge_page will not require a fail path. Guarantee of success is a fundamental property of split_huge_page to avoid decrasing swapping reliability and to avoid adding -ENOMEM fail paths that would otherwise force the hugepage-unaware VM code to learn rolling back in the middle of its pte mangling operations (if something we need it to learn handling pmd_trans_huge natively rather being capable of rollback). When split_huge_page runs a pte is needed to succeed the split, to map the newly splitted regular pages with a regular pte. This way all existing VM code remains backwards compatible by just adding a split_huge_page* one liner. The memory waste of those preallocated ptes is negligible and so it is worth it. Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Acked-by: Rik van Riel <riel@redhat.com> Acked-by: Mel Gorman <mel@csn.ul.ie> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4e6af67 commit e7a00c4

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎include/linux/mm_types.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ struct mm_struct {
309309
#endif
310310
#ifdef CONFIG_MMU_NOTIFIER
311311
struct mmu_notifier_mm *mmu_notifier_mm;
312+
#endif
313+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
314+
pgtable_t pmd_huge_pte; /* protected by page_table_lock */
312315
#endif
313316
/* How many tasks sharing this mm are OOM_DISABLE */
314317
atomic_t oom_disable_count;

‎kernel/fork.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@ void __mmdrop(struct mm_struct *mm)
529529
mm_free_pgd(mm);
530530
destroy_context(mm);
531531
mmu_notifier_mm_destroy(mm);
532+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
533+
VM_BUG_ON(mm->pmd_huge_pte);
534+
#endif
532535
free_mm(mm);
533536
}
534537
EXPORT_SYMBOL_GPL(__mmdrop);
@@ -669,6 +672,10 @@ struct mm_struct *dup_mm(struct task_struct *tsk)
669672
mm->token_priority = 0;
670673
mm->last_interval = 0;
671674

675+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
676+
mm->pmd_huge_pte = NULL;
677+
#endif
678+
672679
if (!mm_init(mm, tsk))
673680
goto fail_nomem;
674681

0 commit comments

Comments
 (0)