View previous topic :: View next topic |
Author |
Message |
krumpf Apprentice

Joined: 15 Jul 2018 Posts: 214
|
Posted: Fri Mar 14, 2025 10:49 pm Post subject: Kernel : MAX_SMP vs NR_CPUS |
|
|
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 |
|
 |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5620 Location: Bavaria
|
Posted: Fri Mar 14, 2025 11:38 pm Post subject: |
|
|
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 |
|
 |
krumpf Apprentice

Joined: 15 Jul 2018 Posts: 214
|
Posted: Sat Mar 15, 2025 7:09 am Post subject: |
|
|
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 |
|
 |
Hu Administrator

Joined: 06 Mar 2007 Posts: 23350
|
Posted: Sat Mar 15, 2025 11:24 am Post subject: |
|
|
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 |
|
 |
krumpf Apprentice

Joined: 15 Jul 2018 Posts: 214
|
Posted: Sat Mar 15, 2025 2:59 pm Post subject: |
|
|
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 |
|
 |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5620 Location: Bavaria
|
Posted: Sat Mar 15, 2025 4:38 pm Post subject: |
|
|
krumpf wrote: | Thanks for the explanations. |
You are very Welcome.
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 |
|
 |
|
|
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
|
|