Skip to contentSkip to conversation

x86/Kconfig: Allow NR_CPUS between 512 and 8192

PATCH In review Saurabh Sengar 2 participants 4 messages Feb 20, 2024 – Jan 3, 2025 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/Kconfig: Allow NR_CPUS between 512 and 8192

Today there is no way one can choose any value between 512 to 8192 for NR_CPUS seamlessly. NR_CPUS is guarded by NR_CPUS_RANGE_END which is further dependent on CPUMASK_OFFSTACK to allow NR_CPUs > 512.

For x86, CPUMASK_OFFSTACK can only be enabled either by selecting MAXSMP or DEBUG_PER_CPU_MAPS. Both of these options has a cost to pay. MAXSMP will increase the NR_CPUS to 8192 which will have impact on kernel image size whereas DEBUG_PER_CPU_MAPS will have additional run time overheads. Thus there is no good way to have NR_CPUS anything between 512 to 8192.

Fix this by selecting CPUMASK_OFFSTACK if NR_CPUS > 512 and let NR_CPUS_RANGE_END set to 8192.

On a Hyper-V system where max number of CPUs are only 2048, this patch saves around 1 MB of kernel image size, compare to MAXSMP.

---

I want to mention that in ARM and other archs its very simple to select any value for NR_CPUS. This is an attempt to have more flexibilty in x86 arch as well to choose NR_CPUS.

Some of the earlier discussions reated to it which could be of interest:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/

Another approach I can think of is to allow CPUMASK_OFFSTACK to be enabled more freely like the below patch of Libo Chen, that will also solve the problem I am addressing. But I feel this patch may have impact on other archs as well and I am not sure if that is in best interest of all the archs.

https://lore.kernel.org/lkml/[email protected]/

 arch/x86/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/Kconfig +2 -2
index 07a0c8d4e9c7..458f3f250d7f 100644
@@ -34,6 +34,7 @@ config X86_64
 	select SWIOTLB
 	select ARCH_HAS_ELFCORE_COMPAT
 	select ZONE_DMA32
+	select CPUMASK_OFFSTACK if NR_CPUS > 512
 
 config FORCE_DYNAMIC_FTRACE
 	def_bool y
@@ -1006,8 +1007,7 @@ config NR_CPUS_RANGE_END
 config NR_CPUS_RANGE_END
 	int
 	depends on X86_64
-	default 8192 if  SMP && CPUMASK_OFFSTACK
-	default  512 if  SMP && !CPUMASK_OFFSTACK
+	default 8192 if  SMP
 	default    1 if !SMP
 
 config NR_CPUS_DEFAULT
Signature · 1 line
2.34.1
#1 lore raw
Quoted 63 lines · Saurabh Sengar

Today there is no way one can choose any value between 512 to 8192 for NR_CPUS seamlessly. NR_CPUS is guarded by NR_CPUS_RANGE_END which is further dependent on CPUMASK_OFFSTACK to allow NR_CPUs > 512.

For x86, CPUMASK_OFFSTACK can only be enabled either by selecting MAXSMP or DEBUG_PER_CPU_MAPS. Both of these options has a cost to pay. MAXSMP will increase the NR_CPUS to 8192 which will have impact on kernel image size whereas DEBUG_PER_CPU_MAPS will have additional run time overheads. Thus there is no good way to have NR_CPUS anything between 512 to 8192.

Fix this by selecting CPUMASK_OFFSTACK if NR_CPUS > 512 and let NR_CPUS_RANGE_END set to 8192.

On a Hyper-V system where max number of CPUs are only 2048, this patch saves around 1 MB of kernel image size, compare to MAXSMP.

---

I want to mention that in ARM and other archs its very simple to select any value for NR_CPUS. This is an attempt to have more flexibilty in x86 arch as well to choose NR_CPUS.

Some of the earlier discussions reated to it which could be of interest:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/

Another approach I can think of is to allow CPUMASK_OFFSTACK to be enabled more freely like the below patch of Libo Chen, that will also solve the problem I am addressing. But I feel this patch may have impact on other archs as well and I am not sure if that is in best interest of all the archs.

https://lore.kernel.org/lkml/[email protected]/

 arch/x86/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/Kconfig +2 -2
index 07a0c8d4e9c7..458f3f250d7f 100644
@@ -34,6 +34,7 @@ config X86_64
 	select SWIOTLB
 	select ARCH_HAS_ELFCORE_COMPAT
 	select ZONE_DMA32
+	select CPUMASK_OFFSTACK if NR_CPUS > 512
 
 config FORCE_DYNAMIC_FTRACE
 	def_bool y
@@ -1006,8 +1007,7 @@ config NR_CPUS_RANGE_END
 config NR_CPUS_RANGE_END
 	int
 	depends on X86_64
-	default 8192 if  SMP && CPUMASK_OFFSTACK
-	default  512 if  SMP && !CPUMASK_OFFSTACK
+	default 8192 if  SMP
 	default    1 if !SMP
 
 config NR_CPUS_DEFAULT
Signature · 2 lines
-- 
2.34.1

x86 Maintainers,

Kind reminder to have your feedback on this patch.

- Saurabh

#2 lore raw
Quoted 67 lines · Saurabh Singh Sengar
Quoted 63 lines · Saurabh Sengar

Today there is no way one can choose any value between 512 to 8192 for NR_CPUS seamlessly. NR_CPUS is guarded by NR_CPUS_RANGE_END which is further dependent on CPUMASK_OFFSTACK to allow NR_CPUs > 512.

For x86, CPUMASK_OFFSTACK can only be enabled either by selecting MAXSMP or DEBUG_PER_CPU_MAPS. Both of these options has a cost to pay. MAXSMP will increase the NR_CPUS to 8192 which will have impact on kernel image size whereas DEBUG_PER_CPU_MAPS will have additional run time overheads. Thus there is no good way to have NR_CPUS anything between 512 to 8192.

Fix this by selecting CPUMASK_OFFSTACK if NR_CPUS > 512 and let NR_CPUS_RANGE_END set to 8192.

On a Hyper-V system where max number of CPUs are only 2048, this patch saves around 1 MB of kernel image size, compare to MAXSMP.

---

I want to mention that in ARM and other archs its very simple to select any value for NR_CPUS. This is an attempt to have more flexibilty in x86 arch as well to choose NR_CPUS.

Some of the earlier discussions reated to it which could be of interest:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/

Another approach I can think of is to allow CPUMASK_OFFSTACK to be enabled more freely like the below patch of Libo Chen, that will also solve the problem I am addressing. But I feel this patch may have impact on other archs as well and I am not sure if that is in best interest of all the archs.

https://lore.kernel.org/lkml/[email protected]/

 arch/x86/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/Kconfig +2 -2
index 07a0c8d4e9c7..458f3f250d7f 100644
@@ -34,6 +34,7 @@ config X86_64
 	select SWIOTLB
 	select ARCH_HAS_ELFCORE_COMPAT
 	select ZONE_DMA32
+	select CPUMASK_OFFSTACK if NR_CPUS > 512
 
 config FORCE_DYNAMIC_FTRACE
 	def_bool y
@@ -1006,8 +1007,7 @@ config NR_CPUS_RANGE_END
 config NR_CPUS_RANGE_END
 	int
 	depends on X86_64
-	default 8192 if  SMP && CPUMASK_OFFSTACK
-	default  512 if  SMP && !CPUMASK_OFFSTACK
+	default 8192 if  SMP
 	default    1 if !SMP
 
 config NR_CPUS_DEFAULT
Signature · 2 lines
-- 
2.34.1

x86 Maintainers,

Quoted 4 lines

Kind reminder to have your feedback on this patch.

- Saurabh

ping