public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/Kconfig: Allow NR_CPUS between 512 and 8192
@ 2024-02-20  9:50 Saurabh Sengar
  2024-03-04 16:13 ` Saurabh Singh Sengar
  0 siblings, 1 reply; 4+ messages in thread
From: Saurabh Sengar @ 2024-02-20  9:50 UTC (permalink / raw)
  To: tglx, mingo, bp, dave.hansen, x86, hpa, linux-kernel
  Cc: ssengar, libo.chen, mhklinux

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.

Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
---

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/1708092603-14504-1-git-send-email-ssengar@linux.microsoft.com/
https://lore.kernel.org/lkml/794a1211-630b-3ee5-55a3-c06f10df1490@linux.com/

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/20220412231508.32629-2-libo.chen@oracle.com/

 arch/x86/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 07a0c8d4e9c7..458f3f250d7f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -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
-- 
2.34.1


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

end of thread, other threads:[~2025-01-03 22:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-20  9:50 [PATCH] x86/Kconfig: Allow NR_CPUS between 512 and 8192 Saurabh Sengar
2024-03-04 16:13 ` Saurabh Singh Sengar
2024-04-14 16:31   ` Saurabh Singh Sengar
2025-01-03 22:10     ` Hardik Garg

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