Re: [PATCH v2 1/9] mm: hugetlb: convert to use more alloc_fresh_hugetlb_folio()

Kefeng Wang
2025-09-08T12:59:11Z

On 2025/9/8 17:21, Oscar Salvador wrote:
> On Tue, Sep 02, 2025 at 08:48:12PM +0800, Kefeng Wang wrote:
>> Simplify alloc_fresh_hugetlb_folio() and convert more functions
>> to use it, which help us to remove prep_new_hugetlb_folio() and
>> __prep_new_hugetlb_folio().
>>
>> Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>
> Acked-by: Oscar Salvador <osalvador@suse.de>
>
> But...
>
>> /*
>> - * Common helper to allocate a fresh hugetlb page. All specific allocators
>> - * should use this function to get new hugetlb pages
>> + * Common helper to allocate a fresh hugetlb folio. All specific allocators
>> + * should use this function to get new hugetlb folio
>> *
>> - * Note that returned page is 'frozen': ref count of head page and all tail
>> + * Note that returned folio is 'frozen': ref count of head page and all tail
>> * pages is zero.
>> */
>> static struct folio *alloc_fresh_hugetlb_folio(struct hstate *h,
>> @@ -2016,14 +2002,9 @@ static struct folio *alloc_fresh_hugetlb_folio(struct hstate *h,
>> {
>> struct folio *folio;
>>
>> - if (hstate_is_gigantic(h))
>> - folio = alloc_gigantic_folio(h, gfp_mask, nid, nmask);
>> - else
>> - folio = alloc_buddy_hugetlb_folio(h, gfp_mask, nid, nmask, NULL);
>> - if (!folio)
>> - return NULL;
>> -
>> - prep_new_hugetlb_folio(h, folio, folio_nid(folio));
>> + folio = only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, NULL);
>> + if (folio)
>> + hugetlb_vmemmap_optimize_folio(h, folio);
>> return folio;
>
> We no longer do the accounting in the callee but in the caller, so it might be
> tricky to grasp why.
> I would add a comment above after the "Note that returned ..." stating that the
> accounting must be done in the caller, should someone else add another call to
> alloc_fresh_hugetlb_folio().
> Hugetlb code is tricky enough, let us make it crystal clear.

OK， will a comment in next version.

>
> Thanks
>
>