Linux Gets O(1) SMP Patch As Late Christmas Gift
bodin writes: "Now that new-year's parties are over things are getting boring again. For those who want to see and perhaps even try something more complex, Ingo Molnar is
announcing this patch that is a pretty radical rewrite of the Linux
scheduler. This is big stuff!"
Hehe!
I liked O Xymoron's enthusiastic response:
On Fri, 4 Jan 2002, Ingo Molnar wrote:
> this is more than 6 million context switches per second!
Everyone knows scheduling is boring.
:)
Yours Sincerely, Michael.
For those of you who haven't read enough computer science to know what O(1) means, here is a short explanation.
The Big O-notation is a way to describe how the (asymptotic) execution time of an algorithm depends on the inputs to the algorithm. For instance, an algorithm that loops over n values is said to have the asymptotic execution time O(n) - it is proportional to the number of times the loop is executed.
Similarly, an algorithm that runs in constant time, i.e., that takes equally long to execute for 10 values and for 1000000 values, is said to be O(1). The execution time is proportional to 1.
For the Linux scheduler, switching processes is O(p), where p is the number of currently running processes. This new scheduler switches processes in O(1) time.
This means that even though the old scheduler might be fast for low numbers of running processes, it will take longer and longer timer to switch processes when the number of active processes grow. The new scheduler will switch processes just as fast for 2 processes or for 200 processes. Even though the new scheduler might be slower in when there are few processes, it will be faster when the number of running processes increase.
of myself)
I don't know if in 2.ed kernels Linus still likes the "small patch" idea. but this is pretty amazing. I am no kernel coder, but some of these tests showed 600% percent improvement and (seemed to me to be) impressive scaling. All the kernel gurus out there, what is the chance that this will make it into the kernel? (2.5)
What comes first, finding a teacher or becoming a student?
Before attempting to install this on my test box I'd like to know exactly what the performance inplications are to specific types of applications and services. For example I am extremely interested in improving JVM performance on a Linux box.
Any information or direction about this would be very helpful.
Wow. I read this guy's description of what he has done. I hope he's a teacher, because his explanation of those complex issues was a joy to read.
I have a BP6 dual-celeron Debian machine which already gives me the benefits of countless hours of volunteer time, including the SMP kernel and ReiserFS, along with dozens of free development tools. Now I see this guy working like a dog to tune the heck out of the scheduler for SMP machines, and I know that when I eventually run the 2.6 kernel, I'm again going to reap the benefits of his work.
It's almost enough to make me learn to hack the Linux kernel out of a sense of obligation.
Patrick Doyle
I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
By the way, since the links /and/ the URL's (as far as I can tell) in the post are broken, this should help:
:) but hey, my kernel compiled just fine.
e 8s chedO1.patch.gz
2 pr e8schedO1.patch.gz
:)
;)
:)
:-\
http://people.redhat.com/mingo/O(1)-scheduler/
I've created diffs between 2.5.1 and 2.5.2pre8 with the O(1) scheduler, and between 2.5.2pre8 and 2.5.2pre8 with the O(1) scheduler.
2.5.2pre8 actually patches pretty well with the original scheduler patch (drivers/char/serial.c.rej can be ignored, and you have to make a few changes to kernel/sched.c in order for it to patch correctly), but because it took me at least ten minutes of fiddling with sched.c I've decided to make a diff for 2.5.2pre8.
No guarantee that either of these works, though
# diff -ru linux-2.5.1 linux-2.5.2pre8schedO1|grep -v '^Only in '|gzip -f >/home/web/patch-2.5.1-2.5.2pre8schedO1.patch.g z
http://os.markbach.com:8080/patch-2.5.1-2.5.2pr
(396,961 bytes)
# diff -ru linux-orig linux |grep -v '^Only in ' |gzip -f >/home/web/patch-2.5.2pre8-2.5.2pre8schedO1.pat ch.gz
http://os.markbach.com:8080/patch-2.5.pre8-2.5.
(31,124 bytes)
Good luck to anyone who tries to use these
And no, I didn't patch in the kdev_t stuff from people/aeb on kernel.org because there's lots of kdev_t stuff in the Changelog for pre7 and pre8, so I decided to assume (yes, I know, assuming makes an ass out of u and me) I didn't need it... of course, when the system crashes after five seconds, maybe I'll change my mind
And if, for some odd reason, you can't connect on port 8080, just connect on port 80 and let's hope you're not blocked by @home's or my firewall.
Damn, I'm using too many smileys
--TheOrangeSquid Is it any wonder things seem so awry? We swim in a sea of confusion and don't have to think to survive
Am I the only person that thinks that every time I see his name?
Will this make apache 1.x as fast as 2.0? I thought one of the main performance bottle necks in the 1.x series was that for every connection a new process had to be forked. And that the system suffered because each process added overhead because it was dependent on a scheduler that didn't scale well. Apache 2.0 solved this problem by using threads instead of forks. But with this new patch will the 1.x version work just as well as a 2.0 version that doesn't use the fancy new features
I haven't really worked with Linux, but despite my technical aversions toward this OS then I sure don't hope that switching processes is linear in time.
An OS maintain a list of running tasks (processes) and each time a task has used up its timeslice (which is around one tenth of a second) or volunterely given up the processor (because it has no more work to compute), then the next task is taken from the list (and the previously running task is appended to the end, unless it volunterely gave up the processor) -- this is "task switching" and the principle is often referred to as roundrobin. Something that most should be able to implement as a constant-time operation.
Often one would use a priority queue instead of a list, that is, the task each have a priority, and instead of adding tasks to the end of the list, they are inserted according to their priority (this can still be done in constant time by e.g. having an array of lists, where the index in the array is the priority).
Using priorities you ensure that tasks with high priority always get the processor when they need it (e.g. a mouse driver) and tasks with low priorities to never interfer with the users work (like a batch job running in the background).
The above is often called static scheduling, because the priorities are set once, and never touched. But this is often not desireable, because it's a tough job adjusting all those priorities, and perhaps not even possible on a multi user system.
So what do we do? Well... this is where black magic comes into play. One simple solution could be to boost the priority of all the tasks which doesn't use their full time slice (so they'll have a higher priority next time they run, because we assume that they won't run for long).
Many heuristics exist to try and make dynamic scheduling (priority rearranging) fair. Often these heuristics only rearrange priorities a few times pr. minute, based on statistics on how the tasks have behaved the last n seconds.
Since this process involve all the running tasks, then it is in nature linear in time (but of course some tricks exist). But as said, this algorithm runs only a few times pr. minute, but the result affect the entire fairness/responsiveness of the machine. So time is probably better spent crafting a better heuristic than making it O(1) instead of O(n).
In additional good news, Ingo and Robert are right now working on making the O(1) scheduler and kernel-preempt play nice together - suddenly, linux starts looking very attractive for BeOS/media-desktop junkies...
Davide Libenzi's been shooting some holes in the architecture of this patch--he's also written a highly scalable multiqueue scheduler. He and Mingo are currently hammering out some ideas, almost certainly something will go into 2.5 but this may not be it.
rage, rage against the dying of the light
Each time a process became runnable, the NN could assign a priority, and the process would be placed on a priority queue (this isn't O(1), but it's better than O(p)). It seems to me like this would work; it would slow down wake_up_process() (i can't remember the exact name; i haven't looked at the scheduler since october) a bit, but the payoff as the NN got trained should make up for it...
(if this is a terrible idea, tell me so before you moderate me down
I wish SPI would get a PayPal account so I could make these "warm fuzzy" donations on the spur of the moment.
Bob-
The Ludwig von Mises Institute. The reasoning individuals economics
Since Linux already whups Windows in so many other ways, I am looking forward to it beating Win's SMP integration and scaling. Yes, I know it's likely just FUD, but my memory of the last time I read a scaling test was that Win did CPU.gt.2 better.
Clustering and SMP are different answers to different questions, but they both lead to multiplying your firepower without multiplying your cost. Add that to the issue of purchase cost for Win and Lin, and the differences become even more severe. Every effective Linux improvement multiplies Linux effectiveness overall.
As an individual user, I have little use for SMP. Games run just fine on one CPU. So for now, I'm just a fan. We shall see what happens.
BTW, is it just me, or is the fact that these two developers, with different ideas of "right", are working together to make something even better, lighting up other peoples days too?
Bob-
The Ludwig von Mises Institute. The reasoning individuals economics
Why do we want everyone's grandmother to be using Linux?
My grandma refuses to use Linux because its scheduler is O(n) and its "goodness" function can blow her L1 cache. If Linus adopts Ingo's O(1) scheduler, she just might reconsider.
cpeterso
Cool!
In US, you always find party. In USSR, party always find you!
Sorry but this is not going to magicly make your system that much faster.
/much/ quicker.
The whole point of this patch is that it makes the switch time linar O(1) as opposed to exponetial O(p), most people not run machines with enough seperate processes (i only have 80, and im in a java dev sessio now), to see a difference.
What it does mean is that the big Oracle / IBM (the people who wanted the improvement), database systems running on 8 / 16 CPU untis with 10,000s of database transactions will be
-matthew
Since when did ignorance become a point of view ??
> it makes the switch time linar O(1) as opposed to exponetial O(p)
No, it makes it constant, instead of linear with the number of processes that are ready to run. Processes that are waiting for I/O (or otherwise sleeping) are not on this queue, and thus aren't slowing you down with even with the old scheduler. Your 80 processes are _not_ all running.
Besides the algorithmic complexity improvement, Ingo says he's improved CPU affinity, and made fork()+exec() more efficient by running the child on the same processor.
But as you say, the main improvement will be in large multiproc systems that are worked to the limit (so they have lots of _runnable_ processes). You won't, of course, see 600% improvement in Oracle performance or anything. That was only in synthetic benchmark. The 600% improvement is in something that takes up a fairly small (but not insignificant) part of a DB server's time.
Another thing this should help is people who run distributed.net or SETI clients. They run at nice 19, and if I read Ingo's message correctly, such processes will be treated as SCHED_IDLE: That is, they will get _no_ CPU time while you're recompiling something, or compressing a vorbis audio file, instead of the usual 7% or so they get now, when a nice=0 process wants all the CPU it can get.
Well, I'm impressed. I like how well he presented his work, it was pretty easy to understand.
#define X(x,y) x##y
Peter Cordes ; e-mail: X(peter@cordes ,
600% improvement on something that your machine probably spends very little time doing. It's not going to turn your 1GHz system into a 6GHz system...