: Introduce CONFIG_MAXSMP to allow up to 512 cpus
PATCH 1/1 : Introduce CONFIG_MAXSMP to allow up to 512 cpus
Ampere Computing develops high end ARM processors that support an ever increasing number of processors. The current default of 256 processors is not enough for our newer products. The default is used by Linux distros and therefore our customers cannot use distro kernels because the number of processors is not supported.
The x86 arch has support for a "CONFIG_MAXSMP" configuration option that enables support for the largest known configurations. This usually means hundreds or thousands of processors. For those sizes it is no longer practical to allocate bitmaps of cpus on the kernel stack. There is a kernel option CONFIG_CPUMASK_OFFSTACK that makes the kernel allocate and free bitmaps for cpu masks from slab memory instead of keeping it on the stack etc.
With that is becomes possible to dynamically size the allocation of the bitmap depending on the quantity of processors detected on bootup.
This patch enables that logic if CONFIG_MAXSMP is enabled.
If CONFIG_MAXSMP is disabled then a default of 64 processors is supported. A bitmap for 64 processors fits into one word and therefore can be efficiently handled on the stack. Using a pointer to a bitmap would be overkill.
The number of processors can be manually configured if CONFIG_MAXSMP is not set.
Currently the default for CONFIG_MAXSMP is 512 processors. This will have to be increased if ARM processor vendors start supporting more processors.
---NR_CPU limits on ARM64 were discussed before at
https://lore.kernel.org/all/[email protected]/
arch/arm64/Kconfig +49 -3
@@ -1402,10 +1402,56 @@ config SCHED_SMT MultiThreading at a cost of slightly increased overhead in some places. If unsure say N here. + +config MAXSMP + bool "Compile kernel with support for the maximum number of SMP Processors" + depends on SMP && DEBUG_KERNEL + select CPUMASK_OFFSTACK + help + Enable maximum number of CPUS and NUMA Nodes for this architecture. + If unsure, say N. + +# +# The maximum number of CPUs supported: +# +# The main config value is NR_CPUS, which defaults to NR_CPUS_DEFAULT, +# and which can be configured interactively in the +# [NR_CPUS_RANGE_BEGIN ... NR_CPUS_RANGE_END] range. +# +# ( If MAXSMP is enabled we just use the highest possible value and disable +# interactive configuration. ) +# + +config NR_CPUS_RANGE_BEGIN + int + default NR_CPUS_RANGE_END if MAXSMP + default 1 if !SMP + default 2 + +config NR_CPUS_RANGE_END + int + default 8192 if SMP && CPUMASK_OFFSTACK + default 512 if SMP && !CPUMASK_OFFSTACK + default 1 if !SMP + +config NR_CPUS_DEFAULT + int + default 512 if MAXSMP + default 64 if SMP + default 1 if !SMP + config NR_CPUS - int "Maximum number of CPUs (2-4096)" - range 2 4096 - default "256" + int "Set maximum number of CPUs" if SMP && !MAXSMP + range NR_CPUS_RANGE_BEGIN NR_CPUS_RANGE_END + default NR_CPUS_DEFAULT + help + This allows you to specify the maximum number of CPUs which this + kernel will support. If CPUMASK_OFFSTACK is enabled, the maximum + supported value is 8192, otherwise the maximum value is 512. The + minimum value which makes sense is 2. + + This is purely to save memory: each supported CPU adds about 8KB + to the kernel image. config HOTPLUG_CPU bool "Support for hot-pluggable CPUs"
arch/arm64/configs/defconfig +1 -0
@@ -15,6 +15,7 @@ CONFIG_TASK_IO_ACCOUNTING=y CONFIG_IKCONFIG=y CONFIG_IKCONFIG_PROC=y CONFIG_NUMA_BALANCING=y +CONFIG_MAXSMP=y CONFIG_MEMCG=y CONFIG_BLK_CGROUP=y CONFIG_CGROUP_PIDS=y
Catalin Marinas
maintainerQuoted 23 lines · Christoph Lameter (Ampere)
Index: linux/arch/arm64/Kconfig
===================================================================arch/arm64/Kconfig +15
-0@@ -1402,10 +1402,56 @@ config SCHED_SMT MultiThreading at a cost of slightly increased overhead in some places. If unsure say N here. + +config MAXSMP + bool "Compile kernel with support for the maximum number of SMP Processors" + depends on SMP && DEBUG_KERNEL + select CPUMASK_OFFSTACK + help + Enable maximum number of CPUS and NUMA Nodes for this architecture. + If unsure, say N. + +# +# The maximum number of CPUs supported: +# +# The main config value is NR_CPUS, which defaults to NR_CPUS_DEFAULT, +# and which can be configured interactively in the +# [NR_CPUS_RANGE_BEGIN ... NR_CPUS_RANGE_END] range.
arch/arm64/Kconfig config SCHED_SMT · line 1429
Quoted 10 lines
arch/arm64/Kconfig +10
-0+# +# ( If MAXSMP is enabled we just use the highest possible value and disable +# interactive configuration. ) +# + +config NR_CPUS_RANGE_BEGIN + int + default NR_CPUS_RANGE_END if MAXSMP + default 1 if !SMP + default 2
We don't support !SMP on arm64.
Quoted 18 lines
arch/arm64/Kconfig +14
-3+ +config NR_CPUS_RANGE_END + int + default 8192 if SMP && CPUMASK_OFFSTACK + default 512 if SMP && !CPUMASK_OFFSTACK + default 1 if !SMP + +config NR_CPUS_DEFAULT + int + default 512 if MAXSMP + default 64 if SMP + default 1 if !SMP + config NR_CPUS - int "Maximum number of CPUs (2-4096)" - range 2 4096 - default "256" + int "Set maximum number of CPUs" if SMP && !MAXSMP
arch/arm64/Kconfig config SCHED_SMT · line 1454
Quoted 10 lines
arch/arm64/Kconfig +10
-0+ range NR_CPUS_RANGE_BEGIN NR_CPUS_RANGE_END + default NR_CPUS_DEFAULT + help + This allows you to specify the maximum number of CPUs which this + kernel will support. If CPUMASK_OFFSTACK is enabled, the maximum + supported value is 8192, otherwise the maximum value is 512. The + minimum value which makes sense is 2. + + This is purely to save memory: each supported CPU adds about 8KB + to the kernel image.
Is this all needed just to select CPUMASK_OFFSTACK if larger NR_CPUS? Would something like this do:
arch/arm64/Kconfig +1 -0
@@ -119,6 +119,7 @@ config ARM64 select CLONE_BACKWARDS select COMMON_CLK select CPU_PM if (SUSPEND || CPU_IDLE) + select CPUMASK_OFFSTACK if NR_CPUS > 512 select CRC32 select DCACHE_WORD_ACCESS select DYNAMIC_FTRACE if FUNCTION_TRACER
togehther with a larger NR_CPUS in defconfig?
Signature · 1 line
Catalin
Quoted 7 lines · Catalin Marinas
Review
Quoted 5 lines
(quoted diff) +5
-0+config NR_CPUS_RANGE_BEGIN + int + default NR_CPUS_RANGE_END if MAXSMP + default 1 if !SMP + default 2We don't support !SMP on arm64.
Ok we can drop that.
Quoted 19 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ This is purely to save memory: each supported CPU adds about 8KB + to the kernel image.Is this all needed just to select
CPUMASK_OFFSTACKif largerNR_CPUS? Would something like this do:arch/arm64/Kconfig +1
-0@@ -119,6 +119,7 @@ config ARM64 select CLONE_BACKWARDS select COMMON_CLK select CPU_PM if (SUSPEND || CPU_IDLE) + select CPUMASK_OFFSTACK if NR_CPUS > 512 select CRC32 select DCACHE_WORD_ACCESS select DYNAMIC_FTRACE if FUNCTION_TRACER
Quoted 1 line
togehther with a larger
NR_CPUSin defconfig?
Well that is certainly better because it does not introduce an additional kernel config option.
Quoted 5 lines · Christoph Lameter (Ampere)
Ampere Computing develops high end ARM processors that support an ever increasing number of processors. The current default of 256 processors is not enough for our newer products. The default is used by Linux distros and therefore our customers cannot use distro kernels because the number of processors is not supported.
In the previous thread mentioned below, Catalin had mentioned that the distros do tweak the config for their needs. The default is applicable for an wide range systems, hence just wondering why default NR_CPUS be changed for all.
Also just curious, what might be the concern for distros to have large platform specific configs overriding the default.
Quoted 103 lines
The x86 arch has support for a "
CONFIG_MAXSMP" configuration option that enables support for the largest known configurations. This usually means hundreds or thousands of processors. For those sizes it is no longer practical to allocate bitmaps of cpus on the kernel stack. There is a kernel optionCONFIG_CPUMASK_OFFSTACKthat makes the kernel allocate and free bitmaps for cpu masks from slab memory instead of keeping it on the stack etc.With that is becomes possible to dynamically size the allocation of the bitmap depending on the quantity of processors detected on bootup.
This patch enables that logic if
CONFIG_MAXSMPis enabled.If
CONFIG_MAXSMPis disabled then a default of 64 processors is supported. A bitmap for 64 processors fits into one word and therefore can be efficiently handled on the stack. Using a pointer to a bitmap would be overkill.The number of processors can be manually configured if
CONFIG_MAXSMPis not set.Currently the default for
CONFIG_MAXSMPis 512 processors. This will have to be increased if ARM processor vendors start supporting more processors.Signed-off-by Christoph Lameter (Ampere) <[email protected]>---
NR_CPUlimits on ARM64 were discussed before at
https://lore.kernel.org/all/[email protected]/Index: linux/arch/arm64/Kconfig
===================================================================arch/arm64/Kconfig +0
-0@@ -1402,10 +1402,56 @@ config SCHED_SMTMultiThreading at a cost of slightly increased overhead in some places. If unsure say N here.
arch/arm64/Kconfig +38
-0+ +config MAXSMP + bool "Compile kernel with support for the maximum number of SMP Processors" + depends on SMP && DEBUG_KERNEL + select CPUMASK_OFFSTACK + help + Enable maximum number of CPUS and NUMA Nodes for this architecture. + If unsure, say N. + +# +# The maximum number of CPUs supported: +# +# The main config value is NR_CPUS, which defaults to NR_CPUS_DEFAULT, +# and which can be configured interactively in the +# [NR_CPUS_RANGE_BEGIN ... NR_CPUS_RANGE_END] range. +# +# ( If MAXSMP is enabled we just use the highest possible value and disable +# interactive configuration. ) +# + +config NR_CPUS_RANGE_BEGIN + int + default NR_CPUS_RANGE_END if MAXSMP + default 1 if !SMP + default 2 + +config NR_CPUS_RANGE_END + int + default 8192 if SMP && CPUMASK_OFFSTACK + default 512 if SMP && !CPUMASK_OFFSTACK + default 1 if !SMP + +config NR_CPUS_DEFAULT + int + default 512 if MAXSMP + default 64 if SMP + default 1 if !SMP +config
NR_CPUS
- int "Maximum number of CPUs (2-4096)"
- range 2 4096
- default "256"
+ int "Set maximum number of CPUs" if SMP && !MAXSMP
+ rangeNR_CPUS_RANGE_BEGINNR_CPUS_RANGE_END
+ defaultNR_CPUS_DEFAULT
+ help
+ This allows you to specify the maximum number of CPUs which this + kernel will support. IfCPUMASK_OFFSTACKis enabled, the maximum + supported value is 8192, otherwise the maximum value is 512. The + minimum value which makes sense is 2.
+
+ This is purely to save memory: each supported CPU adds about 8KB + to the kernel image.config
HOTPLUG_CPU
bool "Support for hot-pluggable CPUs"
Index: linux/arch/arm64/configs/defconfig
===================================================================arch/arm64/configs/defconfig +0
-0@@ -15,6 +15,7 @@ CONFIG_TASK_IO_ACCOUNTING=y
Quoted 7 lines
CONFIG_IKCONFIG=y
CONFIG_IKCONFIG_PROC=y
CONFIG_NUMA_BALANCING=y
+CONFIG_MAXSMP=y
CONFIG_MEMCG=y
CONFIG_BLK_CGROUP=y
CONFIG_CGROUP_PIDS=y
I do agree with Catalin's suggestion - just selecting CPUMASK_OFFSTACK for larger NR_CPUS.
Quoted 9 lines · Anshuman Khandual
Quoted 5 lines · Christoph Lameter (Ampere)
Ampere Computing develops high end ARM processors that support an ever increasing number of processors. The current default of 256 processors is not enough for our newer products. The default is used by Linux distros and therefore our customers cannot use distro kernels because the number of processors is not supported.
Quoted 4 lines
In the previous thread mentioned below, Catalin had mentioned that the distros do tweak the config for their needs. The default is applicable for an wide range systems, hence just wondering why default
NR_CPUSbe changed for all.
We would like the standard kernel to be able to boot on our systems and those have more than the current NR_CPU processors. The distros only tweaks things on request and with this change the tweaking is no longer necessary.
Quoted 2 lines
Also just curious, what might be the concern for distros to have large platform specific configs overriding the default.
There are numerous distributions as well as individuals who built kernels. It is surprising if someone builds an upstream kernel with the defaults that should fit all supported platforms only to find that only a portion of their cpus come up. The work of discovery why this is and how to fix it has to be done by numerous individuals and organizations in order to enable all cpus. That work is not necessary if the default is such that a sufficient number of processors are supported by the default configuration accommodating all ARM hardware.
The CONFIG_MAXSMP configuration on X86 was developed exactly for these situations and we have a special KCONFIG option to have potentially large bitmaps for cpus allocated as needed in the kernel core. The patch enables the use of that facility.
PATCH 1/1 ARM64: Dynamicaly allocate cpumasks and increase supported CPUs to 512 (was: CONFIG_MAXSMP to allow up to 512 cpus)
New version of the patch after feedback from Catalin:
From: Christoph Lameter (Ampere) <[email protected]>
Subject: [PATCH] ARM64: Dynamicaly allocate cpumasks and increase supported CPUs to 512
Ampere Computing develops high end ARM processor that support an ever increasing number of processors. The default 256 processors are not enough for our newer products. The default is used by distros and therefore our customers cannot use distro kernels because the number of processors is not supported.
One of the objections against earlier patches to increase the limit was that the memory use becomes too high. There is a feature called CPUMASK_OFFSTACK that configures the cpumasks in the kernel to be dynamically allocated. This was used in the X86 architecture in the past to enable support for larger CPU configurations up to 8k cpus.
With that is becomes possible to dynamically size the allocation of the cpu bitmaps depending on the quantity of processors detected on bootup.
This patch enables that logic if more than 256 processors are configured and increases the default to 512 processors.
Further increases may be needed if ARM processor vendors start supporting more processors. Given the current inflationary trends in core counts from multiple processor manufacturers this may occur.
arch/arm64/Kconfig +15 -1
@@ -1407,7 +1407,21 @@ config SCHED_SMT config NR_CPUS int "Maximum number of CPUs (2-4096)" range 2 4096 - default "256" + default 512 + +# +# Determines the placement of cpumasks. +# +# With CPUMASK_OFFSTACK the cpumasks are dynamically allocated. +# Useful for machines with lots of core because it avoids increasing +# the size of many of the data structures in the kernel. +# +# If this is off then the cpumasks have a static sizes and are +# embedded within data structures. +# +config CPUMASK_OFFSTACK + def_bool y + depends on NR_CPUS > 256 config HOTPLUG_CPU bool "Support for hot-pluggable CPUs"