linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Oscar Salvador <osalvador@suse.de>
To: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	Muchun Song <muchun.song@linux.dev>,
	linux-mm@kvack.org, sidhartha.kumar@oracle.com,
	jane.chu@oracle.com, Zi Yan <ziy@nvidia.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Brendan Jackman <jackmanb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH 3/5] mm: hugetlb: optimize replace_free_hugepage_folios()
Date: Tue, 13 Jan 2026 06:27:53 +0100	[thread overview]
Message-ID: <aWXX2WqZ6bEpEtee@localhost.localdomain> (raw)
In-Reply-To: <20260112150954.1802953-4-wangkefeng.wang@huawei.com>

On Mon, Jan 12, 2026 at 11:09:52PM +0800, Kefeng Wang wrote:
> If no free hugepage folios are available, there is no need to perform
> any replacement operations. Additionally, gigantic folios should not
> be replaced under any circumstances. Therefore, we only check for the
> presence of non-gigantic folios.
> 
> To ensure that gigantic folios are not mistakenly replaced, we utilize
> isolate_or_dissolve_huge_folio().
> 
> Lastly, to optimize performance, we skip unnecessary iterations over pfn
> for compound pages and high-order buddy pages to save processing time.
> 
> A simple test on machine with 114G free memory, allocate 120 * 1G
> HugeTLB folios(104 successfully returned),
> 
>   time echo 120 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
> 
> Before: 0m0.602s
> After:  0m0.431s
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
...
>  int replace_free_hugepage_folios(unsigned long start_pfn, unsigned long end_pfn)
>  {
> -	struct folio *folio;
> -	int ret = 0;
> +	unsigned long nr = 0;
> +	struct page *page;
> +	struct hstate *h;
> +	LIST_HEAD(list);
>  
> -	LIST_HEAD(isolate_list);
> +	/* Avoid pfn iterations if no free non-gigantic huge pages */
> +	for_each_hstate(h) {
> +		if (hstate_is_gigantic(h))
> +			continue;
> +
> +		nr += h->free_huge_pages;
> +		if (nr)
> +			break;
> +	}
> +
> +	if (!nr)
> +		return 0;
>  
>  	while (start_pfn < end_pfn) {
> -		folio = pfn_folio(start_pfn);
> +		page = pfn_to_page(start_pfn);
> +		nr = 1;
>  
> -		/* Not to disrupt normal path by vainly holding hugetlb_lock */
> -		if (folio_test_hugetlb(folio) && !folio_ref_count(folio)) {
> -			ret = alloc_and_dissolve_hugetlb_folio(folio, &isolate_list);
> -			if (ret)
> -				break;
> +		if (PageHuge(page) || PageCompound(page)) {
> +			struct folio *folio = page_folio(page);
> +
> +			nr = folio_nr_pages(folio) - folio_page_idx(folio, page);
> +
> +			/* Not to disrupt normal path by vainly holding hugetlb_lock */
> +			if (folio_test_hugetlb(folio) && !folio_ref_count(folio)) {
> +				if (isolate_or_dissolve_huge_folio(folio, &list))

isolate_or_dissolve_huge_folio() can also return -EBUSY, but you supersed that with
ENOMEM in case it fails. Is that alright?
Maybe it is because down the chain we ignore the type of error as long as it is
an error but just brining it up because the log now differs.

 

-- 
Oscar Salvador
SUSE Labs


  reply	other threads:[~2026-01-13  5:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-12 15:09 [PATCH mm-new resend 0/5] mm: accelerate gigantic folio allocation Kefeng Wang
2026-01-12 15:09 ` [PATCH 1/5] mm: page_isolation: introduce page_is_unmovable() Kefeng Wang
2026-01-12 16:36   ` Zi Yan
2026-01-13  4:37   ` Oscar Salvador
2026-01-12 15:09 ` [PATCH 2/5] mm: page_alloc: optimize pfn_range_valid_contig() Kefeng Wang
2026-01-12 17:02   ` Zi Yan
2026-01-13  1:24     ` Kefeng Wang
2026-01-13  1:27       ` Zi Yan
2026-01-13  5:14   ` Oscar Salvador
2026-01-12 15:09 ` [PATCH 3/5] mm: hugetlb: optimize replace_free_hugepage_folios() Kefeng Wang
2026-01-13  5:27   ` Oscar Salvador [this message]
2026-01-12 15:09 ` [PATCH 4/5] mm: hugetlb_cma: optimize hugetlb_cma_alloc_frozen_folio() Kefeng Wang
2026-01-12 15:09 ` [PATCH 5/5] mm: hugetlb_cma: mark hugetlb_cma{_only} as __ro_after_init 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=aWXX2WqZ6bEpEtee@localhost.localdomain \
    --to=osalvador@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.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=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