Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Kernel : MAX_SMP vs NR_CPUS
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
krumpf
Apprentice
Apprentice


Joined: 15 Jul 2018
Posts: 214

PostPosted: Fri Mar 14, 2025 10:49 pm    Post subject: Kernel : MAX_SMP vs NR_CPUS Reply with quote

Hi all,
here's something I've been wondering about for a while : what's the difference between setting the numbers of CPUs manually with NR_CPUS, and using the MAX_SMP option ?
The NR_CPUS help says "This is purely to save memory: each supported CPU adds about 8KB to the kernel image.", while the MAX_SMP says "If unsure, say N.". From what I've read here & there, MAX_SMP is made for really large number of cpus (up to 8192), which I guess applies for servers/datacenters.
So I'd like to know what are the pros and cons for each option ? Is it bad practice to use MAX_SMP on a desktop computer instead of NR_CPUS ?
_________________
Dragon Princess Music Games Heroes and villains
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 5620
Location: Bavaria

PostPosted: Fri Mar 14, 2025 11:38 pm    Post subject: Reply with quote

Usually you can choose between 2 and 512 CPUs (see <Help> of CONFIG_NR_CPUS) ... IF you need more THEN you must enable CONFIG_MAXSMP.

If you enable CONFIG_MAXSMP you have automatically the maximum of 8192 CPUs ... AND ... you cannot select CONFIG_NR_CPUS futhermore, because you will see CONFIG_NR_CPUS only if ->
Code:
Visible if: SMP [=y] && !MAXSMP [=n]

(!MAXSMP means NOT MAXSMP)

I recommend always to disable CONFIG_MAXSMP and set the necessary value in CONFIG_NR_CPUS ... even if the advantage is very small.
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
krumpf
Apprentice
Apprentice


Joined: 15 Jul 2018
Posts: 214

PostPosted: Sat Mar 15, 2025 7:09 am    Post subject: Reply with quote

Thanks pietinger, but you didn't really answer my question.

How to explain... My CPU is a 8cores/16threads, so I suppose the optimal NR_CPUS would be 16. Let's say I set it on 64, as I understand it, it will inflate the kernel image by (64-16)*8KB = 384 KB, and during boot the kernel will "discard" the cpus that are not detected.
But what are the consequences of using MAX_SMP instead of NR_CPUS ? Would that increase the kernel size by (8192-16)*8KB almost 64MB ? Or does the compiler detects the correct number of cpus when building, and automatically set it ?
_________________
Dragon Princess Music Games Heroes and villains
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23350

PostPosted: Sat Mar 15, 2025 11:24 am    Post subject: Reply with quote

A kernel built for N CPUs can be run on a system with M CPUs, regardless of whether N < M, N = M, or N > M. However, if N < M, you only get use of N CPUs, meaning the (M - N) CPUs go to waste. If N > M, you get use of all M CPUs that you actually have, but the kernel sets aside some extra memory as if you had N CPUs. Thus, setting N > M is a waste of memory, and the greater the delta, the greater the waste. Per pietinger's post, MAXSMP forces N = 8192, thus giving you maximal memory waste. You should always pick N such that it is at least M, but preferably no bigger. If you want a single kernel that runs on multiple different systems, you might set N to max(system1, system2, ...), so that all systems can use all their CPUs, and the less capable systems just waste a bit of memory.
Back to top
View user's profile Send private message
krumpf
Apprentice
Apprentice


Joined: 15 Jul 2018
Posts: 214

PostPosted: Sat Mar 15, 2025 2:59 pm    Post subject: Reply with quote

I think I finally understand, it affects the kernel image once it's decompressed in RAM, not the image written on disk.
Thanks for the explanations.

(Feels like I have the hardest time to figure out the simplest things. Now if you excuse me, my shame and me are going to hide in some deep hole.)
_________________
Dragon Princess Music Games Heroes and villains
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 5620
Location: Bavaria

PostPosted: Sat Mar 15, 2025 4:38 pm    Post subject: Reply with quote

krumpf wrote:
Thanks for the explanations.

You are very Welcome. :D

krumpf wrote:
[...] Now if you excuse me, my shame and me are going to hide in some deep hole.)

There is no reason to do this, because your question could also be asked by other users who now have an answer in your thread. ;-)
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum