Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/hugetlb: retry to allocate for early boot hugepage allocation

In cloud environments with massive hugepage reservations (95%+ of system
RAM), single-attempt allocation during early boot often fails due to
memory pressure.

Commit 91f386bf0772 ("hugetlb: batch freeing of vmemmap pages")
intensified this by deferring page frees, increase peak memory usage
during allocation.

Introduce a retry mechanism that leverages vmemmap optimization reclaim
(~1.6% memory) when available. Upon initial allocation failure, the
system retries until successful or no further progress is made, ensuring
reliable hugepage allocation while preserving batched vmemmap freeing
benefits.

Testing on a 256G machine allocating 252G of hugepages:
Before: 128056/129024 hugepages allocated
After: Successfully allocated all 129024 hugepages

Link: https://lkml.kernel.org/r/20250901082052.3247-1-lirongqing@baidu.com
Signed-off-by: Li RongQing <lirongqing@baidu.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Li RongQing <lirongqing@baidu.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Li RongQing and committed by
Andrew Morton
2a8f3f44 2b79cb3e

+22 -4
+22 -4
mm/hugetlb.c
··· 3593 3593 3594 3594 unsigned long jiffies_start; 3595 3595 unsigned long jiffies_end; 3596 + unsigned long remaining; 3596 3597 3597 3598 job.thread_fn = hugetlb_pages_alloc_boot_node; 3598 - job.start = 0; 3599 - job.size = h->max_huge_pages; 3600 3599 3601 3600 /* 3602 3601 * job.max_threads is 25% of the available cpu threads by default. ··· 3619 3620 } 3620 3621 3621 3622 job.max_threads = hugepage_allocation_threads; 3622 - job.min_chunk = h->max_huge_pages / hugepage_allocation_threads; 3623 3623 3624 3624 jiffies_start = jiffies; 3625 - padata_do_multithreaded(&job); 3625 + do { 3626 + remaining = h->max_huge_pages - h->nr_huge_pages; 3627 + 3628 + job.start = h->nr_huge_pages; 3629 + job.size = remaining; 3630 + job.min_chunk = remaining / hugepage_allocation_threads; 3631 + padata_do_multithreaded(&job); 3632 + 3633 + if (h->nr_huge_pages == h->max_huge_pages) 3634 + break; 3635 + 3636 + /* 3637 + * Retry only if the vmemmap optimization might have been able to free 3638 + * some memory back to the system. 3639 + */ 3640 + if (!hugetlb_vmemmap_optimizable(h)) 3641 + break; 3642 + 3643 + /* Continue if progress was made in last iteration */ 3644 + } while (remaining != (h->max_huge_pages - h->nr_huge_pages)); 3645 + 3626 3646 jiffies_end = jiffies; 3627 3647 3628 3648 pr_info("HugeTLB: allocation took %dms with hugepage_allocation_threads=%ld\n",