From: Qi Zheng <qi.zheng@linux.dev>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
muchun.song@linux.dev, akpm@linux-foundation.org,
osalvador@suse.de, azpijr@gmail.com, lance.yang@linux.dev,
Qi Zheng <zhengqi.arch@bytedance.com>
Subject: Re: [PATCH v3 0/3] mm: hugetlb: fix CMA-related issues
Date: Thu, 19 Nov 2026 10:05:13 +0800 [thread overview]
Message-ID: <ec86fecf-0919-4da7-b675-3a9be49b50f5@linux.dev> (raw)
In-Reply-To: <3e4b8ed8-c435-4fb6-ac74-b3a9eb40504d@kernel.org>
On 11/18/26 11:24 PM, David Hildenbrand (Arm) wrote:
> On 11/17/26 07:55, Qi Zheng wrote:
>> Hi David,
>>
>> On 11/16/26 8:07 PM, David Hildenbrand (Arm) wrote:
>>>
>>> Hi,
>>>
>>> sorry somehow I missed your mail.
>>>
>>>
>>>
>>> Ugh, what a hacky mess people created.
>>>
>>>
>>> That would be cleanest. Would it break existing setups?
>>
>> Yes, this requires an existing user to explicitly configure a 32M memory
>> pool.
>>
>> But in practice there shouldn't be such a user today, otherwise the
>> misalignment issue would have surfaced long ago, wouldn't it?
>>
>>>
>>>
>>> Another quick-fix idea could be to always allocate larger folios first.
>>>
>>> That way we should avoid any holes, right>
>>
>> Ah, this looks feasible. How about the following?
>>
>> (If that looks good, this could go as a stable-first fix.)
>>
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> index 6fba92b0f6749..32e65ce347c90 100644
>> --- a/mm/hugetlb.c
>> +++ b/mm/hugetlb.c
>> @@ -4556,6 +4556,22 @@ void __init hugetlb_bootmem_set_nodes(void)
>> node_set(nid, hugetlb_bootmem_nodes);
>> }
>>
>> +/* Return the largest early-CMA hstate below the given order. */
>> +static struct hstate * __init
>> +hugetlb_next_early_cma_hstate(unsigned int order)
>> +{
>> + struct hstate *h, *next = NULL;
>> +
>> + for_each_hstate(h) {
>> + if (!hugetlb_early_cma(h) || huge_page_order(h) >= order)
>> + continue;
>> + if (!next || huge_page_order(h) > huge_page_order(next))
>> + next = h;
>> + }
>> +
>> + return next;
>> +}
>> +
>> void __init hugetlb_bootmem_alloc(void)
>> {
>> struct hstate *h;
>> @@ -4571,9 +4587,19 @@ void __init hugetlb_bootmem_alloc(void)
>> for_each_hstate(h) {
>> h->next_nid_to_alloc = first_online_node;
>>
>> - if (hstate_is_gigantic(h))
>> + if (hstate_is_gigantic(h) && !hugetlb_early_cma(h))
>> hugetlb_hstate_alloc_pages(h);
>> }
>> +
>> + /*
>> + * CMA ranges are aligned to the largest supported size. Allocate larger
>> + * sizes first to keep the early reservation cursor aligned without gaps.
>> + */
>> + h = hugetlb_next_early_cma_hstate(UINT_MAX);
>> + while (h) {
>> + hugetlb_hstate_alloc_pages(h);
>> + h = hugetlb_next_early_cma_hstate(huge_page_order(h));
>> + }
>> }
>>
>> /*
>
> I think this should do. Best to send out a proper patch.
Okay, will post a proper patch.
Thanks,
Qi
>
prev parent reply other threads:[~2026-11-19 2:05 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 10:30 Qi Zheng
2026-11-07 10:30 ` [PATCH v3 1/3] x86: hugetlb: disable default CMA reservations on 32-bit kernel Qi Zheng
2026-11-07 10:30 ` [PATCH v3 2/3] mm: gup: allow long-term pins of CMA-allocated HugeTLB folios Qi Zheng
2026-11-07 17:58 ` David Hildenbrand (Arm)
2026-11-09 3:10 ` Qi Zheng
2026-11-11 7:43 ` David Hildenbrand (Arm)
2026-11-11 10:26 ` Qi Zheng
2026-11-11 22:26 ` Frank van der Linden
2026-11-12 3:27 ` Qi Zheng
2026-11-12 8:36 ` David Hildenbrand (Arm)
2026-11-12 8:40 ` David Hildenbrand (Arm)
2026-11-07 10:30 ` [PATCH v3 3/3] mm: hugetlb: fix GFP mask propagation to CMA Qi Zheng
2026-11-07 17:02 ` Oscar Salvador (SUSE)
2026-11-09 3:10 ` Qi Zheng
2026-11-11 22:05 ` [PATCH v3 0/3] mm: hugetlb: fix CMA-related issues David Hildenbrand (Arm)
2026-11-12 3:25 ` Qi Zheng
2026-11-16 2:01 ` Qi Zheng
2026-11-16 12:07 ` David Hildenbrand (Arm)
2026-11-17 6:55 ` Qi Zheng
2026-11-18 15:24 ` David Hildenbrand (Arm)
2026-11-19 2:05 ` Qi Zheng [this message]
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=ec86fecf-0919-4da7-b675-3a9be49b50f5@linux.dev \
--to=qi.zheng@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=azpijr@gmail.com \
--cc=david@kernel.org \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=zhengqi.arch@bytedance.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
all inboxes | Powered by JetHome®