Issue
I'm trying to compile 4.14 Linux kernel for Ubuntu 18.04, with some minor changes I've made in the code (not relevant to the discussion).
From some reason the NR_CPUS
define translates to number 8192 for me, which is a way too big number, and it messes up with my code. (I have only 4 CPU cores on my Kabylake machine). Why is it so big? Did I miss something in the configs before I tried to compile the kernel? How do I change the definition correctly?
Solution
In your kernel tree, check arch/x86/Kconfig to see which kernel options you've set from menuconfig may be affecting Kabylake NR_CPUS. According to my 4.14.2 version of this Kconfig:
config NR_CPUS
int "Maximum number of CPUs" if SMP && !MAXSMP
range 2 8 if SMP && X86_32 && !X86_BIGSMP
range 2 512 if SMP && !MAXSMP && !CPUMASK_OFFSTACK
range 2 8192 if SMP && !MAXSMP && CPUMASK_OFFSTACK && X86_64
default "1" if !SMP
default "8192" if MAXSMP
default "32" if SMP && X86_BIGSMP
default "8" if SMP && X86_32
default "64" if SMP
---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.
So setting MAXSMP (appears in menuconfig session as "Enable Maximum number of SMP Processors and NUMA Nodes [N/y]") could be getting you to 8192. Note that with NR_CPUS you are specifying the maximum number of CPUs to be used with this kernel; it's not expected to match your current CPU count exactly. That should be done on the fly.
Answered By - Frank Hoeflich Answer Checked By - Willingham (WPSolving Volunteer)