Skip to contentSkip to conversation

mm/hugetlb: use kvmalloc_array for hugetlb_fault_mutex_table

PATCH Superseded Dheeraj Kumar Srivastava 2 participants 3 messages Oct 6

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/hugetlb: use kvmalloc_array for hugetlb_fault_mutex_table

On systems/VMs with a large number of CPUs (e.g. 4096), hugetlb_init() computes num_fault_mutexes = roundup_pow_of_two(8 * num_possible_cpus()) = 32768. The subsequent kmalloc for the mutex table can exceed MAX_PAGE_ORDER when struct mutex is enlarged by debug options like CONFIG_DEBUG_MUTEXES and CONFIG_DEBUG_LOCK_ALLOC, resulting in:

  WARNING: at __alloc_frozen_pages_noprof (order > MAX_PAGE_ORDER)
  kernel BUG at mm/hugetlb.c (BUG_ON(!hugetlb_fault_mutex_table))
  Kernel panic - not syncing: Fatal exception

Switch to kvmalloc_array() so the allocation falls back to vmalloc when the contiguous physical allocation is too large. The table is only accessed by index, so virtual contiguity is sufficient.

Fixes 8382d914ebf7 ("mm, hugetlb: improve page-fault scalability")
---
 mm/hugetlb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/hugetlb.c +2 -1
index cea25773a6c9..f1b982595151 100644
@@ -4177,7 +4177,8 @@ static int __init hugetlb_init(void)
 	num_fault_mutexes = 1;
 #endif
 	hugetlb_fault_mutex_table =
-		kmalloc_objs(struct mutex, num_fault_mutexes);
+		kvmalloc_array(num_fault_mutexes,
+			       sizeof(*hugetlb_fault_mutex_table), GFP_KERNEL);
 	BUG_ON(!hugetlb_fault_mutex_table);
 
 	for (i = 0; i < num_fault_mutexes; i++)
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 29 lines · Dheeraj Kumar Srivastava

On systems/VMs with a large number of CPUs (e.g. 4096), hugetlb_init() computes num_fault_mutexes = roundup_pow_of_two(8 * num_possible_cpus()) = 32768. The subsequent kmalloc for the mutex table can exceed MAX_PAGE_ORDER when struct mutex is enlarged by debug options like CONFIG_DEBUG_MUTEXES and CONFIG_DEBUG_LOCK_ALLOC, resulting in:

 WARNING: at __alloc_frozen_pages_noprof (order > MAX_PAGE_ORDER)
 kernel BUG at mm/hugetlb.c (BUG_ON(!hugetlb_fault_mutex_table))
 Kernel panic - not syncing: Fatal exception

Switch to kvmalloc_array() so the allocation falls back to vmalloc when the contiguous physical allocation is too large. The table is only accessed by index, so virtual contiguity is sufficient.

Fixes 8382d914ebf7 ("mm, hugetlb: improve page-fault scalability")

---
mm/hugetlb.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
mm/hugetlb.c +0 -0
index cea25773a6c9..f1b982595151 100644

mm/hugetlb.c static int __init hugetlb_init(void) · line 4181

Quoted 6 lines
mm/hugetlb.c +2 -1
@@ -4177,7 +4177,8 @@ static int __init hugetlb_init(void)
 	num_fault_mutexes = 1;
 #endif
 	hugetlb_fault_mutex_table =
- 		kmalloc_objs(struct mutex, num_fault_mutexes);
+ 		kvmalloc_array(num_fault_mutexes,
+			       sizeof(*hugetlb_fault_mutex_table), GFP_KERNEL);

Why not use kvmalloc_objs instead? A little simple.

Thanks

Quoted 6 lines
mm/hugetlb.c +0 -0
 	BUG_ON(!hugetlb_fault_mutex_table);
 
 	for (i = 0; i < num_fault_mutexes; i++)
Signature · 1 line
2.25.1
#2 lore raw

AMD General

Hi,

I will send v2.

Thanks
Dheeraj

-----Original Message-----
From: Muchun Song <[email protected]>
Sent: Tuesday, October 6, 2026 7:41 PM
To: Srivastava, Dheeraj Kumar <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Hegde, Vasant <[email protected]>; Rao, Bharata Bhasker <[email protected]>
Subject: Re: [PATCH] mm/hugetlb: use kvmalloc_array for hugetlb_fault_mutex_table

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 28 lines · Dheeraj Kumar Srivastava

On systems/VMs with a large number of CPUs (e.g. 4096), hugetlb_init() computes num_fault_mutexes = roundup_pow_of_two(8 * num_possible_cpus()) = 32768. The subsequent kmalloc for the mutex table can exceed MAX_PAGE_ORDER when struct mutex is enlarged by debug options like CONFIG_DEBUG_MUTEXES and CONFIG_DEBUG_LOCK_ALLOC, resulting in:

 WARNING: at __alloc_frozen_pages_noprof (order > MAX_PAGE_ORDER)
kernel BUG at mm/hugetlb.c (BUG_ON(!hugetlb_fault_mutex_table))
 Kernel panic - not syncing: Fatal exception

Switch to kvmalloc_array() so the allocation falls back to vmalloc when the contiguous physical allocation is too large. The table is only accessed by index, so virtual contiguity is sufficient.

Fixes 8382d914ebf7 ("mm, hugetlb: improve page-fault scalability")
Signed-off-by Dheeraj Kumar Srivastava

<[email protected]>
---
mm/hugetlb.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
mm/hugetlb.c index renamed from mm/hugetlb.c +0 -0

cea25773a6c9..f1b982595151 100644

mm/hugetlb.c static int __init hugetlb_init(void) · line 4182

Quoted 7 lines
mm/hugetlb.c +3 -1
@@ -4177,7 +4177,8 @@ static int __init hugetlb_init(void)
      num_fault_mutexes = 1;
 #endif
      hugetlb_fault_mutex_table =
-             kmalloc_objs(struct mutex, num_fault_mutexes);
+             kvmalloc_array(num_fault_mutexes,
+                            sizeof(*hugetlb_fault_mutex_table),
+ GFP_KERNEL);

Why not use kvmalloc_objs instead? A little simple.

Thanks

Quoted 6 lines
mm/hugetlb.c +0 -1
      BUG_ON(!hugetlb_fault_mutex_table);
 
      for (i = 0; i < num_fault_mutexes; i++)
--

2.25.1