[PATCH][v2] mm/hugetlb: early exit from hugetlb_pages_alloc_boot() when max_huge_pages=0

From: lirongqing
Date: Thu Aug 14 2025 - 06:33:37 EST


From: Li RongQing <lirongqing@xxxxxxxxx>

Optimize hugetlb_pages_alloc_boot() to return immediately when
max_huge_pages is 0, avoiding unnecessary CPU cycles and the below
log message when hugepages aren't configured in the kernel command
line.
[ 3.702280] HugeTLB: allocation took 0ms with hugepage_allocation_threads=32

Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
---
diff with v1: adding the reduced log messages in commit header

mm/hugetlb.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 753f99b..514fab5 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3654,6 +3654,9 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h)
return;
}

+ if (!h->max_huge_pages)
+ return;
+
/* do node specific alloc */
if (hugetlb_hstate_alloc_pages_specific_nodes(h))
return;
--
2.9.4