The patch titled Subject: thp: lazy huge zero page allocation has been added to the -mm tree. Its filename is thp-lazy-huge-zero-page-allocation.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx> Subject: thp: lazy huge zero page allocation Instead of allocating huge zero page on hugepage_init() we can postpone it until first huge zero page map. It saves memory if THP is not in use. cmpxchg() is used to avoid race on huge_zero_pfn initialization. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx> Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx> Cc: "H. Peter Anvin" <hpa@xxxxxxxxxxxxxxx> Cc: Mel Gorman <mel@xxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/huge_memory.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff -puN mm/huge_memory.c~thp-lazy-huge-zero-page-allocation mm/huge_memory.c --- a/mm/huge_memory.c~thp-lazy-huge-zero-page-allocation +++ a/mm/huge_memory.c @@ -161,22 +161,24 @@ static int start_khugepaged(void) return err; } -static int init_huge_zero_page(void) +static int init_huge_zero_pfn(void) { struct page *hpage; + unsigned long pfn; hpage = alloc_pages((GFP_TRANSHUGE | __GFP_ZERO) & ~__GFP_MOVABLE, HPAGE_PMD_ORDER); if (!hpage) return -ENOMEM; - - huge_zero_pfn = page_to_pfn(hpage); + pfn = page_to_pfn(hpage); + if (cmpxchg(&huge_zero_pfn, 0, pfn)) + __free_page(hpage); return 0; } static inline bool is_huge_zero_pfn(unsigned long pfn) { - return pfn == huge_zero_pfn; + return huge_zero_pfn && pfn == huge_zero_pfn; } static inline bool is_huge_zero_pmd(pmd_t pmd) @@ -565,10 +567,6 @@ static int __init hugepage_init(void) if (err) return err; - err = init_huge_zero_page(); - if (err) - goto out; - err = khugepaged_slab_init(); if (err) goto out; @@ -591,8 +589,6 @@ static int __init hugepage_init(void) return 0; out: - if (huge_zero_pfn) - __free_page(pfn_to_page(huge_zero_pfn)); hugepage_exit_sysfs(hugepage_kobj); return err; } @@ -736,6 +732,10 @@ int do_huge_pmd_anonymous_page(struct mm return VM_FAULT_OOM; if (!(flags & FAULT_FLAG_WRITE)) { pgtable_t pgtable; + if (unlikely(!huge_zero_pfn && init_huge_zero_pfn())) { + count_vm_event(THP_FAULT_FALLBACK); + goto out; + } pgtable = pte_alloc_one(mm, haddr); if (unlikely(!pgtable)) goto out; _ Patches currently in -mm which might be from kirill.shutemov@xxxxxxxxxxxxxxx are linux-next.patch mm-use-is_enabledconfig_numa-instead-of-numa_build.patch mm-use-is_enabledconfig_compaction-instead-of-compaction_build.patch thp-huge-zero-page-basic-preparation.patch thp-zap_huge_pmd-zap-huge-zero-pmd.patch thp-copy_huge_pmd-copy-huge-zero-page.patch thp-do_huge_pmd_wp_page-handle-huge-zero-page.patch thp-change_huge_pmd-keep-huge-zero-page-write-protected.patch thp-change-split_huge_page_pmd-interface.patch thp-implement-splitting-pmd-for-huge-zero-page.patch thp-setup-huge-zero-page-on-non-write-page-fault.patch thp-lazy-huge-zero-page-allocation.patch thp-implement-refcounting-for-huge-zero-page.patch thp-vmstat-implement-hzp_alloc-and-hzp_alloc_failed-events.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html