From: David Hildenbrand <david@redhat.com>
To: lirongqing <lirongqing@baidu.com>,
muchun.song@linux.dev, osalvador@suse.de,
akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, giorgitchankvetadze1997@gmail.com
Cc: Wenjie Xu <xuwenjie04@baidu.com>
Subject: Re: [PATCH] mm/hugetlb: two-phase hugepage allocation when reservation is high
Date: Tue, 26 Aug 2025 15:25:17 +0200 [thread overview]
Message-ID: <f8940d8d-0cb8-4b10-854d-6097d1a2c39c@redhat.com> (raw)
In-Reply-To: <20250826101840.3954-1-lirongqing@baidu.com>
On 26.08.25 12:18, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
>
> When the total reserved hugepages account for 95% or more of system RAM
> (common in cloud computing on physical servers), allocating them all in one
> go can lead to OOM or fail to allocate huge page during early boot.
>
> The commit 91f386bf0772 ("hugetlb: batch freeing of vmemmap pages") can
> worsen peak memory pressure under these conditions by deferring page frees,
> exacerbating allocation failures. To prevent this, split the allocation
> into two equal batches whenever
> huge_reserved_pages >= totalram_pages() * 90 / 100.
>
> This change does not alter the number of padata worker threads per batch;
> it merely introduces a second round of padata_do_multithreaded(). The added
> overhead of restarting the worker threads is minimal.
>
> The result on a 256G memory machine as below:
> Before:
> [ 4.350400] HugeTLB: allocation took 706ms with hugepage_allocation_threads=32
> [ 4.351577] HugeTLB: allocating 128512 of page size 2.00 MiB failed. Only allocated 128074 hugepages.
> [ 4.355608] HugeTLB: registered 2.00 MiB page size, pre-allocated 128074 pages
> After:
> [ 3.561088] HugeTLB: two-phase hugepage allocation is used
> [ 4.280300] HugeTLB: allocation took 712ms with hugepage_allocation_threads=32
> [ 4.281054] HugeTLB: registered 2.00 MiB page size, pre-allocated 128512 pages
>
> Fixes: 91f386bf0772 ("hugetlb: batch freeing of vmemmap pages")
>
> Co-developed-by: Wenjie Xu <xuwenjie04@baidu.com>
> Signed-off-by: Wenjie Xu <xuwenjie04@baidu.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> Diff with v1: add log if two-phase hugepage allocation is triggered
> add the knod to control split ratio
>
> Documentation/admin-guide/mm/hugetlbpage.rst | 12 +++++++++
> mm/hugetlb.c | 39 ++++++++++++++++++++++++++--
> 2 files changed, 49 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/admin-guide/mm/hugetlbpage.rst b/Documentation/admin-guide/mm/hugetlbpage.rst
> index 67a9419..5cfb6e3 100644
> --- a/Documentation/admin-guide/mm/hugetlbpage.rst
> +++ b/Documentation/admin-guide/mm/hugetlbpage.rst
> @@ -156,6 +156,18 @@ hugepage_alloc_threads
> hugepage_alloc_threads=8
>
> Note that this parameter only applies to non-gigantic huge pages.
> +
> +hugepage_split_ratio
> + Controls the threshold for two-phase hugepage allocation.
> + When the total number of reserved hugepages (huge_reserved_pages) exceeds
> + (totalram_pages * hugepage_split_ratio / 100), the hugepage allocation process
> + during boot is split into two batches.
> +
> + Default value is 90, meaning the two-phase allocation is triggered when
> + reserved hugepages exceed 90% of total system RAM.
> + The value can be adjusted via the kernel command line parameter
> + "hugepage_split_ratio=". Valid range is 1 to 99.
Can we just do something reasonable here and not introduce toggles where
nobody knows how to really set a reasonable value?
This really sounds like something we should not be exporting to users.
Also, can't we fail lightly during the first attempt and dynamically
decide if we should do a second pase?
--
Cheers
David / dhildenb
next prev parent reply other threads:[~2025-08-26 13:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 10:18 [PATCH] mm/hugetlb: two-phase hugepage allocation when reservation is high lirongqing
2025-08-26 13:25 ` David Hildenbrand [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-08-27 12:33 Li,Rongqing
2025-08-27 12:37 ` David Hildenbrand
2025-08-27 4:12 Li,Rongqing
2025-08-27 11:51 ` David Hildenbrand
2025-08-22 11:28 lirongqing
2025-08-22 13:50 ` Giorgi Tchankvetadze
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f8940d8d-0cb8-4b10-854d-6097d1a2c39c@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=giorgitchankvetadze1997@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lirongqing@baidu.com \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=xuwenjie04@baidu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).