linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Zi Yan <ziy@nvidia.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>,
	Oscar Salvador <osalvador@suse.de>,
	Muchun Song <muchun.song@linux.dev>, <sidhartha.kumar@oracle.com>,
	<jane.chu@oracle.com>, Vlastimil Babka <vbabka@suse.cz>,
	Brendan Jackman <jackmanb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>, <linux-mm@kvack.org>
Subject: Re: [PATCH v2 9/9] mm: hugetlb: allocate frozen pages in alloc_gigantic_folio()
Date: Tue, 9 Sep 2025 15:34:52 +0800	[thread overview]
Message-ID: <631af84e-c2e0-4d4d-b55d-eda41fbe58ba@huawei.com> (raw)
In-Reply-To: <FAA075C3-7C56-434A-BB23-973E947E8F24@nvidia.com>



On 2025/9/9 10:02, Zi Yan wrote:
> On 2 Sep 2025, at 8:48, Kefeng Wang wrote:
> 
>> The alloc_gigantic_folio() will allocate a folio by alloc_contig_range()
> 
> s/will allocate/allocates, since you are describing an existing behavior.
> It confused me when I look at the code change.

OK,

> 
>> with refcount increated and then freeze it, convert to allocate a frozen
>> folio directly to remove the atomic operation about folio refcount, also
>> saving atomic operation during __update_and_free_hugetlb_folio too.
>>
>> Rename some functions to make them more self-explanatory,
>>
>>    folio_alloc_gigantic		-> folio_alloc_frozen_gigantic
>>    cma_alloc/free_folio		-> cma_alloc/free_frozen_folio
> 
> s/cma_alloc/cma_alloc_folio, s/cma_alloc/cma_alloc_frozen_folio.
> If you do not want to type folio multiple times,
> 
> {cma_alloc,free}_folio -> {cma_alloc,free}_frozen_folio would be
> less confusing.
> 
>>    hugetlb_cma_alloc/free_folio	-> hugetlb_cma_alloc/free_frozen_folio
> 
> ditto.

Will update,

> 
>>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>> ---
>>   include/linux/cma.h |  8 ++++----
>>   include/linux/gfp.h | 14 ++++++-------
>>   mm/cma.c            | 22 +++++++++++++-------
>>   mm/hugetlb.c        | 50 +++++++++------------------------------------
>>   mm/hugetlb_cma.c    | 13 ++++++------
>>   mm/hugetlb_cma.h    | 10 ++++-----
>>   6 files changed, 47 insertions(+), 70 deletions(-)
>>
>> diff --git a/include/linux/cma.h b/include/linux/cma.h
>> index e5745d2aec55..cceec7b25bae 100644
>> --- a/include/linux/cma.h
>> +++ b/include/linux/cma.h
>> @@ -57,16 +57,16 @@ extern bool cma_intersects(struct cma *cma, unsigned long start, unsigned long e
>>   extern void cma_reserve_pages_on_error(struct cma *cma);
>>
>>   #ifdef CONFIG_CMA
>> -struct folio *cma_alloc_folio(struct cma *cma, int order, gfp_t gfp);
>> -bool cma_free_folio(struct cma *cma, const struct folio *folio);
>> +struct folio *cma_alloc_frozen_folio(struct cma *cma, int order, gfp_t gfp);
>> +bool cma_free_frozen_folio(struct cma *cma, const struct folio *folio);
>>   bool cma_validate_zones(struct cma *cma);
>>   #else
>> -static inline struct folio *cma_alloc_folio(struct cma *cma, int order, gfp_t gfp)
>> +static inline struct folio *cma_alloc_frozen_folio(struct cma *cma, int order, gfp_t gfp)
>>   {
>>   	return NULL;
>>   }
>>
>> -static inline bool cma_free_folio(struct cma *cma, const struct folio *folio)
>> +static inline bool cma_free_frozen_folio(struct cma *cma, const struct folio *folio)
>>   {
>>   	return false;
>>   }
>> diff --git a/include/linux/gfp.h b/include/linux/gfp.h
>> index d0047b85fe34..ceda042be704 100644
>> --- a/include/linux/gfp.h
>> +++ b/include/linux/gfp.h
>> @@ -447,26 +447,26 @@ struct page *alloc_contig_frozen_pages_noprof(unsigned long nr_pages,
>>   void free_contig_range(unsigned long pfn, unsigned long nr_pages);
>>
>>   #ifdef CONFIG_CONTIG_ALLOC
>> -static inline struct folio *folio_alloc_gigantic_noprof(int order, gfp_t gfp,
>> -							int nid, nodemask_t *node)
>> +static inline struct folio *folio_alloc_frozen_gigantic_noprof(int order,
>> +		gfp_t gfp, int nid, nodemask_t *node)
>>   {
>>   	struct page *page;
>>
>>   	if (WARN_ON(!order || !(gfp & __GFP_COMP)))
>>   		return NULL;
>>
>> -	page = alloc_contig_pages_noprof(1 << order, gfp, nid, node);
>> +	page = alloc_contig_frozen_pages_noprof(1 << order, gfp, nid, node);
>>
>>   	return page ? page_folio(page) : NULL;
>>   }
>>   #else
>> -static inline struct folio *folio_alloc_gigantic_noprof(int order, gfp_t gfp,
>> -							int nid, nodemask_t *node)
>> +static inline struct folio *folio_alloc_frozen_gigantic_noprof(int order,
>> +		gfp_t gfp, int nid, nodemask_t *node)
>>   {
>>   	return NULL;
>>   }
>>   #endif
>> -/* This should be paired with folio_put() rather than free_contig_range(). */
>> -#define folio_alloc_gigantic(...) alloc_hooks(folio_alloc_gigantic_noprof(__VA_ARGS__))
>> +/* This must be paired with free_frozen_pages() rather than free_contig_range(). */
>> +#define folio_alloc_frozen_gigantic(...) alloc_hooks(folio_alloc_frozen_gigantic_noprof(__VA_ARGS__))
>>
>>   #endif /* __LINUX_GFP_H */
>> diff --git a/mm/cma.c b/mm/cma.c
>> index b4413e382d5d..49d53879c1d0 100644
>> --- a/mm/cma.c
>> +++ b/mm/cma.c
>> @@ -924,20 +924,21 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
>>   			   ACR_FLAGS_CMA);
>>   }
>>
>> -struct folio *cma_alloc_folio(struct cma *cma, int order, gfp_t gfp)
>> +struct folio *cma_alloc_frozen_folio(struct cma *cma, int order, gfp_t gfp)
>>   {
>>   	struct page *page;
>>
>>   	if (WARN_ON(!order || !(gfp & __GFP_COMP)))
>>   		return NULL;
>>
>> -	page = __cma_alloc(cma, 1 << order, order, gfp, ACR_FLAGS_CMA);
>> +	page = __cma_alloc(cma, 1 << order, order, gfp,
>> +			   ACR_FLAGS_CMA | ACR_FLAGS_FROZEN);
>>
>>   	return page ? page_folio(page) : NULL;
>>   }
>>
>>   static bool __cma_release(struct cma *cma, const struct page *pages,
>> -			  unsigned long count)
>> +			  unsigned long count, bool frozen_page)
>>   {
>>   	unsigned long pfn, end;
>>   	int r;
>> @@ -960,7 +961,14 @@ static bool __cma_release(struct cma *cma, const struct page *pages,
>>   	if (r == cma->nranges)
>>   		return false;
>>
>> -	free_contig_range(pfn, count);
>> +	if (frozen_page) {
>> +		struct page *head_page = compound_head((struct page *)pages);
> 
> A WARN_ONCE refcount check might be helpful, since there are two
> cases here.

ACK, thanks for all comments.

> 
>> +
>> +		free_frozen_pages(head_page, compound_order(head_page));
>> +	} else {
>> +		free_contig_range(pfn, count);
>> +	}
>> +
> 
> Best Regards,
> Yan, Zi



  reply	other threads:[~2025-09-09  7:35 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 12:48 [PATCH v2 0/9] mm: hugetlb: cleanup and allocate frozen hugetlb folio Kefeng Wang
2025-09-02 12:48 ` [PATCH v2 1/9] mm: hugetlb: convert to use more alloc_fresh_hugetlb_folio() Kefeng Wang
2025-09-08  9:21   ` Oscar Salvador
2025-09-08 12:59     ` Kefeng Wang
2025-09-09  0:54   ` Zi Yan
2025-09-02 12:48 ` [PATCH v2 2/9] mm: hugetlb: convert to account_new_hugetlb_folio() Kefeng Wang
2025-09-08  9:26   ` Oscar Salvador
2025-09-08 13:20     ` Kefeng Wang
2025-09-08 13:38       ` Oscar Salvador
2025-09-08 13:40   ` Oscar Salvador
2025-09-09  7:04     ` Kefeng Wang
2025-09-09  0:59   ` Zi Yan
2025-09-02 12:48 ` [PATCH v2 3/9] mm: hugetlb: directly pass order when allocate a hugetlb folio Kefeng Wang
2025-09-08  9:29   ` Oscar Salvador
2025-09-09  1:11   ` Zi Yan
2025-09-09  7:11     ` Kefeng Wang
2025-09-02 12:48 ` [PATCH v2 4/9] mm: hugetlb: remove struct hstate from init_new_hugetlb_folio() Kefeng Wang
2025-09-08  9:31   ` Oscar Salvador
2025-09-09  1:13   ` Zi Yan
2025-09-02 12:48 ` [PATCH v2 5/9] mm: hugeltb: check NUMA_NO_NODE in only_alloc_fresh_hugetlb_folio() Kefeng Wang
2025-09-08  9:34   ` Oscar Salvador
2025-09-09  1:16   ` Zi Yan
2025-09-02 12:48 ` [PATCH v2 6/9] mm: page_alloc: add alloc_contig_frozen_pages() Kefeng Wang
2025-09-09  0:21   ` jane.chu
2025-09-09  1:44   ` Zi Yan
2025-09-09  7:29     ` Kefeng Wang
2025-09-09  8:11   ` Oscar Salvador
2025-09-09 18:55   ` Matthew Wilcox
2025-09-09 19:08     ` Zi Yan
2025-09-10  2:05       ` Kefeng Wang
2025-09-02 12:48 ` [PATCH v2 7/9] mm: cma: add alloc flags for __cma_alloc() Kefeng Wang
2025-09-09  0:19   ` jane.chu
2025-09-09  2:03   ` Zi Yan
2025-09-09  8:05   ` Oscar Salvador
2025-09-02 12:48 ` [PATCH v2 8/9] mm: cma: add __cma_release() Kefeng Wang
2025-09-09  0:15   ` jane.chu
2025-09-02 12:48 ` [PATCH v2 9/9] mm: hugetlb: allocate frozen pages in alloc_gigantic_folio() Kefeng Wang
2025-09-09  1:48   ` jane.chu
2025-09-09  7:33     ` Kefeng Wang
2025-09-09  2:02   ` Zi Yan
2025-09-09  7:34     ` Kefeng Wang [this message]
2025-09-02 13:51 ` [PATCH v2 0/9] mm: hugetlb: cleanup and allocate frozen hugetlb folio Oscar Salvador

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=631af84e-c2e0-4d4d-b55d-eda41fbe58ba@huawei.com \
    --to=wangkefeng.wang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=jane.chu@oracle.com \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=sidhartha.kumar@oracle.com \
    --cc=vbabka@suse.cz \
    --cc=ziy@nvidia.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