From: Qi Zheng <qi.zheng@linux.dev>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Qi Zheng <zhengqi.arch@bytedance.com>,
muchun.song@linux.dev, akpm@linux-foundation.org,
osalvador@suse.de, azpijr@gmail.com, lance.yang@linux.dev
Subject: Re: [PATCH v3 0/3] mm: hugetlb: fix CMA-related issues
Date: Mon, 16 Nov 2026 10:01:15 +0800 [thread overview]
Message-ID: <bc6ffcff-3aaa-43da-91b4-82f27513c761@linux.dev> (raw)
In-Reply-To: <7e733c3b-2aa2-406e-a5ca-cd9a2c872f9f@bytedance.com>
On 11/12/26 11:25 AM, Qi Zheng wrote:
> Hi David,
>
> On 11/12/26 6:05 AM, David Hildenbrand (Arm) wrote:
>> On 11/7/26 11:30, Qi Zheng wrote:
>>> From: Qi Zheng <zhengqi.arch@bytedance.com>
>>>
>>> Hi all,
>>>
>>> This series fixes three CMA-related issues in HugeTLB reservation,
>>> long-term pinning and allocation:
>>>
>>
>> Can I hand you over another CMA-related hugetlb problem?
>>
>> On arm64, we can end up allocating 1GiB and 32MiB hugetlb folios from the cma
>> region.
>>
>> Doing that dynamically is not a problem. Doing it during boot doesn't quite work.
>>
>> cma_reserve_early() does not handle any kind of alignment.
>>
>> So if you allocate a 32M folio followed by a 1G folio, the 1G folio will
>> suddenly start at offset 32M, not being naturally aligned in physical address space.
>
> Yes.
>
>>
>> Likely cma_reserve_early() must be taught to align (and maybe consume an order
>> instead of a size), similar to how the dynamic cma allocations work.
>
> However, simply adding alignment would leave gaps that the
> current activation code cannot distinguish from actual reservations.
>
> The early allocation path would become:
>
> hugetlb_cma_alloc_bootmem()
> -> cma_reserve_early()
> pfn = ALIGN(cmr->early_pfn, nr_pages);
> cmr->early_pfn = pfn + nr_pages;
> cma->available_count -= nr_pages;
>
> For a CMA range starting at 4 GiB, reserving 32 MiB followed by 1 GiB
> would produce:
>
> 4 GiB 4 GiB + 32 MiB 5 GiB 6 GiB
> | 32 MiB used |------ 992 MiB gap ------| 1 GiB used |
> ^
> early_pfn
>
> Later, cma_activate_area() marks the entire prefix below early_pfn as
> allocated, including the gap:
>
> count = early_pfn[r] - cmr->base_pfn;
> bitmap_count = cma_bitmap_pages_to_bits(cma, count);
> bitmap_set(cmr->bitmap, 0, bitmap_count);
>
> It only initializes and frees pageblocks after that cursor:
>
> for (pfn = early_pfn[r]; pfn < cmr->base_pfn + cmr->count;
> pfn += pageblock_nr_pages)
> init_cma_reserved_pageblock(pfn_to_page(pfn));
>
> The gap therefore remains reserved and marked allocated. Releasing the
> two HugeTLB folios only clears their own ranges through
> cma_release_frozen(); neither release covers the gap. Those 992 MiB
> would be permanently lost from usable CMA capacity.
>
> So we would also need to track the gaps, clear their bitmap bits during
> activation, and initialize them as free CMA pageblocks.
>
>>
>
> Another possibility would be to give 32 MiB pages their own pool,
> similar to the separate PMD-sized pool proposed in the other series. On
> arm64 with 4 KiB base pages, 2 MiB, 32 MiB and 1 GiB allocations would
> then use separate pools.
>
> This could work during early boot too: hugetlb_cma_reserve() establishes
> the CMA areas and their ranges before hugetlb_bootmem_alloc() runs.
> Although the bitmaps are allocated later, each range already has its
> own early_pfn. With naturally aligned ranges and one allocation size
> per pool, the cursors would stay aligned without creating gaps.
>
> What do you think?
Hi David, gentle ping.
I’d like to update to v5 so that I can continue advancing the support
for 2M hugetlb CMA. Regarding this issue, would you like me to include a
fix in v5? If you agree with the "split pool" approach, we can handle it
as part of the patch set for 2M hugetlb CMA support.
Thanks,
Qi
>
> Thanks,
> Qi
next prev parent reply other threads:[~2026-11-16 2:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 10:30 [PATCH v3 0/3] mm: hugetlb: fix CMA-related issues 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 [this message]
2026-11-16 12:07 ` David Hildenbrand (Arm)
2026-11-17 6:55 ` Qi Zheng
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=bc6ffcff-3aaa-43da-91b4-82f27513c761@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.