x86: make CONFIG_NR_CPUS a tunable (2-512)

Add KERNEL_NR_CPUS option in Global build settings → Kernel build
options, allowing users to set maximum CPU count (2-512) for the image.

Defaults:
- x86_64: 512 CPUs (backward compatible)
- x86: 8 CPUs (fix broken single-CPU default)

Per-CPU data structures consume ~100-200KB each.
On a 4-core system configured to NR_CPUS=4, this frees approx 76 MB
of RAM: (512 - 4) × 150 KB = ~76 MB

Note: CONFIG_NR_CPUS_RANGE_{BEGIN,END}= and CONFIG_NR_CPUS_DEFAULT= are
set by the build system and will default to 2/512/64 per arch/x86/Kconfig
These are harmless metadata and don't affect memory allocation.

Note pending https://github.com/openwrt/openwrt/pull/21407

Signed-off-by: John Audia <therealgraysky@proton.me>
Link: https://github.com/openwrt/openwrt/pull/21078
Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
John Audia
2026-01-04 10:31:43 -05:00
committed by Robert Marko
parent c9075798cc
commit 65d36329e3
2 changed files with 20 additions and 4 deletions

View File

@@ -64,6 +64,26 @@ config KERNEL_RISCV_PMU_SBI
bool
depends on riscv64
config KERNEL_NR_CPUS
int "Maximum number of CPUs (2-512)" if TARGET_x86
range 2 512 if TARGET_x86
default 512 if TARGET_x86_64
default 8 if TARGET_x86
help
Maximum number of CPUs supported by the kernel.
Each CPU allocates approximately 100-200KB of RAM for
per-CPU data structures.
Sample values:
4 - Ultra-low-level desktops e.g. Intel N150
8 - Low-level desktops e.g. Intel N305
16 - Mid-level dekstops e.g. AMD Ryzen 7
32 - High-level desktops e.g. AMD Ryzen 9/Intel Core i9
384 - High-level server e.g. AMD EPYC 9965
Lower values reduce memory usage. Set to match your hardware
for optimal memory efficiency.
config KERNEL_X86_VSYSCALL_EMULATION
bool "Enable vsyscall emulation"
depends on x86_64

View File

@@ -328,10 +328,6 @@ CONFIG_NLS=y
# CONFIG_NOHIGHMEM is not set
CONFIG_NO_HZ=y
CONFIG_NO_HZ_IDLE=y
CONFIG_NR_CPUS=1
CONFIG_NR_CPUS_DEFAULT=1
CONFIG_NR_CPUS_RANGE_BEGIN=1
CONFIG_NR_CPUS_RANGE_END=1
# CONFIG_NSC_GPIO is not set
CONFIG_NVRAM=y
# CONFIG_OF is not set