From: Zi Yan <ziy@nvidia.com>
To: Muchun Song <muchun.song@linux.dev>,
Kaitao Cheng <kaitao.cheng@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>,
David Hildenbrand <david@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Mike Kravetz <mike.kravetz@oracle.com>,
Frank van der Linden <fvdl@google.com>,
Michal Hocko <mhocko@suse.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
Chris Down <chris@chrisdown.name>,
Roman Gushchin <roman.gushchin@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Kaitao Cheng <chengkaitao@kylinos.cn>
Subject: Re: [PATCH 2/3] mm/hugetlb: preserve CMA flag when returning folios to the pool
Date: Wed, 28 Oct 2026 10:00:26 -0400 [thread overview]
Message-ID: <379883F4-4F55-4206-98DD-CB10D5DAF0FA@nvidia.com> (raw)
In-Reply-To: <0005A5C9-47ED-45EF-BEA8-2693DAA7C46E@linux.dev>
On 28 Oct 2026, at 9:56, Muchun Song wrote:
>> On Oct 28, 2026, at 19:33, Kaitao Cheng <kaitao.cheng@linux.dev> wrote:
>>
>> From: Kaitao Cheng <chengkaitao@kylinos.cn>
>>
>> When vmemmap restoration fails, add_hugetlb_folio() returns the folio
>> to the hugetlb pool. It clears folio->private and restores only
>> HPG_vmemmap_optimized, losing HPG_cma on CMA-allocated folios.
>>
>> A later successful free then bypasses hugetlb_cma_free_frozen_folio()
>> and returns the pages through free_frozen_pages(). The CMA allocation
>> bitmap remains set, so the range is unavailable for future CMA
>> allocations.
>>
>> Save the CMA flag before resetting folio->private and restore it along
>> with the vmemmap optimization flag.
>
> We already knew this issue. Cc Zi Yan. Seems he hasn't sent a fix.
Thanks. No, I have not formed a proper patch yet.
>
> But we want a different solution. See:
>
> https://lore.kernel.org/linux-mm/A1A14368-7A43-40ED-B2AB-C2EC2C5FFB1D@linux.dev/
Feel free to grab my version from the link and add
VM_WARN_ON_ONCE_FOLIO()s Muchun suggested. You can add
Suggested-by: Zi Yan <ziy@nvidia.com> in your patch.
Thanks.
>
> Thanks,
> Muchun
>
>>
>> Fixes: d2d786714080 ("mm/hugetlb: enable bootmem allocation from CMA areas")
>> Closes: https://sashiko.dev/#/bug/linux-5363eb09-9c3c-4f8b-9f3c-a998a8c4b258
>> Signed-off-by: Kaitao Cheng <chengkaitao@kylinos.cn>
>> ---
>> mm/hugetlb.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> index 4a008afaedf9..8da4bab676c9 100644
>> --- a/mm/hugetlb.c
>> +++ b/mm/hugetlb.c
>> @@ -1437,6 +1437,7 @@ void remove_hugetlb_folio(struct hstate *h, struct folio *folio,
>> void add_hugetlb_folio(struct hstate *h, struct folio *folio,
>> bool adjust_surplus)
>> {
>> + bool cma = folio_test_hugetlb_cma(folio);
>> int nid = folio_nid(folio);
>>
>> VM_BUG_ON_FOLIO(!folio_test_hugetlb_vmemmap_optimized(folio), folio);
>> @@ -1453,9 +1454,11 @@ void add_hugetlb_folio(struct hstate *h, struct folio *folio,
>> }
>>
>> __folio_set_hugetlb(folio);
>> - /* Clear all folio->private flags except hugetlb_vmemmap_optimized. */
>> + /* Preserve the vmemmap optimization state and CMA allocation origin. */
>> folio->private = NULL;
>> folio_set_hugetlb_vmemmap_optimized(folio);
>> + if (cma)
>> + folio_set_hugetlb_cma(folio);
>>
>> arch_clear_hugetlb_flags(folio);
>> enqueue_hugetlb_folio(h, folio);
>> --
>> 2.53.0
>>
Best Regards,
Yan, Zi
next prev parent reply other threads:[~2026-10-28 14:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 11:33 [PATCH 0/3] Subject: mm/hugetlb: fix CMA handling and surplus allocation accounting Kaitao Cheng
2026-10-28 11:33 ` [PATCH 1/3] mm/hugetlb_cma: fix incorrect hugetlb_cma_size assignment on malformed input Kaitao Cheng
2026-10-28 13:47 ` Muchun Song
2026-10-28 14:46 ` Oscar Salvador (SUSE)
2026-10-28 11:33 ` [PATCH 2/3] mm/hugetlb: preserve CMA flag when returning folios to the pool Kaitao Cheng
2026-10-28 13:56 ` Muchun Song
2026-10-28 14:00 ` Zi Yan [this message]
2026-10-28 11:33 ` [PATCH 3/3] mm/hugetlb: fix NR_HUGETLB accounting for unused surplus folios Kaitao Cheng
2026-10-28 15:01 ` Oscar Salvador (SUSE)
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=379883F4-4F55-4206-98DD-CB10D5DAF0FA@nvidia.com \
--to=ziy@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chengkaitao@kylinos.cn \
--cc=chris@chrisdown.name \
--cc=david@kernel.org \
--cc=fvdl@google.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kaitao.cheng@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=mike.kravetz@oracle.com \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=roman.gushchin@linux.dev \
/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®