The Linux kernel has been accidentally hardcoded to a maximum of 8 cores
thehftguy.com
thehftguy.com
If you read the commit [0], you can see, that a /certain/ scaling factor for scheduling can scale linearly or logarithmically with the number of cores and for calculating this scaling factor, the number is capped to 8. This has nothing to do with the number of cores that can actually be used.
[0] https://github.com/torvalds/linux/commit/acb4a848da821a095ae...
* On single core machines the scheduler interval is quite fine grained to ensure responsiveness.
* As the number of cores grows, the scheduler interval increases (by default), presumably because there's greater cost to task switching across more cores and the greater number of cores inherently increases the responsiveness anyway.
* BUT – and this is the point of the article – above 8 cores, the scheduler interval remains constant rather than increasing further.
If I have read it right, then surely that's exactly what you want? If you have done enormously beefy server with hundreds of cores then you don't want a CPU bound task persisting for several seconds! You almost certainly have proportionally more tasks to run and need to keep that interval down. There's presumably also diminishing increases to the cost of switching across more cores (admittedly a logarithmically increasing interval, as mentioned in the article, world also cope with that). And, in any case, a huge server is more likely to have this sort of setting manually tuned.
If there is a bug here at all then it's a minor one, nothing like the title suggests.
Performance was critical, and we had beefy developer machines (for the time), all with 8 cores. Development was done in C++, and as the project progressed the system performed very well, and more than exceeded our performance goals.
Fast forward a couple of years and it became time to put the thing into production on a massive 128 core Windows server. Much to our surprise the performance completely tanked when scaled to all 128 cores.
After much debugging, it turned out that the system spent most of its time context switching instead of doing actual work, and because we used atomic operations for message queue functionality (compare & swap), it effectively meant clearing the cache for every core working with/on that piece of heap memory, so every time a task passed a message to something else, it effectively reset the CPU cache, which would then have to be refetched from RAM. This was not (as big) a problem on the developer machines, as there were fewer cores and each task had more work queued up for it, but with 16 as many cores to work with, it simply ran out of tasks to do faster.
The "cure" was to limit the system to run on 8 cores just like the developer machines, and AFAIK it still runs in that way all these years later.
Why? The article show no evidence of this being problematic.
> It can’t be good to reschedule hundreds of tasks every few milliseconds, maybe on a different core, maybe on a different die. It can’t be good for performance and cache locality.
Make a PoC and prove it.
It won't be appearing again in my feeds that's for sure.
I can understand having a bug like that, but unnoticed for 15 years? more than 8 cores was rare 15 years ago, and as a percentage of chips sold is still rare, but presumably people with threadrippers ran benchmarks? optimized? etc? just doesn't seem possible
Still don't get after rereading the article, what is the malus, it must be small by that? Because you definitely saw linear scaling with parallelizable problems on >8 cores, otherwise people would have noticed?
So this is only relevant for an overloaded system, and furthermore just means that processes may be preempted after 3ms (instead of that protection delay keeping on increasing), ignoring all other tunables e.g. priority and stuff.
Not only that but it’s a log2, so if this was relaxed on a 128 cores system you’d have a preemption delay of 7ms instead. I don’t think that would save you if you’re overloading a 128 cores system honestly, although it does beg the question as to why the kernel devs felt the need to cap the scaling. Even assuming it scales per thread, and you have a dual socket epyc, log2(512) = 9.
Clickbaity headline from a technical person makes me sad :(
The issue us more subtle: "[the minimum granularity] is supposed to allow tasks to run for a minimum amount of [3ms] when the system is overloaded".
That's supposed to scale with number of cores, but the scaling us limited to 8 cores. However, imho that's not even necessarily a bad thing. It's a trade off between responsiveness and throughput in overload situations. You don't want slices to become too tiny/large...
The number of cores in the heuristic used to calculate task switch frequency was capped to 8.
This is a reasonable thing to do as a heuristic, because you don’t want your time slice to grow indefinitely with core count on an interactive system.
E.g. 1 ms slice with 1 core = 1000 process switches per second. With 2 cores you can increase the slice to 2 ms and still maintain the same number of switches per second for the system, but reducing the switches per second on each core to 500. This reduces the overhead for the scheduler.
It seems like at around 8 times the slice efficiency starts to go the other way, so they’ve limited it. Seems reasonable, but scheduler math is crazy.
Note, that this has nothing to do with the scheduler assignments per core which have clearly been working or people would’ve noticed!
You'll lose your mind once you realise that Windows NT handles a lot of things single-threaded. I had a situation once where I was handling a few million packets per second of TCP on Windows and it only pins a single core.
Though: that's not what TFA is looking at: in this case you're not actually limited to 8 cores, you're limited to slicing your executions into 8 parts per cpu per "tick".
This is a known way of scheduling, you only get 1/8th of a tick with a fair scheduler.
From what I understand what was limited to 8 cores is the scaling of the preemption delay (min_granularity / min_slice). Again from what I understand that what this is is the window during which a process can not be preempted, so this is only relevant when the scheduler has more tasks to run than available slices (the system is heavily / over - loaded).
I would assume well-administered systems where this would be relevant:
1. Are not overloaded
2. Have the important tasks pinned to avoid migrations
3. Have priorities configured to avoid preempting / descheduling their primary workloads
As such, on a well-administered system this would mostly translate to possibly over-pre-empting low-priority tasks (and most likely not pre-empting anything because the machine is configured with capacity for those ancillary / transient low priority tasks). This may show up during transient overloads, and worsen an already bad situation, but it probably wouldn’t show up during normal operations.
It also doesn’t seem accidental, the maintainers literally slapped an `min(8, …)` on there, so they explicitly designed the scaling to have an upper bound. Maybe it’s a mistake, maybe it’s too low, maybe it should be a tunable, but I’d think it makes sense to not allow the preemption delay to grow infinitely.
Either the author is deranged or this was written by AI.
If capped to 8 it would be very clear
Reading the other comments here it seems the title is stupid and wrong and my suspicion that this can't be right was correct.
So it’s only relevant if the system has more tasks than cores, and if you ignore priorities and pinning. I assume these are the sort of mistakes people working with supercomputers would not be making, and residency would be a very carefully monitored to ensure the system is not thrashing.
And the function that does this uses the same value for 8 and more cores.
So the performance impact is likely <<1%.
en.wikipedia.org/wiki/Brain_Fuck_Scheduler
i’m doing high performance gamedev on a 7950x with smt off. 16 cores.
i can only use 8 to run the game.
mutex and other synchronization gets highly variable latency if the first 8 cores try to talk to the second 8.
i hadn’t heard of this before i started this game, but apparently it’s well known, and nobody makes a chip with more than 8 cores that can have low variability synchronization.
linux running on 8 cores seems like a potentially good idea. one wants the kernel to have low latency with low variability.
Essentially, a 16 core AMD CPU is actually two separate 8 core CPUs glued together with a link.
Intel does not have this limitation.
Edit: Though I'd still recommend heeding menaerus excellent sibling answer. Maybe not for this project, but it is great knowledge to have in your domain and I'd expect it to be relevant for the future.
When dealing with NUMA we know that cross-socket, or in this case cross-CCD, latencies are always higher than the ones within the same socket or same CCD. Usually multi-fold.
This article nicely lists the core-to-core latencies between the Intel and AMD microarchitectures: https://chipsandcheese.com/2023/07/17/genoa-x-server-v-cache...
So, if you're able to somehow take advantage of this knowledge in your code (e.g. by scheduling less latency-sensitive tasks to the other CCD), you may be able to improve your overall performance.
when i compile, all 16 cores are used.
when playing, core0 is main thread, core1 is physx, core2 is network, core3-7 are background jobs used by main thread.
i’m not sure more than 8 cpu cores can be meaningfully used by any current game engine tech.
when i run the server locally, i reduce usage to 4 cores so client and server don’t contend. not much impact.
One thing I noticed is that min/max functions are tricky to use and it's easily to accidentally do the wrong thing, like in this case
Because you think "you want the minimum (that is, the number should be at least 8) of those numbers to be 8" then you slap min(). And you got it wrong. You should have used max()
But that aside, I feel your pain around min() and max(). In my case, I feel the problem comes from language (I mean, the real life one): I speak Italian and in Italian the words for "at most" are "al massimo" (i.e. "at max") and the words for "at least" are "come minimo" (i.e. "as min") that is, the exact opposite of their mathematical meaning. I've taken an habit of reviewing 3 times any piece of code where I write "min" or "max" for this reason.
I appears the author has misunderstood exactly what was its purpose, and that setting this scaling factor unbound beyond 8 cores would have detrimental effects even if there are more cores available.
x.atLeast(10).atMost(100)
Very easy to read in my opinion