linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Kefeng Wang <wangkefeng.wang@huawei.com>,
	20250910133958.301467-1-wangkefeng.wang@huawei.com,
	Andrew Morton <akpm@linux-foundation.org>,
	Oscar Salvador <osalvador@suse.de>,
	Muchun Song <muchun.song@linux.dev>, Zi Yan <ziy@nvidia.com>,
	Matthew Wilcox <willy@infradead.org>
Cc: 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 4/4] mm: hugetlb: allocate frozen pages in alloc_gigantic_folio()
Date: Fri, 12 Sep 2025 09:23:19 +0200	[thread overview]
Message-ID: <1da42002-9dad-45a7-98f8-90a97801002d@redhat.com> (raw)
In-Reply-To: <3a842ae3-f13a-4f5d-8870-d81cf1f0d56d@redhat.com>

On 12.09.25 09:18, David Hildenbrand wrote:
> On 12.09.25 08:57, Kefeng Wang wrote:
>>
>>
>> On 2025/9/12 2:56, David Hildenbrand wrote:
>>> On 11.09.25 11:11, Kefeng Wang wrote:
>>>>
>>>>
>>>> On 2025/9/11 16:25, David Hildenbrand wrote:
>>>>> On 11.09.25 08:56, Kefeng Wang wrote:
>>>>>> The alloc_gigantic_folio() allocates a folio by alloc_contig_range()
>>>>>> 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
>>>>>>       hugetlb_cma_{alloc,free}_folio  -> hugetlb_cma_{alloc,free}
>>>>>> _frozen_folio
>>>>>
>>>>> Can we just get rid of folio_alloc_frozen_gigantic?
>>>>>
>>>>
>>>> OK, we could kill it.
>>>>
>>>>> Further, can we just get rid of cma_{alloc,free}_frozen_folio() as well
>>>>> and just let hugetlb use alloc_contig_range_frozen() etc?
>>>>
>>>> HugeTLB can allocate folio by alloc_contig_frozen_pages() directly, but
>>>> it could allocate from hugetlb_cma, cma_alloc_folio() need change some
>>>> cma metadata, so we need to keep it.
>>>
>>> Hm. Assuming we just have cma_alloc_frozen() -- again, probably what
>>> cma_alloc() would look like in the future, hugetlb can just construct a
>>> folio out of that.
>>
>> I get your point,firstly, we could convert to use cma_alloc_frozen()
>> instead of cma_alloc_folio() in hugetlb_cma_alloc_folio().
>>
>>>
>>> Maybe we just want a helper to create a folio out of a given page range?
>>>
>>> And that page range is either obtained through cma_alloc_frozen() or
>>> alloc_contig_frozen_pages().
>>>
>>> Just a thought, keeping in mind that these things should probably just
>>> work with frozen pages and let allcoating of a memdesc etc. be taken
>>> care of someone else.
>>>
>>> I'd be happy if we can remove the GFP_COMPOUND parameter from
>>> alloc_contig*.
>>
>> But not sure about this part,  GFP_COMPOUND for alloc_contig* is
>> introduced by commit e98337d11bbd "mm/contig_alloc: support __GFP_COMP",
>> if we still allocate a range of order-0 pages and create a folio
>> outside, it will slow the large folio allocation.
> 
> Assuming we leave the refcount untouched (frozen), I guess what's left is
> 
> a) Calling post_alloc_hook() on each free buddy chunk we isolated
> b) Splitting all pages to order 0
> 
> Splitting is updating the page owner + alloc tag + memcg, and currently
> still updating the refcount.
> 
> 
> I would assume that most of the overhead came from the atomics when
> updating the refcount in split_page, which we would optimize out.
> 
>       Perf profile before:
>         Alloc
>           - 99.99% alloc_pool_huge_folio
>              - __alloc_fresh_hugetlb_folio
>                 - 83.23% alloc_contig_pages_noprof
>                    - 47.46% alloc_contig_range_noprof
>                       - 20.96% isolate_freepages_range
>                            16.10% split_page
>                       - 14.10% start_isolate_page_range
>                       - 12.02% undo_isolate_page_range
> 
> Would be interesting trying to see how much overhead would remain when
> just dealing
> 
> OTOH, maybe we can leave GFP_COMPOUND support in but make the function
> more generic, not limited to folios (I suspect many users will not want
> folios, except hugetlb).
> 
> Maybe just a
> 
> struct page * cma_alloc_compound(struct cma *cma, unsigned int order,
> unsigned int align, bool no_warn);

^ no need for the align as I realized, just like
cma_alloc_folio() doesn't have.

I do wonder why we decided to allow cma_alloc_folio() to consume gfp_t 
flags when we don't do the same for cma_alloc().

-- 
Cheers

David / dhildenb



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

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11  6:56 [PATCH 0/4] mm: hugetlb: allocate frozen gigantic folio Kefeng Wang
2025-09-11  6:56 ` [PATCH 1/4] mm: debug_vm_pgtable: add debug_vm_pgtable_free_huge_page() Kefeng Wang
2025-09-12  6:58   ` Kefeng Wang
2025-09-11  6:56 ` [PATCH 2/4] mm: page_alloc: add alloc_contig_{range_frozen,frozen_pages}() Kefeng Wang
2025-09-11  6:56 ` [PATCH 3/4] mm: cma: add __cma_release() Kefeng Wang
2025-09-11  6:56 ` [PATCH 4/4] mm: hugetlb: allocate frozen pages in alloc_gigantic_folio() Kefeng Wang
2025-09-11  8:25   ` David Hildenbrand
2025-09-11  9:11     ` Kefeng Wang
2025-09-11 18:56       ` David Hildenbrand
2025-09-12  6:57         ` Kefeng Wang
2025-09-12  7:18           ` David Hildenbrand
2025-09-12  7:23             ` David Hildenbrand [this message]
2025-09-12  9:12               ` Kefeng Wang
2025-09-12 18:07                 ` David Hildenbrand
2025-09-13  4:13                   ` Kefeng Wang

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=1da42002-9dad-45a7-98f8-90a97801002d@redhat.com \
    --to=david@redhat.com \
    --cc=20250910133958.301467-1-wangkefeng.wang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --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=wangkefeng.wang@huawei.com \
    --cc=willy@infradead.org \
    --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