The Linux Scheduler: A Decade of Wasted Cores (2016) [pdf]
people.ece.ubc.ca
people.ece.ubc.ca
A better design would be to only lock a subset of dirty pages and let new writes to virtual memory continue while the write-out is happening, but it doesn't seem like the system can accomodate that.
A simple test to see this in action is to use netcat to transfer a large file across the network, and monitor the device activity with sar or atop (or just check the disk/network activity lights). What you'll see is that while the disk is writing, network activity drops to zero, and when network activity resumes, the disk remains idle again for seconds. It doesn't matter how much smaller you make vm.dirty_background_{bytes,ratio} with respect to vm.dirty_{bytes,ratio}, the network traffic will block as soon as the "background" disk write starts. The only effect a low value for vm.dirty_background_{bytes,ratio} has is to increase the frequency at which the network and disk activity will alternate.
Edit: apparently it has been done, but only very recently and hasn't had a major distro ship it yet
I'm okayish at systems level debugging but I never figured that one out. It caused the kernel to use alot of memory. Arguable whether or not it impacted performance since it was a cache.
There was a kernel patch though that solved around 95% of issues with no userspace changes: vm.dirty_write_behind. Unfortunately it never made it into the mainline kernel. [1] For strong latency guarantees it ws insufficient but it greatly improved the typical network/IO spike alternations described above.
I'm surprised it was never fixed upstream despite that fact that even most basic and simple scenarios like "nginx writes a log file to the disk" sometimes explode with seconds-long lockups on memory-fat machines.
[1] https://lore.kernel.org/linux-fsdevel/156896493723.4334.1334...
That is unfortunate, and a bit surprising given how positively both Linus Torvalds, and Jens Axboe, responded to the patch.
But really, this is all fantasy given that I know nothing about the virtual memory internal data structures.
Edit: fixed typo
[1] https://docs.kernel.org/core-api/xarray.html
[2] https://elixir.bootlin.com/linux/latest/source/include/linux...
[3] https://elixir.bootlin.com/linux/latest/source/mm/page-write...
[4] https://elixir.bootlin.com/linux/latest/source/mm/page-write...
There is just one caveat with regards to the previous solution: pages that are already pending writeout still need to be locked. In the previous design, a write to a page already pending writeout could be duplicated into the new dirty queue. But since it seems that a page can exist only once in the page cache, it cannot be written to without possibly violating write barriers. So the write must block until the writeout process has un-dirtied the page.
Armchair programming is fun, isn't it? :)
The Linux scheduler: A decade of wasted cores (2016) - https://news.ycombinator.com/item?id=33462345 - Nov 2022 (26 comments)
The Linux Scheduler: A Decade of Wasted Cores (2016) - https://news.ycombinator.com/item?id=15531332 - Oct 2017 (35 comments)
The Linux Scheduler: A Decade of Wasted Cores - https://news.ycombinator.com/item?id=11570606 - April 2016 (38 comments)
The Linux Scheduler: A Decade of Wasted Cores [pdf] - https://news.ycombinator.com/item?id=11501493 - April 2016 (142 comments)
I'd take a patch of CFS and its millions of broken knobs from Google over newly released EEVDF any day, because I trust scheduler AB testing by Google over millions of machines and every single scheduling pattern under the sun way more than whatever synthetic micro-benchmark a single kernel dev (as competent as they might be) ran.
If you're interested in quantitative analysis of schedulers & tooling around it, these 2 projects are very interesting:
https://github.com/google/schedviz
https://fuchsia.dev/fuchsia-src/concepts/kernel/fair_schedul...
I have nothing against the EEVDF algorithm itself (in fact I like it) and I dislike CFS very much. But I dislike the current development process of the Linux scheduler even more. Proper quantitative benchmarks of CPU schedulers are missing, which is why CFS ended in the sad state it did, where hundreds of patches were submitted to fix random edge cases over the years. What makes you confident that the initial EEVDF Linux implementation won't suffer the same fate, given that the development process hasn't changed (single kernel dev implementing it and running micro benchmarks)?
An increase in performance of 10-30% across "real" workloads. Just for changing one line (well, two lines including disabling p-state drivers)? I'll take it.
I would say its not a strange position to assume it has been improved further since then.
What would be interesting although niche is checking how iGPU's perform alongside it. I know that on Intel, "thermald" lowers iGPU performance because it improves CPU utilization and thus leaves less mW for the iGPU. Perhaps something similar will happen with EEVDF.
Granted, this combination is rather rare. Most people aren't capable. Of those who are, they have better things to do and they probably have very well paying jobs they could be focusing on instead.
With that being said, Linux is _still_ more efficient than Windows.
I don't want to say Linux is free, in practice it's not, those who are running the big powerful machines are using RHEL and paying hefty licenses.
Which are still better than any other alternative.
Google/Amazon/MS isn't paying RHEL licenses.
Reason for using RHEL is basically "we don't want to hire experts", which makes a lot of sense in small/midsized company but in big one it's probably mostly the ability to blame someone else if something is fucked up, and the fact some of the software basically says "run it on this distro or it is unsupported".
This never happened, of course. But it's CYA.
We couldn't containerize it (it's a client for a security monitor), we couldn't ship it as a VM, so eventually we all agreed to ditch everything except RHEL and everyone else would be unsupported (we grandfathered all the existing ones in, and it took a year and a half before everything worked.).
This is the sort of research that scientific grants are _supposed_ to be targeting for the public good. Supposed to be.
he had scheduled 9 "use 100% of a core" processes on an 8 core machine and expected each process to get 8/9ths of a core on the machine, with each process proceeding at the same rate. (If I got that math wrong, basically I mean that all processes should receive the same amount of CPU time over an interval, with the expectation that the CPUs will be at 100%).
Instead, he found that one of the 9 processes always went slower than all the others. Tru64 did what he expected. I believe at this point, we were running a kernel before the completely fair scheduler, but I've always wondered if there was a right answer here- I don't think UNIX or Linux truly 'guarantee' fully predictable and evenly divded CPU performance when you have n+1 (or n+whatever) processes running on n cores.
(also, he used "yes > /dev/null" as the CPU-generating task and I had to spend a lot of time explaining to him that wasn't really 100% cpu)
Can you explain?
If you look at the source code for yes, https://github.com/coreutils/coreutils/blob/master/src/yes.c
it builds a buffer of output and then writes that in a for loop
while (full_write (STDOUT_FILENO, buf, bufused) == bufused)
continue;
Inside the kernel, /dev/null is handled by doing nothing. So basically when this runs, the majority of the CPU time it consumes is just context switches from process to kernel and back. It consumes 100% of a core on an idle machine, but what you really want for your basic scheduling test is to have a pure CPU hog with no kernel transitions (I've seen variations- increment a register, do some light flops that don't hit memory, or even just a nop loop (which is basically "increment register, branch if less than"). If you get the expected performance on the cpu hog, then you can proceed to the yes hog.https://tuxcare.com/blog/linux-kernel-6-6-is-here-find-out-w....
So it helped me at least :-)
And for multicore scheduling, job shop scheduling [1], it is the even harder version of NP-Hard (no pun intended). This is literally taught in senior year uni CS class, that there is no perfect solution to the scheduling problem, unless Cook-Levin Theorem or anyone of those NP-Complete problems are solved [2].
[1]: https://optimization.cbe.cornell.edu/index.php?title=Job_sho...
[2]: https://www.cse.cuhk.edu.hk/~siuon/csci3130-f19/slides/lec22...
Most real-world combinatorial problems can be solved relatively well. This is why Gurobi is in business, Alpha Go exists, or why Amazon and United Airlines still manage to practically solve their resource allocation problems.
[1]: https://netflixtechblog.com/predictive-cpu-isolation-of-cont...
By too much I mean:
1. A clickbait title
2. A conclusion that phrases “scheduling was thought to be a solved problem”
This oddly lines up with an observation I've made about traffic lights. It is very surprising how often you'll be stopped at an intersection where everybody is waiting and nobody is allowed to go, sometimes for what feels like 10-30 seconds.
It seems like the lowest-hanging fruit for improving traffic is to aim never to have degenerate intersections. If someone is waiting and nobody is going, the light should change quickly.
The sensors help gather high quality data for traffic models though. That should help traffic engineers to do their job
(You'd think this was obvious, but I've been on the Internet a while and it sure isn't.)
I mean, I get that they are testing a general fix for the sort of problems that, like, non-scientific-computing users get. So it isn’t to say the work is useless. It just seems like a funny example.
I think coming up with benchmarks for schedulers must actually be very difficult, because you have figure out exactly how silly of a thing you want the imagined user to do.
I’d love to see something new built with modern practices and ideas come and dethrone it. Maybe Theseus OS (not affiliated).
The stuff that can be changed without breaking compatibility is, well, it was the developer's best idea at the time and some of them turned out to be good, some turned out to be bad.
Going "but on paper that idea would be better, let's make OS around it" rarely ends up being plain better. It's not one dimensional.
For example if your CPU scheduler makes all jobs run faster (less cache thrashing while keeping CPUs busy etc.) but is unfair, that might be great for people running batch jobs, but shit for desktop users.
Scheduler wasting cycles but making sure interactive tasks get the right level of priority might be improvement for desktop users but not for server use etc.
Or you figure out that the reason something was "unnecessarily complex", was actual necessary complexity that wasn't obvious at first.
Also Linux isn't exactly stranger to taking the whole bunch of code and replacing it with something better, I think we're at 3th firewall stack now (ipchains -> iptables -> nftables)
- a real-time kernel
- a single user mode kernel
- an embedded device kernel (like an esp 32 or rpi)
- general purpose desktop use (surely there are gems in here)
- to use the linux kernel as a hypervisor hosting others
- tuning the linux kernel for within a vm (guest to another hypervisor)
- tuning for gaming performance
I myself do not know enough about sysctls, and I'm sure it's a goldmine.