Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

Linux Gets Completely Fair Scheduler

Posted by kdawson on Tue Jul 10, 2007 08:55 PM
from the take-turns-now dept.
SchedFred writes "KernelTrap is reporting that CFS, Ingo Molnar's Completely Fair Scheduler, was just merged into the Linux kernel. The new CPU scheduler includes a pluggable framework that completely replaces Molnar's earlier O(1) scheduler, and is described to 'model an "ideal, precise multi-tasking CPU" on real hardware. CFS tries to run the task with the "gravest need" for more CPU time. So CFS always tries to split up CPU time between runnable tasks as close to "ideal multitasking hardware" as possible.' The new CPU scheduler should improve the desktop Linux experience, and will be part of the upcoming 2.6.23 kernel."
+ -
story

Related Stories

[+] The Completely Fair Scheduler 292 comments
hichetu writes "Kernel trap has a nice summary of what is going on behind the scenes to change the Linux Scheduler. The O(1) Linux scheduler is going to be changed so that it is fair to interactive tasks. You will be surprised to know that O(1) is really too good not to have any side-effects on fairness to all tasks."
[+] The Completely Fair Scheduler's Impact On Games 315 comments
eldavojohn writes "We've heard a bit about the completely fair scheduler previously, but now Kernel Trap looks at the implications this new scheduler has for 3D games in Linux. Linus Torvalds noted, 'I don't think any scheduler is perfect, and almost all of the time, the RightAnswer(tm) ends up being not one or the other, but somewhere in between. But at the same time, no technical decision is ever written in stone. It's all a balancing act. I've replaced the scheduler before, I'm 100% sure we'll replace it again. Schedulers are actually not at all that important in the end: they are a very very small detail in the kernel.' The posts that follow the brief article, reveal that Linus seems quite confident that he made the right choice in his decision to merge CFS with the Linux kernel. One thing's for certain, gaming on Linux can't suffer any more setbacks or it may be many years before we see FOSS games rival the commercial world."
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More
Loading... please wait.
  • crap (Score:5, Funny)

    by cachimaster (127194) on Tuesday July 10 2007, @08:58PM (#19820885)
    just finished make xconfig;make from 2.6.22!
    • Re:crap (Score:4, Funny)

      by cachimaster (127194) on Tuesday July 10 2007, @09:05PM (#19820937)
      Is not fair!
    • by EmbeddedJanitor (597831) on Tuesday July 10 2007, @09:05PM (#19820943)
      Should take you less than 15 minutes to get there again.

      If you really want a rough time, see how long it takes to rebuild a different OS.

      • Re:crap (Score:5, Informative)

        by Hikaru79 (832891) on Tuesday July 10 2007, @11:18PM (#19821753) Homepage

        Great. A new scheduler will surely attract more masses to Linux than, say, a non-ugly GUI-lib or a sane, standard windowing-environment would. That's the way to go.


        Well, no offense, but I'm glad it isn't you that's in charge of making important decisions in that case. I realize that you were probably less than half-serious, but I would hate for the Linux community to ever be in the stage where "attract more masses" is a goal that diverts effort from interesting projects like this one.

        With that said, what's wrong with Qt/KDE, particularly the new versions (the ones still in Alpha)? I'd say it is very much a "non-ugly GUI lib", and a "sane windowing environment".
        • by Sillygates (967271) on Tuesday July 10 2007, @10:31PM (#19821475) Homepage Journal
          What version of KDE are you running?
        • Re:crap (Score:4, Interesting)

          by Anonymous Coward on Tuesday July 10 2007, @11:04PM (#19821667)
          a fair scheduler won't help. BeOS had a very snappy, responsive GUI by being multithreaded (each window was a thread) and giving window/display threads higher priority. Even if the CPU(s) were bogged down with other threads, moving windows, the display stayed responsive. X is single threaded and the window manager architecture makes the problem worse. A fair scheduler doesn't help; it actually makes things worse.
          • Re:crap (Score:5, Interesting)

            by arodland (127775) on Wednesday July 11 2007, @12:52AM (#19822193)
            Yep. I've seen this in CFS testing actually. Pretty much all of the work that the X server does can be assumed to be "on behalf of" somebody, but in the end those cycles still belong to the X server. So an app can be thoroughly abusive, spam the X server with requests, fill up queues, and prevent anyone else from using the server to do anything useful -- and yet it still gets priority because as far as the scheduler can tell it's a perfectly nice I/O-bound task that spends most of its time waiting for the X server to get back to it. As I recall, Linus provided a "fix" for that particular problem sometime early in 2.6 or late in 2.5 -- but later retracted it because it did more harm than good -- any simple solution you might think of has already been tried and thrown away.

            Oh, and the abusive app that likes to make X servers choke? Firefox. Ugh. Hate that thing. :)
  • For the really touchy-feely OS out there!
  • Neato (Score:4, Insightful)

    by friedman101 (618627) on Tuesday July 10 2007, @08:59PM (#19820899)
    What sort of gain can the typical linux user expect because of this?
  • Process Neutrality? (Score:5, Interesting)

    by Speare (84249) on Tuesday July 10 2007, @09:03PM (#19820917) Homepage

    I know enough about process scheduling to fill a ketchup cup at the nearest burger joint, but it struck me that this sounds like the debate about "network neutrality" vs "tiered service." The O(1) was supposed to be a very generic decision-making system that made a decision in a very agnostic way (to simplify the work down to a predictable consistent order of work). This CFS strikes me as a system which will have a much higher level of complexity and context awareness, which sounds like some processes will get more than others. The intention is to make it fair in the real world but not necessarily balanced, since not all processes are alike in their needs or expectations of task switching.

    This is just rambling on, and admittedly it may be straining a metaphor too far, so don't go crazy biting my head off for not knowing all things about the kernel. See 'ketchup cup' above.

    • by Anonymous Coward on Tuesday July 10 2007, @09:22PM (#19821035)
      Sort of. Scheduling algorithms are very important for routers too. So there is an analogy. But the analogy isn't with a tiered internet. It's with protocol based QoS. For instance, VoIP requires very low latency, but BitTorrent doesn't. So shaping traffic so that VoIP stuff gets handled by a router first (while minimally affecting BitTorrent) improves the quality of service. On the kernel scheduling side of the analogy, some software needs to have quick access to the processor, often, but for short periods of time. A GUI interface is an example. Real-time software is a more important example.

      A tiered internet is something else entirely.
    • by DreadSpoon (653424) on Tuesday July 10 2007, @10:16PM (#19821377) Homepage Journal
      I think you have this TOTALLY backwards.

      The old scheduler was filled with huge chunks of complex code to try to guess at which processes were interactive and such, and would then specially treat those processes differently when scheduling.

      The CFS does none of that. It schedules all processes the same, in a completely fair manner, and doesn't have any special logic in it that tries to classify processes at all, other than nice levels.

      The part yet to be merged is the process grouping, which again isn't anything like the interactivity guessing code. It's just a simple way to say "these processes belong together, so when you do the CPU scheduling, treat them as a single group." It's basically just a weighting mechanism with a logical container.
  • by SoVeryTired (967875) on Tuesday July 10 2007, @09:11PM (#19820983)
    Karma Whores:

    Steal your insightful comments from http://linux.slashdot.org/article.pl?sid=07/04/22/ 1335255 [slashdot.org]

  • Why... (Score:5, Funny)

    by lawpoop (604919) on Tuesday July 10 2007, @09:14PM (#19821005) Homepage Journal
    Why does this sound like the title of a Monty Python Skit?

    "Why isn't my process getting more CPU time?"

    "Well, Sir, it's a Completely Fair Scheduler."

  • We saw crazy performance improvements implementing kqueue in bsd, would love to see something that great at handling many sockets standard linux.
  • --mm line (Score:5, Informative)

    CFS has been available for some time in Andrew Morton's -mm branch of the kernel. If you really want it now, just download his latest patch and there you go.

    I've reen running with it for some time, and I really like it. I'm still not sure if it is better than Con Kolivas' SD scheduler in his patchset, but we'll see.
  • by s_p_oneil (795792) on Tuesday July 10 2007, @09:37PM (#19821133) Homepage
    The only way to make it completely fair is to let one thread slice the time up, and let the other thread choose which slice it wants. ;-)
  • Poor attribution (Score:4, Insightful)

    by the_greywolf (311406) on Tuesday July 10 2007, @10:48PM (#19821579) Homepage

    So little credit is given to Con Kolivas, whose Staircase Deadline scheduler (a more mature and refined design than CFS) spurred Ingo to finally improve his scheduler (which he wrote on the spot because, apparently, Con's scheduler wasn't good enough for him).

    And all Con gets is a minor footnote.

    • Re:Poor attribution (Score:5, Informative)

      by Anonymous Coward on Tuesday July 10 2007, @11:06PM (#19821683)
      Not only does he get very little credit, but the whole experience of trying to get his patches merged into the mainline have soured him on kernel development altogether:
      [ck] It is the end of -ck [bhhdoa.org.au]

      It is clear that I cannot develop code for the linux kernel intended only to
      be used out of mainline and not have mainline get involved somewhere along
      the line. Whether it be the users or even other developers repeatedly
      asking "when will this be merged". This forever gets me into a cycle of
      actually trying to merge the stuff and ... well you all know what happens at
      that point (again I had nastier words but decided not to use them.)

      This is pretty sad for linux kernel development.
      • Re:Poor attribution (Score:4, Informative)

        by Anonymous Coward on Wednesday July 11 2007, @02:29AM (#19822645)
        here is Linus' take on this issue:

        A big issue for me is also the difference in how Con and Ingo took criticism. Both SD and CFS were criticized by various people over different things, and quite frankly, Ingo ended up trying to figure out why something didn't work, while Con ended up getting involved more in flame-wars with the people who criticised SD. Is that important too? Yes it is.
        The full posting of Linus is at: http://bhhdoa.org.au/pipermail/ck/2007-June/007856 .html
    • Re:Poor attribution (Score:5, Informative)

      by tglx (664015) on Wednesday July 11 2007, @01:50AM (#19822475)
      > So little credit is given to Con Kolivas ...
      > And all Con gets is a minor footnote.

      I'm a kernel developer myself and quite surprised you see it that way.
      Let's take a look at the kernel code:

      1) Ingo credited Con for the "fair scheduling" approach right on the first page of kernel/sched.c. That's the
      most prominent place you can get credited for working on the Linux scheduler

          * 2007-04-15 Work begun on replacing all interactivity tuning with a
          * fair scheduling design by Con Kolivas.

      2) He credited Con for a line of code that he added to CFS from SD, in kernel/sched.c

          * This idea comes from the SD scheduler of Con Kolivas:

          This is the only SD code in CFS - the two designs and approaches are quite different.

      3) He credited Con in Documentation/sched-design-CFS.txt

            I'd like to give credit to Con Kolivas for the general approach here:
            he has proven via RSDL/SD that 'fair scheduling' is possible and that
            it results in better desktop scheduling. Kudos Con!

      4) Finally he credited Con in the CFS commit log as well:

        commit c31f2e8a42c41efa46397732656ddf48cc77593e
        Author: Ingo Molnar
        Date: Mon Jul 9 18:52:01 2007 +0200

                sched: add CFS credits

                add credits for recent major scheduler contributions:

                    Con Kolivas, for pioneering the fair-scheduling approach
                    Peter Williams, for smpnice
                    Mike Galbraith, for interactivity tuning of CFS
                    Srivatsa Vaddagiri, for group scheduling enhancements

                Signed-off-by: Ingo Molnar

      I don't see much more places, where credit could be documented.

            tglx
  • CFS vs. O(1) (Score:5, Informative)

    by Ingo Molnar (206899) on Tuesday July 10 2007, @11:09PM (#19821707) Homepage

    (disclaimer, i'm the main author of CFS.)

    I'd like to point out that CFS is O(1) too.

    With current PID limits the worst-case depth of the rbtree is ~15 [and O(15) == O(1), so execution time has a clear upper bound]. Even with a theoretical system that can have 4 million tasks running at once (!), the rbtree depth would have a maximum of ~20-21.

    The "O(1) scheduler" that CFS replaces is O(140) [== O(1)] in theory. (in practice the "number of steps" it takes to schedule is much lower than that, on most platforms.)

    So the new scheduler is O(1) too (with a worst-case "number of steps" of 15, if you happen to have 32 thousand tasks running at once(!)), and the main difference is not in the O(1)-ness but in the behavior of the scheduler.

    • Re:CFS vs. O(1) (Score:5, Informative)

      by -Bacon- (75425) on Wednesday July 11 2007, @12:12AM (#19822027)
      Big O notation describes performance as "n" approaches infinity. If you cap n, then of course you cap the execution time, that's the case for most any algorithm. What you're describing still remains O(ln(n)).

      Frankly big O notation isn't a very good way to describe scheduler performance. Execution time under common loads, and maybe an extreme case would be better. Who cares about an O(1) scheduler that always takes 1 second to schedule the next task :)
    • Re:CFS vs. O(1) (Score:4, Informative)

      by Elladan (17598) on Wednesday July 11 2007, @12:16AM (#19822043)
      Ingo,

      This kind of a silly thing to say. I mean, all terminating algorithms on a finite machine are O(1) ultimately.

      For example, your 1 gig machine only has 2^(1024*1024*1024*8) states it can go through to reach an answer, not including disk IO... and as we all know, O(2^[1024*1024*1024*8]) =~ O(10^2585827972) = O(1). :-)
    • Re:CFS vs. O(1) (Score:4, Insightful)

      by SillyPerson (920121) on Wednesday July 11 2007, @12:52AM (#19822195)
      Am I the only person worried that the main author of CFS does not seem to understand big O notation and red-black trees?
    • Re:CFS vs. O(1) (Score:4, Interesting)

      by John Nowak (872479) on Wednesday July 11 2007, @01:17AM (#19822325)
      If it's a red-black tree, it's O(2 ln(N)). The fact that N never gets too big has nothing to do with it. It is... disturbing... to hear this from someone like Ingo. I also have no idea where ~20-21 came from, as the maximum depth at four million is higher than that.
  • by ZeekWatson (188017) on Wednesday July 11 2007, @01:03AM (#19822243)
    Ingo Molnar is the worst kind of loser: an attention whore. His O(1) scheduler turned out to be a piece of crap and Con Kolivas spent a considerable amount of time implementing a better solution: Staircase Deadline (SD). The SD scheduler is a well tested, good performing scheduler and just when you think its going to be merged into Linus' kernel and replace Ingo's O(1) turd (and remove Ingo's name from some "important" files), Igno spends a couple of days reimplementing SD. I guess he wont be getting his name deleted after all!

    This shows the black side of open source. Con developed SD in the open and Igno stole his ideas. It was only after people started pointing out that CFS looked _very_ similar to SD that Igno even admitted that the design was based on Con's SD work.

    The only reason CFS is in the kernel and not SD is politics.
  • Of course.. (Score:5, Funny)

    by Ztream (584474) on Wednesday July 11 2007, @11:17AM (#19826459)
    "Hello. My name is Ingo Molnar. You killed my task. Prepare to die."
    • Re:Improve how? (Score:4, Informative)

      by the_greywolf (311406) on Tuesday July 10 2007, @10:52PM (#19821605) Homepage

      CFS and Con Kolivas' SD both aim to improve interactivity of processes under high load - in particular, the goal was to reduce scheduling latency for applications which have realtime needs - like audio players. Con Kolivas has been maintaining variations no his low-latency Staircase design for several years with precisely that goal in mind.

      On the desktop, it improves latencies for (for example) music players and 3D games, improving performance and elimingating jitter, lag, and general choppiness. Both SD and CFS achieved this under loads as high as 50.

      On the server, it can have several benefits, including improved time-to-network latencies. They both want and need test cases for servers that show no detrimental effects. If you want to help, you can try out CFS on a server and report to Ingo if there are performance or latency issues.

        • by the_greywolf (311406) on Tuesday July 10 2007, @10:58PM (#19821643) Homepage

          Actually, no, Gnome and KDE aren't the troublemakers. It turns out that certain X drivers are poorly written and X preempts processes vying for CPU. CFS helps improve the situation - almost to the point where you don't notice it.

        • by Ingo Molnar (206899) on Wednesday July 11 2007, @12:17AM (#19822051) Homepage

          Seriously? What, the kernel switches to a process, the process checks its environment and figures out that the event it was waiting for hasn't happened yet, and goes back to sleep? I can't believe that a project as mature as the Linux kernel would use a scheduler like that.

          No, CFS does not do that, and that would be quite silly to do indeed :-)

          CFS keeps tasks that woke up in the runqueue, and allows them to run immediately in the typical case - just like the old scheduler did.

          Where CFS differs from the old scheduler is mainly the case when there are more tasks runnable than there are CPUs/cores available. In such cases, on any modern multitasking kernel, the scheduler has to decide which task to run, and in what order and weight to run those tasks, with the goal to provide to the user the happy illusion of multiple, snappy applications running at once.

          The old O(1) scheduler decided the "order and weight" of runnable tasks based on an pretty elaborate set of heuristics. The rules are pretty complex, but it mostly boils down to 'sleepers get more CPU time than runners'.

          (sidenote: CFS is an O(1) scheduler too for all practical purposes, with an upper limit of ~15 algorithmic steps worst-case)

          Now those heuristics worked pretty well for 15 years (those sleep-heuristics were always part of Linux scheduling, the O(1) scheduler i wrote inherited them from the original O(N) scheduler), but good is never good enough in the land of Linux ;-)

          How does CFS work? CFS follows an approach similar to Con Kolivas' SD project: a scheduler core that instead of heuristics uses "fair scheduling" to achieve interactivity. Runnable tasks are scheduled in a painstakingly fair way (and that seemingly simple concept alone is pretty hard to achieve in a general purpose kernel).

          The simplest case is when there are only CPU-intense tasks running. For example, if there are 8 CPU-intense tasks running on the CPU, each task gets exactly 12.5% CPU time. If you watch how much CPU time the tasks get it will be 12.5% long-term too, with no deviations, with no skewing caused by other tasks running inbetween.

          The more complex case is when applications schedule frequently (and that is the case on most desktops and servers), so CFS extends the concept of 'fairness' to sleeping tasks too. CFS accounts not only 'runners', but 'sleepers' too. Tasks that sleep/run frequently are still given their full 'fair share' of the CPU, up to the limit they could have gotten were they not sleeping at all.

          So for example, if you have two tasks on a CPU, one a 100% CPU hog, the other one an application that sleeps/runs 50% of the time - both will get 50% of the CPU in CFS. Under the strict 'runner fairness' approach (which for example SD is following), the 100% CPU hog would get ~66% of CPU time, the sleeper would get ~33% of CPU time.

          To achieve 'sleeper fairness', CFS runs the (ex-)sleeper task sooner, to offset its disadvantage of not hanging around on the CPU all the time. Or in other words: interactive tasks (tasks that sleep often) will get to the CPU with lower latencies. Which is the holy grail of good desktop scheduling :-)

          (granted, CFS does a whole lot more than that, its patch-impact size is 3 times larger than SD. CFS is not a single patch but a series of 50 patches, which also modularize kernel scheduling policy implementation (note, it does not modularize the scheduler itself a'la PlugSched), offer "group scheduling" (nifty thing for containers/virtualization and large systems, written by Srivatsa Vaddagiri of IBM), offer precise CPU usage accounting to /proc (used by CPU/task monitoring tools), and much more. We decided to turn Linux scheduling upside down, which gave me the easy excuse^H^H^H opportunity to extend the scheduler's design a bit more ;-)

          • by TeXMaster (593524) on Wednesday July 11 2007, @01:46AM (#19822459)

            How does CFS work? CFS follows an approach similar to Con Kolivas' SD project:

            Too bad that the NIH syndrome hit Linux Kernel development too, and Ingo Molnar, after blocking all the attempts to merge SD into mainline because "it couldn't be done", uses the same idea, whips out his own scheduler calling it "Completely Fair", and woosh it gets merged (easily, given that Ingo Molnar himself is the maintainer of that part of the kernel).

            Con Kolivas is (obviously and justifiably) disgruntled, to say the least, he stops working on the SD project, and Linux loses an excellent developer because of politics.

            • by Per Abrahamsen (1397) on Wednesday July 11 2007, @04:58AM (#19823249) Homepage
              Well, given that he is the maintainer, Ingo Molnar's code is presumably more maintainable. It happens all the time in free software projects, someone submits a patch, the idea in the patch is good, but the section of the code is important enough that the maintainer must be certain he understands it. Rewriting it is a good way to gain such understanding.

              Back when I was a maintainer, I guess I rewrote half the patches I got. Most submitters are just happy to see the functionality in there, but there was a few people with fragile egos take it as a personal insult That happens, life goes on, and usually the fragile egos grow more robust with time, and learn that developing what amounts to a prototype of the final code is also a valuable contribution.
              • by Ganesh999 (1075569) on Wednesday July 11 2007, @04:43AM (#19823187)
                > Ingo please comment on this because I have read similar stories elsewhere and would like to hear a
                > response.

                I'd understand if Ingo doesn't want to comment on this; it was a painful clash between two competent and strong characters, which expanded to other parties accusing Ingo of elitism and plagiarism.

                For reference, this was archived on kerneltrap.org, and I believe it was covered in an earlier /. article. (Direct link to full KernelTrap article not provided, in the hope of saving the site from a slashdotting).

                For what it's worth, here's the "facts" as I see them :

                1/ It looks as though Ingo *and*Linus* refused Con's original patch on certain grounds which weren't clearly understood/communicated. Ingo, however, stated that in general he was "quite positive about the staircase scheduler." He proceeded to test it and gave Con feedback.

                2/ Con's work was good enough that Ingo about-turned on his earlier, negative stance about fair schedulers and was inspired to go and develop something very similar (but which fitted better with the overall kernel architecture). It's clear that this was predominantly Ingo's own code (hence no plagiarism), and Ingo credits Con in the code comments for coming up with the general approach.

                3/ Somewhere in the middle of the ensuing discussion on lkml there are complaints that Con wasn't kept in the loop. However, Ingo cites examples where he *did* communicate to Con; by Con's own admission he was very ill (hospitalised) during a critical period.

                4/ Parent suggests that Con has since stopped contributing to the kernel. I don't see any indication of this in the kernel thread - in fact Con's post gives every indication that he'll continue to contribute.

                My analysis :

                I put the situation down to an applied case of "standing on the shoulders of giants". It's very rare that anyone creates something completely new, and in large projects this can occasionally generate friction.

                Con was in a susceptible condition when the CFS code was released, had a grumble on the list, but generally acted pretty maturely. Ingo credited Con's contributions wherever feasible, clarified this in discussion, and stayed polite and friendly throughout. End of story.

                What's pretty disgusting is the partisan name-calling that follows in the KernelTrap comments. "Shame on Ingo", "Con is acting like a baby", etc. I hope that this doesn't generate bad feeling between Molnar & Kolivas, because after Con's original complaint on lkml and Ingo's response things seemed to be settled.

                No doubt in future Ingo will take an increased amount of care about vetting other people's code, not promoting his own to the exclusion of others, and crediting other people in his own work (note: I don't claim that he has been lacking in this respect in the past). Con, likewise, will doubtless be mollified when his contributions are more readily recognised as being of merit in future. In the meantime Linus has emphasised that competition between developers is a *good* thing to a reasonable extent, as it directly increases motivation.

                Now, I suggest that everyone else with a ready opinion hold their breath a while, and let all them get on with coding.

                Conrad