mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm/hugetlb: avoid unnecessary TLB flush for empty folio list in vmemmap optimize
@ 2026-06-30 11:38 Wentao Guan
  2026-06-30 12:00 ` Muchun Song
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Guan @ 2026-06-30 11:38 UTC (permalink / raw)
  To: mike.kravetz, muchun.song
  Cc: osalvador, david, akpm, linux-mm, linux-kernel, Wentao Guan

__hugetlb_vmemmap_optimize_folios() unconditionally issues a final
flush_tlb_all() in its out path.  However, a TLB flush must be paired
with an actual page table modification.

When the input folio list is empty, neither PMD splitting nor PTE
remapping takes place, so no page tables are modified and the flush is
pure overhead.  An empty list is reached in common paths such as
gather_bootmem_prealloc_node() on nodes without bootmem gigantic pages,
hugetlb_pages_alloc_boot_node() when no pages were allocated, and
runtime allocation failure paths in set_max_huge_pages().

Add an early return for empty lists.  This restores the basic invariant
that TLB flushes are only issued when page tables have been modified,
and it also makes the NULL hstate passed by gather_bootmem_prealloc_node()
on an empty list harmless.

Assisted-by: kimi-cli:kimi-k2.7 code
Assisted-by: Github Copilot:gpt-5.2 #Reported-by

Fixes: 79359d6d24df ("hugetlb: perform vmemmap optimization on a list of pages")
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
---
 mm/hugetlb_vmemmap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 133b46dfb09f5..d45d5355d1af1 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -624,6 +624,9 @@ static void __hugetlb_vmemmap_optimize_folios(struct hstate *h,
 	LIST_HEAD(vmemmap_pages);
 	unsigned long flags = VMEMMAP_REMAP_NO_TLB_FLUSH;
 
+	if (list_empty(folio_list))
+		return;
+
 	nr_to_optimize = 0;
 	list_for_each_entry(folio, folio_list, lru) {
 		int ret;
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm/hugetlb: avoid unnecessary TLB flush for empty folio list in vmemmap optimize
  2026-06-30 11:38 [PATCH] mm/hugetlb: avoid unnecessary TLB flush for empty folio list in vmemmap optimize Wentao Guan
@ 2026-06-30 12:00 ` Muchun Song
  0 siblings, 0 replies; 2+ messages in thread
From: Muchun Song @ 2026-06-30 12:00 UTC (permalink / raw)
  To: Wentao Guan; +Cc: mike.kravetz, osalvador, david, akpm, linux-mm, linux-kernel



> On Jun 30, 2026, at 19:38, Wentao Guan <guanwentao@uniontech.com> wrote:
> 
> __hugetlb_vmemmap_optimize_folios() unconditionally issues a final
> flush_tlb_all() in its out path.  However, a TLB flush must be paired
> with an actual page table modification.
> 
> When the input folio list is empty, neither PMD splitting nor PTE
> remapping takes place, so no page tables are modified and the flush is
> pure overhead.  An empty list is reached in common paths such as
> gather_bootmem_prealloc_node() on nodes without bootmem gigantic pages,
> hugetlb_pages_alloc_boot_node() when no pages were allocated, and
> runtime allocation failure paths in set_max_huge_pages().
> 
> Add an early return for empty lists.  This restores the basic invariant
> that TLB flushes are only issued when page tables have been modified,
> and it also makes the NULL hstate passed by gather_bootmem_prealloc_node()
> on an empty list harmless.
> 
> Assisted-by: kimi-cli:kimi-k2.7 code
> Assisted-by: Github Copilot:gpt-5.2 #Reported-by
> 
> Fixes: 79359d6d24df ("hugetlb: perform vmemmap optimization on a list of pages")

Actually, this is an optimization, so it doesn't need a bugfix—unless it's a hot
path or causing a massive performance degradation, that's clearly not the case
here.

> Signed-off-by: Wentao Guan <guanwentao@uniontech.com>

I actually have a local optimization that covers this, so LGTM:

Reviewed-by: Muchun Song <muchun.song@linux.dev>

Thanks.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-30 12:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-30 11:38 [PATCH] mm/hugetlb: avoid unnecessary TLB flush for empty folio list in vmemmap optimize Wentao Guan
2026-06-30 12:00 ` Muchun Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome