Skip to contentSkip to conversation

Modular Scheduler Core and Completely Fair Scheduler [CFS]

PATCH In review Ingo Molnar 76 participants 711 messages Apr 13, 2007 – Jun 30, 2007 10 messages not in the archive Page 1 of 4

Subsystems (11)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Modular Scheduler Core and Completely Fair Scheduler [CFS]

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.

[ QuickStart: apply the patch to v2.6.21-rc6, recompile, reboot. The
new scheduler will be active by default and all tasks will default to the new SCHED_FAIR interactive scheduling class. ]

Highlights are:

- the introduction of Scheduling Classes: an extensible hierarchy of scheduler modules. These modules encapsulate scheduling policy details and are handled by the scheduler core without the core code assuming about them too much.

- sched_fair.c implements the 'CFS desktop scheduler': it is a replacement for the vanilla scheduler's SCHED_OTHER interactivity code.

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!

The CFS patch uses a completely different approach and implementation from RSDL/SD. My goal was to make CFS's interactivity quality exceed that of RSDL/SD, which is a high standard to meet :-) Testing feedback is welcome to decide this one way or another. [ and, in any case, all of SD's logic could be added via a kernel/sched_sd.c module as well, if Con is interested in such an approach. ]

CFS's design is quite radical: it does not use runqueues, it uses a time-ordered rbtree to build a 'timeline' of future task execution, and thus has no 'array switch' artifacts (by which both the vanilla scheduler and RSDL/SD are affected).

CFS uses nanosecond granularity accounting and does not rely on any jiffies or other HZ detail. Thus the CFS scheduler has no notion of 'timeslices' and has no heuristics whatsoever. There is only one central tunable:

/proc/sys/kernel/sched_granularity_ns

which can be used to tune the scheduler from 'desktop' (low latencies) to 'server' (good batching) workloads. It defaults to a setting suitable for desktop workloads. SCHED_BATCH is handled by the CFS scheduler module too.

due to its design, the CFS scheduler is not prone to any of the 'attacks' that exist today against the heuristics of the stock
scheduler: fiftyp.c, thud.c, chew.c, ring-test.c, massive_intr.c all work fine and do not impact interactivity and produce the expected behavior.

the CFS scheduler has a much stronger handling of nice levels and
SCHED_BATCH: both types of workloads should be isolated much more agressively than under the vanilla scheduler.

( another rdetail: due to nanosec accounting and timeline sorting,
sched_yield() support is very simple under CFS, and in fact under CFS sched_yield() behaves much better than under any other scheduler i have tested so far. )

- sched_rt.c implements SCHED_FIFO and SCHED_RR semantics, in a simpler way than the vanilla scheduler does. It uses 100 runqueues (for all 100 RT priority levels, instead of 140 in the vanilla scheduler) and it needs no expired array.

- reworked/sanitized SMP load-balancing: the runqueue-walking assumptions are gone from the load-balancing code now, and iterators of the scheduling modules are used. The balancing code got quite a bit simpler as a result.

the core scheduler got smaller by more than 700 lines:

 kernel/sched.c | 1454 ++++++++++++++++------------------------------------------------
 1 file changed, 372 insertions(+), 1082 deletions(-)

and even adding all the scheduling modules, the total size impact is relatively small:

 18 files changed, 1454 insertions(+), 1133 deletions(-)

most of the increase is due to extensive comments. The kernel size impact is in fact a small negative:

   text    data     bss     dec     hex filename
  23366    4001      24   27391    6aff kernel/sched.o.vanilla
  24159    2705      56   26920    6928 kernel/sched.o.CFS

(this is mainly due to the benefit of getting rid of the expired array and its data structure overhead.)

thanks go to Thomas Gleixner and Arjan van de Ven for review of this patchset.

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

Ingo

#1 lore raw
Quoted 1 line · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

...

Quoted 6 lines

The CFS patch uses a completely different approach and implementation from RSDL/SD. My goal was to make CFS's interactivity quality exceed that of RSDL/SD, which is a high standard to meet :-) Testing feedback is welcome to decide this one way or another. [ and, in any case, all of SD's logic could be added via a kernel/sched_sd.c module as well, if Con is interested in such an approach. ]

Ingo,

Con has been asking for module support for years if I understand your patch corectly. You'll also need this for -rt as well with regards to bandwidth scheduling. Good to see that you're moving in this direction.

bill

#2 lore raw
Quoted 2 lines · Bill Huey

Con has been asking for module support for years if I understand your patch corectly. [...]

Yeah. Note that there are some subtle but crutial differences between PlugSched (which Con used, and which i opposed in the past) and this approach.

PlugSched cuts the interfaces at a high level in a monolithic way and introduces kernel/scheduler.c that uses one pluggable scheduler (represented via the 'scheduler' global template) at a time.

while in this CFS patchset i'm using modularization ('scheduler classes') to simplify the _existing_ multi-policy implementation of the scheduler. These 'scheduler classes' are in a hierarchy and are stacked on top of each other. They are in use at once. Currently there's two of
them: sched_ops_rt is stacked ontop of sched_ops_fair. Fortunately the performance impact is minimal.

So scheduler classes are mainly a simplification of the design of the scheduler - not just a mere facility to select multiple schedulers. Their ability to also facilitate easier experimentation with schedulers is 'just' a happy side-effect. So all in one: it's a fairly different model from PlugSched (and that's why i didnt reuse PlugSched) - but there's indeed overlap.

Quoted 2 lines

[...] You'll also need this for -rt as well with regards to bandwidth scheduling.

yeah.

scheduler classes are also useful for other purposes like containers and virtualization, hierarchical/group scheduling, security encapsulation, etc. - features that can be on-demand layered, and which we dont necessarily want to have enabled all the time.

Quoted 1 line

[...] Good to see that you're moving in this direction.

thanks! :)

Ingo

#3 lore raw
Quoted 6 lines · Ingo Molnar

Yeah. Note that there are some subtle but crutial differences between PlugSched (which Con used, and which i opposed in the past) and this approach.
PlugSched cuts the interfaces at a high level in a monolithic way and introduces kernel/scheduler.c that uses one pluggable scheduler (represented via the 'scheduler' global template) at a time.

What I originally did did so for a good reason, which was that it was intended to support far more radical reorganizations, for instance, things that changed the per-cpu runqueue affairs for gang scheduling. I wrote a top-level driver that did support scheduling classes in a similar fashion, though it didn't survive others maintaining the patches.

-- wli

#4 lore raw
Quoted 8 lines · William Lee Irwin III
Quoted 6 lines · Ingo Molnar

Yeah. Note that there are some subtle but crutial differences between PlugSched (which Con used, and which i opposed in the past) and this approach.
PlugSched cuts the interfaces at a high level in a monolithic way and introduces kernel/scheduler.c that uses one pluggable scheduler (represented via the 'scheduler' global template) at a time.

Quoted 5 lines

What I originally did did so for a good reason, which was that it was intended to support far more radical reorganizations, for instance, things that changed the per-cpu runqueue affairs for gang scheduling. I wrote a top-level driver that did support scheduling classes in a similar fashion, though it didn't survive others maintaining the patches.

Also, gang scheduling is needed to solve virtualization issues regarding spinlocks in a guest image. You could potentally be spinning on a thread that isn't currently running which, needless to say, is very bad.

bill

#5 lore raw
In reply to William Lee Irwin III
Quoted 6 lines · William Lee Irwin III

What I originally did did so for a good reason, which was that it was intended to support far more radical reorganizations, for instance, things that changed the per-cpu runqueue affairs for gang scheduling. I wrote a top-level driver that did support scheduling classes in a similar fashion, though it didn't survive others maintaining the patches.

yeah - i looked at plugsched-6.5-for-2.6.20.patch in particular.

Ingo

#6 lore raw
In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar

and even adding all the scheduling modules, the total size impact is relatively small:

 18 files changed, 1454 insertions(+), 1133 deletions(-)

most of the increase is due to extensive comments. The kernel size impact is in fact a small negative:

   text    data     bss     dec     hex filename
  23366    4001      24   27391    6aff kernel/sched.o.vanilla
  24159    2705      56   26920    6928 kernel/sched.o.CFS

update: these were older numbers, here are the stats redone with the latest patch:

     text    data     bss     dec     hex filename
    23366    4001      24   27391    6aff kernel/sched.o.vanilla
    23671    4548      24   28243    6e53 kernel/sched.o.sd.v40
    23349    2705      24   26078    65de kernel/sched.o.cfs

so CFS is now a win both for text and for data size :)

Ingo

#7 lore raw
In reply to Ingo Molnar

Ingo Molnar napisał(a):

Quoted 7 lines

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

Friday the 13th, my lucky day :).

/mnt/md0/devel/linux-msc-cfs/usr/include/linux/sched.h requires linux/rbtree.h, which does not exist in exported headers

make[3]: *** No rule to make target /mnt/md0/devel/linux-msc-cfs/usr/include/linux/.check.sched.h', needed by __headerscheck'. Stop. make[2]: *** [linux] Error 2
make[1]: *** [headers_check] Error 2
make: *** [vmlinux] Error 2

Regards,
Michal

Signature · 18 lines
Michal K. K. Piotrowski
LTG - Linux Testers Group (PL)
(http://www.stardust.webpages.pl/ltg/)
LTG - Linux Testers Group (EN)
(http://www.stardust.webpages.pl/linux_testers_group_en/)

Signed-off-by: Michal Piotrowski <[email protected]>

--- linux-msc-cfs-clean/include/linux/Kbuild	2007-04-13 23:52:47.000000000 +0200
+++ linux-msc-cfs/include/linux/Kbuild	2007-04-13 23:49:41.000000000 +0200
@@ -133,6 +133,7 @@ header-y += quotaio_v1.h
 header-y += quotaio_v2.h
 header-y += radeonfb.h
 header-y += raw.h
+header-y += rbtree.h
 header-y += resource.h
 header-y += rose.h
 header-y += smbno.h
#8 lore raw
In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.

I'm not in love with the current or other schedulers, so I'm indifferent to this change. However, I was reviewing your release notes and the patch and found myself wonder what the logarithmic complexity of this new scheduler is .. I assumed it would also be constant time , but the __enqueue_task_fair doesn't appear to be constant time (rbtree insert complexity).. Maybe that's not a critical path , but I thought I would at least comment on it.

Daniel

#13 lore raw
In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS] i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:
http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch
This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.
[ QuickStart: apply the patch to v2.6.21-rc6, recompile, reboot. The
new scheduler will be active by default and all tasks will default to the new SCHED_FAIR interactive scheduling class. ]

A pleasant surprise, though I did see it coming.

Quoted 5 lines · Ingo Molnar

Highlights are:
- the introduction of Scheduling Classes: an extensible hierarchy of scheduler modules. These modules encapsulate scheduling policy details and are handled by the scheduler core without the core code assuming about them too much.

It probably needs further clarification that they're things on the order of SCHED_FIFO, SCHED_RR, SCHED_NORMAL, etc.; some prioritization amongst the classes is furthermore assumed, and so on. They're not quite capable of being full-blown alternative policies, though quite a bit can be crammed into them.

There are issues with the per- scheduling class data not being very well-abstracted. A union for per-class data might help, if not a dynamically allocated scheduling class -private structure. Getting an alternative policy floating around that actually clashes a little with the stock data in the task structure would help clarify what's needed.

Quoted 6 lines · Ingo Molnar

- sched_fair.c implements the 'CFS desktop scheduler': it is a replacement for the vanilla scheduler's SCHED_OTHER interactivity code.
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!

Bob Mullens banged out a virtual deadline interactive task scheduler for Multics back in 1976 or thereabouts. ISTR the name Ferranti in connection with deadline task scheduling for UNIX in particular. I've largely seen deadline schedulers as a realtime topic, though. In any event, it's not so radical as to lack a fair number of precedents.

Quoted 10 lines · Ingo Molnar

The CFS patch uses a completely different approach and implementation from RSDL/SD. My goal was to make CFS's interactivity quality exceed that of RSDL/SD, which is a high standard to meet :-) Testing feedback is welcome to decide this one way or another. [ and, in any case, all of SD's logic could be added via a kernel/sched_sd.c module as well, if Con is interested in such an approach. ] CFS's design is quite radical: it does not use runqueues, it uses a time-ordered rbtree to build a 'timeline' of future task execution, and thus has no 'array switch' artifacts (by which both the vanilla scheduler and RSDL/SD are affected).

A binomial heap would likely serve your purposes better than rbtrees. It's faster to have the next item to dequeue at the root of the tree structure rather than a leaf, for one. There are, of course, other priority queue structures (e.g. van Emde Boas) able to exploit the limited precision of the priority key for faster asymptotics, though actual performance is an open question.

Another advantage of heaps is that they support decreasing priorities directly, so that instead of removal and reinsertion, a less invasive movement within the tree is possible. This nets additional constant factor improvements beyond those for the next item to dequeue for the case where a task remains runnable, but is preempted and its priority decreased while it remains runnable.

Quoted 9 lines · Ingo Molnar

CFS uses nanosecond granularity accounting and does not rely on any jiffies or other HZ detail. Thus the CFS scheduler has no notion of 'timeslices' and has no heuristics whatsoever. There is only one central tunable:
/proc/sys/kernel/sched_granularity_ns
which can be used to tune the scheduler from 'desktop' (low latencies) to 'server' (good batching) workloads. It defaults to a setting suitable for desktop workloads. SCHED_BATCH is handled by the CFS scheduler module too.

I like not relying on timeslices. Timeslices ultimately get you into a 2.4.x -like epoch expiry scenarios and introduce a number of RR-esque artifacts therefore.

Quoted 5 lines · Ingo Molnar

due to its design, the CFS scheduler is not prone to any of the 'attacks' that exist today against the heuristics of the stock
scheduler: fiftyp.c, thud.c, chew.c, ring-test.c, massive_intr.c all work fine and do not impact interactivity and produce the expected behavior.

I'm always suspicious of these claims. A moderately formal regression test suite needs to be assembled and the testcases rather seriously cleaned up so they e.g. run for a deterministic period of time, have their parameters passable via command-line options instead of editing and recompiling, don't need Lindenting to be legible, and so on. With that in hand, a battery of regression tests can be run against scheduler modifications to verify their correctness and to detect any disturbance in scheduling semantics they might cause.

A very serious concern is that while a fresh scheduler may pass all these tests, later modifications may later cause failures unnoticed because no one's doing the regression tests and there's no obvious test suite for testing types to latch onto. Another is that the testcases themselves may bitrot if they're not maintainable code.

Quoted 3 lines · Ingo Molnar

the CFS scheduler has a much stronger handling of nice levels and
SCHED_BATCH: both types of workloads should be isolated much more agressively than under the vanilla scheduler.

Speaking of regression tests, let's please at least state intended nice semantics and get a regression test for CPU bandwidth distribution by nice levels going.

Quoted 4 lines · Ingo Molnar

( another rdetail: due to nanosec accounting and timeline sorting,
sched_yield() support is very simple under CFS, and in fact under CFS sched_yield() behaves much better than under any other scheduler i have tested so far. )

And there's another one. sched_yield() semantics need a regression test more transparent than VolanoMark or other macrobenchmarks.

At some point we really need to decide what our sched_yield() is intended to do and get something out there to detect whether it's behaving as intended.

Quoted 4 lines · Ingo Molnar

- reworked/sanitized SMP load-balancing: the runqueue-walking assumptions are gone from the load-balancing code now, and iterators of the scheduling modules are used. The balancing code got quite a bit simpler as a result.

The SMP load balancing class operations strike me as unusual and likely to trip over semantic issues in alternative scheduling classes. Getting some alternative scheduling classes out there to clarify the issues would help here, too.

A more general question here is what you mean by "completely fair;" there doesn't appear to be inter-tgrp, inter-pgrp, inter-session, or inter-user fairness going on, though one might argue those are relatively obscure notions of fairness. Complete fairness arguably precludes static prioritization by nice levels, so there is also that. There is also the issue of what a fair CPU bandwidth distribution between tasks of varying desired in-isolation CPU utilization might be. I suppose my thorniest point is where the demonstration of fairness is as, say, a testcase. Perhaps it's fair now; when will we find out when that fairness has been disturbed?

What these things mean when there are multiple CPU's to schedule across may also be of concern.

I propose the following two testcases:
(1) CPU bandwidth distribution of CPU-bound tasks of varying nice levels Create a number of tasks at varying nice levels. Measure the CPU bandwidth allocated to each.
Success depends on intent: we decide up-front that a given nice level should correspond to a given share of CPU bandwidth. Check to see how far from the intended distribution of CPU bandwidth according to those decided-up-front shares the actual distribution of CPU bandwidth is for the test.

(2) CPU bandwidth distribution of tasks with varying CPU demands Create a number of tasks that would in isolation consume varying %cpu. Measure the CPU bandwidth allocated to each. Success depends on intent here, too. Decide up-front that a given %cpu that would be consumed in isolation should correspond to a given share of CPU bandwidth and check the actual distribution of CPU bandwidth vs. what was intended. Note that the shares need not linearly correspond to the %cpu; various sorts of things related to interactivity will make this nonlinear.

A third testcase for sched_yield() should be brewed up.

These testcases are oblivious to SMP. This will demand that a scheduling policy integrate with load balancing to the extent that load balancing occurs for the sake of distributing CPU bandwidth according to nice level. Some explicit decision should be made regarding that.

-- wli

#9 lore raw
In reply to Daniel Walker
Quoted 6 lines · Daniel Walker

I'm not in love with the current or other schedulers, so I'm indifferent to this change. However, I was reviewing your release notes and the patch and found myself wonder what the logarithmic complexity of this new scheduler is .. I assumed it would also be constant time , but the __enqueue_task_fair doesn't appear to be constant time (rbtree insert complexity).. [...]

i've been worried about that myself and i've done extensive measurements before choosing this implementation. The rbtree turned out to be a quite compact data structure: we get it quite cheaply as part of the task structure cachemisses - which have to be touched anyway. For 1000 tasks it's a loop of ~10 - that's still very fast and bound in practice.

here's a test i did under CFS. Lets take some ridiculous load: 1000 infinite loop tasks running at SCHED_BATCH on a single CPU (all inserted into the same rbtree), and lets run lat_ctx:

neptune:~/l> uptime
22:51:23 up 8 min, 2 users, load average: 713.06, 254.64, 91.51

neptune:~/l> ./lat_ctx -s 0 2
"size=0k ovr=1.61
2 1.41

lets stop the 1000 tasks and only have ~2 tasks in the runqueue:

neptune:~/l> ./lat_ctx -s 0 2

"size=0k ovr=1.70
2 1.16

so the overhead is 0.25 usecs. Considering the load (1000 tasks trash the cache like crazy already), this is more than acceptable.

Ingo

#25 lore raw
In reply to Ingo Molnar

Hi Ingo,

Quoted 1 line · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

(...)

Quoted 4 lines

CFS's design is quite radical: it does not use runqueues, it uses a time-ordered rbtree to build a 'timeline' of future task execution, and thus has no 'array switch' artifacts (by which both the vanilla scheduler and RSDL/SD are affected).

I have a high confidence this will work better : I've been using time-ordered trees in userland projects for several years, and never found anything better. To be honnest, I never understood the concept behind the array switch, but as I never felt brave enough to hack something in this kernel area, I simply preferred to shut up (not enough knowledge and not enough time).

However, I have been using a very fast struct timeval-ordered RADIX tree. I found generic rbtree code to generally be slower, certainly because of the call to a function with arguments on every node. Both trees are O(log(n)), the rbtree being balanced and the radix tree being unbalanced. If you're interested, I can try to see how that would fit (but not this week-end).

Also, I had spent much time in the past doing paper work on how to improve fairness between interactive tasks and batch tasks. I came up with the conclusion that for perfectness, tasks should not be ordered by their expected wakeup time, but by their expected completion time, which automatically takes account of their allocated and used timeslice. It would also allow both types of workloads to share equal CPU time with better responsiveness for the most interactive one through the reallocation of a "credit" for the tasks which have not consumed all of their timeslices. I remember we had discussed this with Mike about one year ago when he fixed lots of problems in mainline scheduler. The downside is that I never found how to make this algo fit in O(log(n)). I always ended in something like O(n.log(n)) IIRC.

But maybe this is overkill for real life anyway. Given that a basic two arrays switch (which I never understood) was sufficient for many people, probably that a basic tree will be an order of magnitude better.

Quoted 11 lines

CFS uses nanosecond granularity accounting and does not rely on any jiffies or other HZ detail. Thus the CFS scheduler has no notion of 'timeslices' and has no heuristics whatsoever. There is only one central tunable:

/proc/sys/kernel/sched_granularity_ns

which can be used to tune the scheduler from 'desktop' (low latencies) to 'server' (good batching) workloads. It defaults to a setting suitable for desktop workloads. SCHED_BATCH is handled by the CFS scheduler module too.

I find this useful, but to be fair with Mike and Con, they both have proposed similar tuning knobs in the past and you said you did not want to add that complexity for admins. People can sometimes be demotivated by seeing their proposals finally used by people who first rejected them. And since both Mike and Con both have done a wonderful job in that area, we need their experience and continued active participation more than ever.

Quoted 5 lines

due to its design, the CFS scheduler is not prone to any of the 'attacks' that exist today against the heuristics of the stock
scheduler: fiftyp.c, thud.c, chew.c, ring-test.c, massive_intr.c all work fine and do not impact interactivity and produce the expected behavior.

I'm very pleased to read this. Because as I have already said it, my major concern with 2.6 was the stock scheduler. Recently, RSDL fixed most of the basic problems for me to the point that I switched the default lilo entry on my notebook to 2.6 ! I hope that whatever the next scheduler will be, we'll definitely get rid of any heuristics. Heuristics are good in 95% of situations and extremely bad in the remaining 5%. I prefer something reasonably good in 100% of situations.

Quoted 14 lines

the CFS scheduler has a much stronger handling of nice levels and
SCHED_BATCH: both types of workloads should be isolated much more agressively than under the vanilla scheduler.

( another rdetail: due to nanosec accounting and timeline sorting,
sched_yield() support is very simple under CFS, and in fact under CFS sched_yield() behaves much better than under any other scheduler i have tested so far. )

- sched_rt.c implements SCHED_FIFO and SCHED_RR semantics, in a simpler way than the vanilla scheduler does. It uses 100 runqueues (for all 100 RT priority levels, instead of 140 in the vanilla scheduler) and it needs no expired array.

Quoted 4 lines

- reworked/sanitized SMP load-balancing: the runqueue-walking assumptions are gone from the load-balancing code now, and iterators of the scheduling modules are used. The balancing code got quite a bit simpler as a result.

Will this have any impact on NUMA/HT/multi-core/etc... ?

Quoted 1 line

the core scheduler got smaller by more than 700 lines:

Well done !

Cheers,
Willy

#10 lore raw
In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar
Quoted 6 lines · Daniel Walker

I'm not in love with the current or other schedulers, so I'm indifferent to this change. However, I was reviewing your release notes and the patch and found myself wonder what the logarithmic complexity of this new scheduler is .. I assumed it would also be constant time , but the __enqueue_task_fair doesn't appear to be constant time (rbtree insert complexity).. [...]

Quoted 5 lines

i've been worried about that myself and i've done extensive measurements before choosing this implementation. The rbtree turned out to be a quite compact data structure: we get it quite cheaply as part of the task structure cachemisses - which have to be touched anyway. For 1000 tasks it's a loop of ~10 - that's still very fast and bound in practice.

I'm not worried at all by O(log(n)) algorithms, and generally prefer smart log(n) than dumb O(1).

In a userland TCP stack I started to write 2 years ago, I used a comparable scheduler and could reach a sustained rate of 145000 connections/s at 4 millions of concurrent connections. And yes, each time a packet was sent or received, a task was queued/dequeued (so about 450k/s with 4 million tasks, on an athlon 1.5 GHz). So that seems much higher than what we currently need.

Regards,
Willy

#14 lore raw
In reply to William Lee Irwin III
Quoted 13 lines · William Lee Irwin III
Quoted 11 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS] i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:
http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch
This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.
[ QuickStart: apply the patch to v2.6.21-rc6, recompile, reboot. The
new scheduler will be active by default and all tasks will default to the new SCHED_FAIR interactive scheduling class. ]

Quoted 1 line

A pleasant surprise, though I did see it coming.

hey ;)

Quoted 10 lines · Ingo Molnar
Quoted 5 lines

Highlights are:
- the introduction of Scheduling Classes: an extensible hierarchy of scheduler modules. These modules encapsulate scheduling policy details and are handled by the scheduler core without the core code assuming about them too much.

It probably needs further clarification that they're things on the order of SCHED_FIFO, SCHED_RR, SCHED_NORMAL, etc.; some prioritization amongst the classes is furthermore assumed, and so on. [...]

yep - they are linked via sched_ops->next pointer, with NULL delimiting the last one.

Quoted 2 lines

[...] They're not quite capable of being full-blown alternative policies, though quite a bit can be crammed into them.

yeah, they are not full-blown: i extended them on-demand, for the specific purposes of sched_fair.c and sched_rt.c. More can be done too.

Quoted 2 lines

There are issues with the per- scheduling class data not being very well-abstracted. [...]

yes. It's on my TODO list: i'll work more on extending the cleanups to those fields too.

Quoted 6 lines

A binomial heap would likely serve your purposes better than rbtrees. It's faster to have the next item to dequeue at the root of the tree structure rather than a leaf, for one. There are, of course, other priority queue structures (e.g. van Emde Boas) able to exploit the limited precision of the priority key for faster asymptotics, though actual performance is an open question.

i'm caching the leftmost leaf, which serves as an alternate, task-pick centric root in essence.

Quoted 6 lines

Another advantage of heaps is that they support decreasing priorities directly, so that instead of removal and reinsertion, a less invasive movement within the tree is possible. This nets additional constant factor improvements beyond those for the next item to dequeue for the case where a task remains runnable, but is preempted and its priority decreased while it remains runnable.

yeah. (Note that in CFS i'm not decreasing priorities anywhere though - all the priority levels in CFS stay constant, fairness is not achieved via rotating priorities or similar, it is achieved via the accounting code.)

Quoted 8 lines · Ingo Molnar
Quoted 5 lines

due to its design, the CFS scheduler is not prone to any of the 'attacks' that exist today against the heuristics of the stock
scheduler: fiftyp.c, thud.c, chew.c, ring-test.c, massive_intr.c all work fine and do not impact interactivity and produce the expected behavior.

I'm always suspicious of these claims. [...]

hey, sure - but please give it a go nevertheless, i _did_ test all these ;)

Quoted 1 line

A moderately formal regression test suite needs to be assembled [...]

by all means feel free! ;)

Quoted 1 line

A more general question here is what you mean by "completely fair;"

by that i mean the most common-sense definition: with N tasks running each gets 1/N CPU time if observed for a reasonable amount of time. Now extend this to arbitrary scheduling patterns, the end result should still be completely fair, according to the fundamental 1/N(time) rule individually applied to all the small scheduling patterns that the scheduling patterns give. (this assumes that the scheduling patterns are reasonably independent of each other - if they are not then there's no reasonable definition of fairness that makes sense, and we might as well use the 1/N rule for those cases too.)

Quoted 3 lines

there doesn't appear to be inter-tgrp, inter-pgrp, inter-session, or inter-user fairness going on, though one might argue those are relatively obscure notions of fairness. [...]

sure, i mainly concentrated on what we have in Linux today. The things you mention are add-ons that i can see handling via new scheduling
classes: all the CKRM and containers type of CPU time management facilities.

Quoted 2 lines

What these things mean when there are multiple CPU's to schedule across may also be of concern.

that is handled by the existing smp-nice load balancer, that logic is preserved under CFS.

Quoted 5 lines

These testcases are oblivious to SMP. This will demand that a scheduling policy integrate with load balancing to the extent that load balancing occurs for the sake of distributing CPU bandwidth according to nice level. Some explicit decision should be made regarding that.

this should already work reasonably fine with CFS: try massive_intr.c on an SMP box.

Ingo

#28 lore raw
In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

[...]

Quoted 3 lines

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

Compile error here.

...

CC kernel/sched.o
kernel/sched.c: In function '__rq_clock':
kernel/sched.c:219: error: 'struct rq' has no member named 'cpu' kernel/sched.c:219: warning: type defaults to 'int' in declaration of '__ret_warn_once' kernel/sched.c:219: error: 'struct rq' has no member named 'cpu' kernel/sched.c: In function 'rq_clock':
kernel/sched.c:230: error: 'struct rq' has no member named 'cpu' kernel/sched.c: In function 'sched_init':
kernel/sched.c:6013: warning: unused variable 'j'
make[1]: *** [kernel/sched.o] Error 1
make: *** [kernel] Error 2
==> ERROR: Build Failed. Aborting...

...

There the config :

http://frugalware.org/~crazy/other/kernel/config

Quoted 4 lines

Ingo
-

Regards,

Gabriel

#26 lore raw
In reply to Willy Tarreau
Quoted 4 lines · Willy Tarreau
Quoted 4 lines

central tunable:

/proc/sys/kernel/sched_granularity_ns

Quoted 8 lines
Quoted 4 lines

which can be used to tune the scheduler from 'desktop' (low latencies) to 'server' (good batching) workloads. It defaults to a setting suitable for desktop workloads. SCHED_BATCH is handled by the CFS scheduler module too.

I find this useful, but to be fair with Mike and Con, they both have proposed similar tuning knobs in the past and you said you did not want to add that complexity for admins. [...]

yeah. [ Note that what i opposed in the past was mostly the 'export all the zillion of sched.c knobs to /sys and let people mess with them' kind of patches which did exist and still exist. A _single_ knob, which represents basically the totality of parameters within sched_fair.c is less of a problem. I dont think i ever objected to this knob within staircase/SD. (If i did then i was dead wrong.) ]

Quoted 4 lines

[...] People can sometimes be demotivated by seeing their proposals finally used by people who first rejected them. And since both Mike and Con both have done a wonderful job in that area, we need their experience and continued active participation more than ever.

very much so! Both Con and Mike has contributed regularly to upstream sched.c:

 $ git-log kernel/sched.c | grep 'by: Con Kolivas' 1 | wc -l
 19
 $ git-log kernel/sched.c | grep 'by: Mike' | wc -l
 6

and i'd very much like both counts to increase steadily in the future too :)

Quoted 6 lines
Quoted 4 lines

- reworked/sanitized SMP load-balancing: the runqueue-walking assumptions are gone from the load-balancing code now, and iterators of the scheduling modules are used. The balancing code got quite a bit simpler as a result.

Will this have any impact on NUMA/HT/multi-core/etc... ?

it will inevitably have some sort of effect - and if it's negative, i'll try to fix it.

I got rid of the explicit cache-hot tracking code and replaced it with a more natural pure 'pick the next-to-run task first, that is likely the most cache-cold one' logic. That just derives naturally from the rbtree approach.

Quoted 3 lines
Quoted 1 line

the core scheduler got smaller by more than 700 lines:

Well done !

thanks :)

Ingo

#29 lore raw
In reply to Gabriel C
Quoted 4 lines · Gabriel C
Quoted 2 lines

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

Compile error here.

ah, !CONFIG_SMP. Does the patch below do the trick for you? (I've also updated the full patch at the cfs-scheduler URL)

Ingo

----------------------->
From: Ingo Molnar <[email protected]>
Subject: [cfs] fix !CONFIG_SMP build

fix the !CONFIG_SMP build error reported by Gabriel C

kernel/sched.c +10 -10
Index: linux/kernel/sched.c
===================================================================
@@ -257,16 +257,6 @@ static inline unsigned long long __rq_cl
 	return rq->rq_clock;
 }
 
-static inline unsigned long long rq_clock(struct rq *rq)
-{
-	int this_cpu = smp_processor_id();
-
-	if (this_cpu == rq->cpu)
-		return __rq_clock(rq);
-
-	return rq->rq_clock;
-}
-
 static inline int cpu_of(struct rq *rq)
 {
 #ifdef CONFIG_SMP
@@ -276,6 +266,16 @@ static inline int cpu_of(struct rq *rq)
 #endif
 }
 
+static inline unsigned long long rq_clock(struct rq *rq)
+{
+	int this_cpu = smp_processor_id();
+
+	if (this_cpu == cpu_of(rq))
+		return __rq_clock(rq);
+
+	return rq->rq_clock;
+}
+
 /*
  * The domain tree (rq->sd) is protected by RCU's quiescent state transition.
  * See detach_destroy_domains: synchronize_sched for details.
#15 lore raw
In reply to Ingo Molnar
Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

A binomial heap would likely serve your purposes better than rbtrees. It's faster to have the next item to dequeue at the root of the tree structure rather than a leaf, for one. There are, of course, other priority queue structures (e.g. van Emde Boas) able to exploit the limited precision of the priority key for faster asymptotics, though actual performance is an open question.

Quoted 2 lines · Ingo Molnar

i'm caching the leftmost leaf, which serves as an alternate, task-pick centric root in essence.

I noticed that, yes. It seemed a better idea to me to use a data structure that has what's needed built-in, but I suppose it's not gospel.

Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

Another advantage of heaps is that they support decreasing priorities directly, so that instead of removal and reinsertion, a less invasive movement within the tree is possible. This nets additional constant factor improvements beyond those for the next item to dequeue for the case where a task remains runnable, but is preempted and its priority decreased while it remains runnable.

Quoted 4 lines · Ingo Molnar

yeah. (Note that in CFS i'm not decreasing priorities anywhere though - all the priority levels in CFS stay constant, fairness is not achieved via rotating priorities or similar, it is achieved via the accounting code.)

Sorry, "priority" here would be from the POV of the queue data structure. From the POV of the scheduler it would be resetting the deadline or whatever the nomenclature cooked up for things is, most obviously in requeue_task_fair() and task_tick_fair().

Quoted 1 line · William Lee Irwin III
Quoted 1 line

I'm always suspicious of these claims. [...]

Quoted 2 lines · Ingo Molnar

hey, sure - but please give it a go nevertheless, i _did_ test all these ;)

The suspicion essentially centers around how long the state of affairs will hold up because comprehensive re-testing is not noticeably done upon updates to scheduling code or kernel point releases.

Quoted 1 line · William Lee Irwin III
Quoted 1 line

A moderately formal regression test suite needs to be assembled [...]

Quoted 1 line · Ingo Molnar

by all means feel free! ;)

I can only do so much, but I have done work to clean up other testcases going around. I'm mostly looking at testcases as I go over them or develop some interest in the subject and rewriting those that already exist or hammering out new ones as I need them. The main contribution toward this is that I've sort of made a mental note to stash the results of the effort somewhere and pass them along to those who do regular testing on kernels or otherwise import test suites into their collections.

Quoted 1 line · William Lee Irwin III
Quoted 1 line

A more general question here is what you mean by "completely fair;"

Quoted 9 lines · Ingo Molnar

by that i mean the most common-sense definition: with N tasks running each gets 1/N CPU time if observed for a reasonable amount of time. Now extend this to arbitrary scheduling patterns, the end result should still be completely fair, according to the fundamental 1/N(time) rule individually applied to all the small scheduling patterns that the scheduling patterns give. (this assumes that the scheduling patterns are reasonably independent of each other - if they are not then there's no reasonable definition of fairness that makes sense, and we might as well use the 1/N rule for those cases too.)

I'd start with identically-behaving CPU-bound tasks here. It's easy enough to hammer out a testcase that starts up N CPU-bound tasks, runs them for a few minutes, stops them, collects statistics on their runtime, and gives us an idea of whether 1/N came out properly. I'll get around to that at some point.

Where it gets complex is when the behavior patterns vary, e.g. they're not entirely CPU-bound and their desired in-isolation CPU utilization varies, or when nice levels vary, or both vary. I went on about testcases for those in particular in the prior post, though not both at once. The nice level one in particular needs an up-front goal for distribution of CPU bandwidth in a mixture of competing tasks with varying nice levels.

There are different ways to define fairness, but a uniform distribution of CPU bandwidth across a set of identical competing tasks is a good, testable definition.

Quoted 3 lines · William Lee Irwin III
Quoted 3 lines

there doesn't appear to be inter-tgrp, inter-pgrp, inter-session, or inter-user fairness going on, though one might argue those are relatively obscure notions of fairness. [...]

Quoted 4 lines · Ingo Molnar

sure, i mainly concentrated on what we have in Linux today. The things you mention are add-ons that i can see handling via new scheduling
classes: all the CKRM and containers type of CPU time management facilities.

At some point the CKRM and container people should be pinged to see what (if anything) they need to achieve these sorts of things. It's not clear to me that the specific cases I cited are considered relevant to anyone. I presume that if they are, someone will pipe up with a feature request. It was more a sort of catalogue of different notions of fairness that could arise than any sort of suggestion.

Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

What these things mean when there are multiple CPU's to schedule across may also be of concern.

Quoted 2 lines · Ingo Molnar

that is handled by the existing smp-nice load balancer, that logic is preserved under CFS.

Given the things going wrong, I'm curious as to whether that works, and if so, how well. I'll drop that into my list of testcases that should be arranged for, though I won't guarantee that I'll get to it myself in any sort of timely fashion.

What this ultimately needs is specifying the semantics of nice levels so that we can say that a mixture of competing tasks with varying nice levels should have an ideal distribution of CPU bandwidth to check for.

Quoted 5 lines · William Lee Irwin III
Quoted 5 lines

These testcases are oblivious to SMP. This will demand that a scheduling policy integrate with load balancing to the extent that load balancing occurs for the sake of distributing CPU bandwidth according to nice level. Some explicit decision should be made regarding that.

Quoted 2 lines · Ingo Molnar

this should already work reasonably fine with CFS: try massive_intr.c on an SMP box.

Where is massive_intr.c, BTW?

-- wli

#30 lore raw
In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar
Quoted 4 lines · Gabriel C
Quoted 2 lines

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

Compile error here.

ah, !CONFIG_SMP. Does the patch below do the trick for you? (I've also updated the full patch at the cfs-scheduler URL)

Yes it does , thx :) , only the " warning: unused variable 'j' " left.

Quoted 2 lines

Ingo

Regards,

Gabriel

#16 lore raw
In reply to William Lee Irwin III
Quoted 3 lines · William Lee Irwin III

Where it gets complex is when the behavior patterns vary, e.g. they're not entirely CPU-bound and their desired in-isolation CPU utilization varies, or when nice levels vary, or both vary. [...]

yes. I tested things like 'massive_intr.c' (attached, written by Satoru Takeuchi) which starts N tasks which each work for 8msec then sleep 1msec:

from its output, the second column is the CPU time each thread got, the more even, the fairer the scheduling. On vanilla i get:

mercury:~> ./massive_intr 10 10

 024873  00000150
 024874  00000123
 024870  00000069
 024868  00000068
 024866  00000051
 024875  00000206
 024872  00000093
 024869  00000138
 024867  00000078
 024871  00000223

on CFS i get:

neptune:~> ./massive_intr 10 10

 002266  00000112
 002260  00000113
 002261  00000112
 002267  00000112
 002269  00000112
 002265  00000112
 002262  00000113
 002268  00000113
 002264  00000112
 002263  00000113

so it is quite a bit more even ;)

another related test-utility is one i wrote:

http://people.redhat.com/mingo/scheduler-patches/ring-test.c

this is a ring of 100 tasks each doing work for 100 msecs and then sleeping for 1 msec. I usually test this by also running a CPU hog in parallel to it, and checking whether it gets ~50.0% of CPU time under CFS. (it does)

Ingo

#if 0

Hi Ingo and all,

When I was executing massive interactive processes, I found that some of them occupy CPU time and the others hardly run.

It seems that some of processes which occupy CPU time always has max effective prio (default+5) and the others have max - 1. What happen here is...

1. If there are moderate number of max interactive processes, they can be re-inserted into active queue without falling down its priority again and again.
2. In this case, the others seldom run, and can't get max effective priority at next exhausting because scheduler considers them to sleep too long.
3. Goto 1, OOPS!

Unfortunately I haven't been able to make the patch resolving this problem yet. Any idea?

I also attach the test program which easily recreates this problem.

Test program flow:

1. First process starts child proesses and wait for 5 minutes.
2. Each child process executes "work 8 msec and sleep 1 msec" loop continuously.
3. After 3 minits have passed, each child processes prints the # of loops which executed.

What expected:

Each child processes execute nearly equal # of loops.

Test environment:

- kernel: 2.6.20(*1)
- # of CPUs: 1 or 2
- # of child processes: 200 or 400
- nice value: 0 or 20(*2)

*1) I confirmed that 2.6.21-rc5 has no change regarding this problem. *2) If a process have nice 20, scheduler never regards it as interactive.

Test results:

-----------+----------------+------+------------------------------------

 # of CPUs | # of processes | nice |              result
-----------+----------------+------+------------------------------------
           |                |   20 | looks good
   1(i386) |                +------+------------------------------------
           |                |    0 | 4 processes occupy 98% of CPU time
-----------+            200 +------+------------------------------------
           |                |   20 | looks good
           |                +------+------------------------------------
           |                |    0 | 8 processes occupy 72% of CPU time
   2(ia64) +----------------+------+------------------------------------
           |            400 |   20 | looks good
           |                +------+------------------------------------
           |                |    0 | 8 processes occupy 98% of CPU time
-----------+----------------+------+------------------------------------

FYI. 2.6.21-rc3-mm1 (enabling RSDL scheduler) works fine in the all casees :-)

Thanks,

Satoru

-------------------------------------------------------------------------------
#endif
/*
* massive_intr - run @nproc interactive processes and print the number of
* loops(*1) each process executes in @runtime secs.
*
* *1) "work 8 msec and sleep 1msec" loop
*
* Usage: massive_intr <nproc> <runtime>
*
* @nproc: number of processes
* @runtime: execute time[sec]
*
* ex) If you want to run 300 processes for 5 mins, issue the
* command as follows:
*
* $ massive_intr 300 300
*
* How to build:
*
* cc -o massive_intr massive_intr.c -lrt
*
*
* Copyright (C) 2007 Satoru Takeuchi <[email protected]> *
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *

 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or (at
 *  your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <semaphore.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <errno.h>
#include <err.h>

#define WORK_MSECS 8
#define SLEEP_MSECS 1

#define MAX_PROC 1024
#define SAMPLE_COUNT 1000000000
#define USECS_PER_SEC 1000000
#define USECS_PER_MSEC 1000
#define NSECS_PER_MSEC 1000000
#define SHMEMSIZE 4096

static const char *shmname = "/sched_interactive_shmem"; static void *shmem;
static sem_t *printsem;
static int nproc;
static int runtime;
static int fd;
static time_t *first;
static pid_t pid[MAX_PROC];
static int return_code;

static void cleanup_resources(void)

{
	if (sem_destroy(printsem) < 0)
		warn("sem_destroy() failed");
	if (munmap(shmem, SHMEMSIZE) < 0)
		warn("munmap() failed");
	if (close(fd) < 0)
		warn("close() failed");
}	

static void abnormal_exit(void)

{
	if (kill(getppid(), SIGUSR2) < 0)
		err(EXIT_FAILURE, "kill() failed");
}

static void sighandler(int signo)
{
}

static void sighandler2(int signo)

{
	return_code = EXIT_FAILURE;
}

static void loopfnc(int nloop)

{
	int i;
	for (i = 0; i < nloop; i++)
		;
}

static int loop_per_msec(void)

{
	struct timeval tv[2];
	int before, after;

	if (gettimeofday(&tv[0], NULL) < 0)
		return -1;
	loopfnc(SAMPLE_COUNT);
	if (gettimeofday(&tv[1], NULL) < 0)
		return -1;
	before = tv[0].tv_sec*USECS_PER_SEC+tv[0].tv_usec;
	after = tv[1].tv_sec*USECS_PER_SEC+tv[1].tv_usec;

	return SAMPLE_COUNT/(after - before)*USECS_PER_MSEC;
}

static void *test_job(void *arg)

{
	int l = (int)arg;
	int count = 0;
	time_t current;
	sigset_t sigset;
	struct sigaction sa;
	struct timespec ts = { 0, NSECS_PER_MSEC*SLEEP_MSECS};

	sa.sa_handler = sighandler;
	if (sigemptyset(&sa.sa_mask) < 0) {
		warn("sigemptyset() failed");
		abnormal_exit();
	}
	sa.sa_flags = 0;
	if (sigaction(SIGUSR1, &sa, NULL) < 0) {
		warn("sigaction() failed");
		abnormal_exit();
	}
	if (sigemptyset(&sigset) < 0) {
		warn("sigfillset() failed");
		abnormal_exit();
	}
	sigsuspend(&sigset);
	if (errno != EINTR) {
		warn("sigsuspend() failed");
		abnormal_exit();
	}
	/* main loop */
	do {
		loopfnc(WORK_MSECS*l);
		if (nanosleep(&ts, NULL) < 0) {
			warn("nanosleep() failed");
			abnormal_exit();
		}
		count++;
		if (time(&current) == -1) {
			warn("time() failed");
			abnormal_exit();
		}
	} while (difftime(current, *first) < runtime);

	if (sem_wait(printsem) < 0) {
		warn("sem_wait() failed");
		abnormal_exit();
	}
	printf("%06d\t%08d\n", getpid(), count);
	if (sem_post(printsem) < 0) {
		warn("sem_post() failed");
		abnormal_exit();
	}
	exit(EXIT_SUCCESS);
}

static void usage(void)

{
	fprintf(stderr,
		"Usage : massive_intr <nproc> <runtime>\n"
		"\t\tnproc  : number of processes\n"
		"\t\truntime   : execute time[sec]\n");
	exit(EXIT_FAILURE);
}

int main(int argc, char **argv)

{
	int i, j;
	int status;
	sigset_t sigset;
	struct sigaction sa;
	int c;

	if (argc != 3)
		usage();

	nproc = strtol(argv[1], NULL, 10);
	if (errno || nproc < 1 || nproc > MAX_PROC)
		err(EXIT_FAILURE, "invalid multinum");
	runtime = strtol(argv[2], NULL, 10);
	if (errno || runtime <= 0)
		err(EXIT_FAILURE, "invalid runtime");

	sa.sa_handler = sighandler2;
	if (sigemptyset(&sa.sa_mask) < 0)
		err(EXIT_FAILURE, "sigemptyset() failed");
	sa.sa_flags = 0;
	if (sigaction(SIGUSR2, &sa, NULL) < 0)
		err(EXIT_FAILURE, "sigaction() failed");
	if (sigemptyset(&sigset) < 0)
		err(EXIT_FAILURE, "sigemptyset() failed");
	if (sigaddset(&sigset, SIGUSR1) < 0)
		err(EXIT_FAILURE, "sigaddset() failed");
	if (sigaddset(&sigset, SIGUSR2) < 0)
		err(EXIT_FAILURE, "sigaddset() failed");
	if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0)
		err(EXIT_FAILURE, "sigprocmask() failed");

	/* setup shared memory */
	if ((fd = shm_open(shmname, O_CREAT | O_RDWR, 0644)) < 0)
		err(EXIT_FAILURE, "shm_open() failed");
	if (shm_unlink(shmname) < 0) {
		warn("shm_unlink() failed");
		goto err_close;
	}
	if (ftruncate(fd, SHMEMSIZE) < 0) {
		warn("ftruncate() failed");
		goto err_close;
	}
	shmem = mmap(NULL, SHMEMSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if (shmem == (void *)-1) {
		warn("mmap() failed");
		goto err_unmap;
	}
	printsem = shmem;
	first = shmem + sizeof(*printsem);
	
	/* initialize semaphore */
	if ((sem_init(printsem, 1, 1)) < 0) {
		warn("sem_init() failed");
		goto err_unmap;
	}

	if ((c = loop_per_msec()) < 0) {
		fprintf(stderr, "loop_per_msec() failed\n");
		goto err_sem;
	}

	for (i = 0; i < nproc; i++) {
		pid[i] = fork();
		if (pid[i] == -1) {
			warn("fork() failed\n");
			for (j = 0; j < i; j++)
				if (kill(pid[j], SIGKILL) < 0)
					warn("kill() failed");
			goto err_sem;
		}
		if (pid[i] == 0)
			test_job((void *)c);
	}

	if (sigemptyset(&sigset) < 0) {
		warn("sigemptyset() failed");
		goto err_proc;
	}
	if (sigaddset(&sigset, SIGUSR2) < 0) {
		warn("sigaddset() failed");
		goto err_proc;
	}
	if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) < 0) {
		warn("sigprocmask() failed");
		goto err_proc;
	}
	if (time(first) < 0) {
		warn("time() failed");
		goto err_proc;
	}
	if ((kill(0, SIGUSR1)) == -1) {
		warn("kill() failed");
		goto err_proc;
	}
	for (i = 0; i < nproc; i++) {
		if (wait(&status) < 0) {
			warn("wait() failed");
			goto err_proc;
		}
	}
	cleanup_resources();
	exit(return_code);
 err_proc:
	for (i = 0; i < nproc; i++)
		if (kill(pid[i], SIGKILL) < 0)
			if (errno != ESRCH)
				warn("kill() failed");
 err_sem:
	if (sem_destroy(printsem) < 0)
		warn("sem_destroy() failed");
 err_unmap:
	if (munmap(shmem, SHMEMSIZE) < 0)
		warn("munmap() failed");
 err_close:
	if (close(fd) < 0)
		warn("close() failed");	
	exit(EXIT_FAILURE);
}
#17 lore raw
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines

Where it gets complex is when the behavior patterns vary, e.g. they're not entirely CPU-bound and their desired in-isolation CPU utilization varies, or when nice levels vary, or both vary. [...]

Quoted 3 lines · Ingo Molnar

yes. I tested things like 'massive_intr.c' (attached, written by Satoru Takeuchi) which starts N tasks which each work for 8msec then sleep 1msec:

[...]

Quoted 6 lines

another related test-utility is one i wrote:
http://people.redhat.com/mingo/scheduler-patches/ring-test.c
this is a ring of 100 tasks each doing work for 100 msecs and then sleeping for 1 msec. I usually test this by also running a CPU hog in parallel to it, and checking whether it gets ~50.0% of CPU time under CFS. (it does)

These are both tremendously useful. The code is also in rather good shape so only minimal modifications (for massive_intr.c I'm not even sure if any are needed at all) are needed to plug them into the test harness I'm aware of. I'll queue them both for me to adjust and send over to testers I don't want to burden with hacking on testcases I myself am asking them to add to their suites.

-- wli

#31 lore raw
In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

Always good to see another contender ;)

Quoted 9 lines

This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.

[ QuickStart: apply the patch to v2.6.21-rc6, recompile, reboot. The
new scheduler will be active by default and all tasks will default to the new SCHED_FAIR interactive scheduling class. ]

I don't know why there is such noise about fairness right now... I thought fairness was one of the fundamental properties of a good CPU scheduler, and my scheduler definitely always aims for that above most other things. Why not just keep SCHED_OTHER?

Quoted 6 lines

Highlights are:

- the introduction of Scheduling Classes: an extensible hierarchy of scheduler modules. These modules encapsulate scheduling policy details and are handled by the scheduler core without the core code assuming about them too much.

Don't really like this, but anyway...

Quoted 7 lines

- sched_fair.c implements the 'CFS desktop scheduler': it is a replacement for the vanilla scheduler's SCHED_OTHER interactivity code.

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!

I guess the 2.4 and earlier scheduler kind of did that as well.

Quoted 6 lines

The CFS patch uses a completely different approach and implementation from RSDL/SD. My goal was to make CFS's interactivity quality exceed that of RSDL/SD, which is a high standard to meet :-) Testing feedback is welcome to decide this one way or another. [ and, in any case, all of SD's logic could be added via a kernel/sched_sd.c module as well, if Con is interested in such an approach. ]

Comment about the code: shouldn't you be requeueing the task in the rbtree wherever you change wait_runtime? eg. task_new_fair? (I've only had a quick look so far).

Quoted 8 lines

CFS's design is quite radical: it does not use runqueues, it uses a time-ordered rbtree to build a 'timeline' of future task execution, and thus has no 'array switch' artifacts (by which both the vanilla scheduler and RSDL/SD are affected).

CFS uses nanosecond granularity accounting and does not rely on any jiffies or other HZ detail. Thus the CFS scheduler has no notion of 'timeslices' and has no heuristics whatsoever.

Well, I guess there is still some mechanism to decide which process is most eligible to run? ;) Considering that question has no "right" answer for SCHED_OTHER scheduling, I guess you could say it has heuristics. But granted they are obviously fairly elegant in contrast to the O(1) scheduler ;)

Quoted 4 lines

There is only one
central tunable:

/proc/sys/kernel/sched_granularity_ns

Suppose you have 2 CPU hogs running, is sched_granularity_ns the frequency at which they will context switch?

Quoted 4 lines

( another rdetail: due to nanosec accounting and timeline sorting,
sched_yield() support is very simple under CFS, and in fact under CFS sched_yield() behaves much better than under any other scheduler i have tested so far. )

What is better behaviour for sched_yield?

Thanks,
Nick

#32 lore raw
Quoted 9 lines · Nick Piggin
Quoted 6 lines

The CFS patch uses a completely different approach and implementation from RSDL/SD. My goal was to make CFS's interactivity quality exceed that of RSDL/SD, which is a high standard to meet :-) Testing feedback is welcome to decide this one way or another. [ and, in any case, all of SD's logic could be added via a kernel/sched_sd.c module as well, if Con is interested in such an approach. ]

Comment about the code: shouldn't you be requeueing the task in the rbtree wherever you change wait_runtime? eg. task_new_fair? [...]

yes: the task's position within the rbtree is updated every time wherever wait_runtime is change. task_new_fair is the method during new task creation, but indeed i forgot to requeue the parent. I've fixed this in my tree (see the delta patch below) - thanks!

Ingo

----------->
From: Ingo Molnar <[email protected]>
Subject: [cfs] fix parent's rbtree position

Nick noticed that upon fork we change parent->wait_runtime but we do not requeue it within the rbtree.

kernel/sched_fair.c +2 -0
Index: linux/kernel/sched_fair.c
===================================================================
@@ -524,6 +524,8 @@ static void task_new_fair(struct rq *rq,
 
 	p->wait_runtime = parent->wait_runtime/2;
 	parent->wait_runtime /= 2;
+	requeue_task_fair(rq, parent);
+
 	/*
 	 * For the first timeslice we allow child threads
 	 * to move their parent-inherited fairness back
#33 lore raw
Quoted 2 lines · Ingo Molnar

Nick noticed that upon fork we change parent->wait_runtime but we do not requeue it within the rbtree.

this fix is not complete - because the child runqueue is locked here, not the parent's. I've fixed this properly in my tree and have uploaded a new sched-modular+cfs.patch. (the effects of the original bug are mostly harmless, the rbtree position gets corrected the first time the parent reschedules. The fix might improve heavy forker handling.)

Ingo

#34 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 2 lines · Ingo Molnar

Nick noticed that upon fork we change parent->wait_runtime but we do not requeue it within the rbtree.

this fix is not complete - because the child runqueue is locked here, not the parent's. I've fixed this properly in my tree and have uploaded a new sched-modular+cfs.patch. (the effects of the original bug are mostly harmless, the rbtree position gets corrected the first time the parent reschedules. The fix might improve heavy forker handling.)

It looks like it did not reach your public dir yet.

BTW, I've given it a try. It seems pretty usable. I have also tried the usual meaningless "glxgears" test with 12 of them at the same time, and they rotate very smoothly, there is absolutely no pause in any of them. But they don't all run at same speed, and top reports their CPU load varying from 3.4 to 10.8%, with what looks like more CPU is assigned to the first processes, and less CPU for the last ones. But this is just a rough observation on a stupid test, I would not call that one scientific in any way (and X has its share in the test too).

I'll perform other tests when I can rebuild with your fixed patch.

Cheers,
Willy

#35 lore raw
Quoted 15 lines · Willy Tarreau
Quoted 11 lines · Ingo Molnar
Quoted 2 lines · Ingo Molnar

Nick noticed that upon fork we change parent->wait_runtime but we do not requeue it within the rbtree.

this fix is not complete - because the child runqueue is locked here, not the parent's. I've fixed this properly in my tree and have uploaded a new sched-modular+cfs.patch. (the effects of the original bug are mostly harmless, the rbtree position gets corrected the first time the parent reschedules. The fix might improve heavy forker handling.)

It looks like it did not reach your public dir yet.

Quoted 8 lines

BTW, I've given it a try. It seems pretty usable. I have also tried the usual meaningless "glxgears" test with 12 of them at the same time, and they rotate very smoothly, there is absolutely no pause in any of them. But they don't all run at same speed, and top reports their CPU load varying from 3.4 to 10.8%, with what looks like more CPU is assigned to the first processes, and less CPU for the last ones. But this is just a rough observation on a stupid test, I would not call that one scientific in any way (and X has its share in the test too).

Follow-up: I think this is mostly X-related. I've started 100 scheddos, and all get the same CPU percentage. Interestingly, mpg123 in parallel does never skip at all because it needs quite less than 1% CPU and gets its fair share at a load of 112. Xterms are slow to respond to typing with the 12 gears and 100 scheddos, and expectedly it was X which was starving. renicing it to -5 restores normal feeling with very slow but smooth gear rotations. Leaving X niced at 0 and killing the gears also restores normal behaviour.

All in all, it seems logical that processes which serve many others become a bottleneck for them.

Forking becomes very slow above a load of 100 it seems. Sometimes, the shell takes 2 or 3 seconds to return to prompt after I run "scheddos &"

Those are very promising results, I nearly observe the same responsiveness as I had on a solaris 10 with 10k running processes on a bigger machine.

I would be curious what a mysql test result would look like now.

Regards,
Willy

#79 lore raw
In reply to Willy Tarreau
Quoted 8 lines · Willy Tarreau
Quoted 6 lines

this fix is not complete - because the child runqueue is locked here, not the parent's. I've fixed this properly in my tree and have uploaded a new sched-modular+cfs.patch. (the effects of the original bug are mostly harmless, the rbtree position gets corrected the first time the parent reschedules. The fix might improve heavy forker handling.)

It looks like it did not reach your public dir yet.

oops, forgot to do the last step - should be fixed now.

Quoted 9 lines

BTW, I've given it a try. It seems pretty usable. I have also tried the usual meaningless "glxgears" test with 12 of them at the same time, and they rotate very smoothly, there is absolutely no pause in any of them. But they don't all run at same speed, and top reports their CPU load varying from 3.4 to 10.8%, with what looks like more CPU is assigned to the first processes, and less CPU for the last ones. But this is just a rough observation on a stupid test, I would not call that one scientific in any way (and X has its share in the test too).

ok, i'll try that too - there should be nothing particularly special about glxgears.

there's another tweak you could try:

	echo 500000 > /proc/sys/kernel/sched_granularity_ns

note that this causes preemption to be done as fast as the scheduler can do it. (in practice it will be mainly driven by CONFIG_HZ, so to get the best results a CONFIG_HZ of 1000 is useful.)

plus there's an add-on to CFS at:

http://redhat.com/~mingo/cfs-scheduler/sched-fair-hog.patch

this makes the 'CPU usage history cutoff' configurable and sets it to a default of 100 msecs. This means that CPU hogs (tasks which actively kept other tasks from running) will be remembered, for up to 100 msecs of their 'hogness'.

Setting this limit back to 0 gives the 'vanilla' CFS scheduler's behavior:

echo 0 > /proc/sys/kernel/sched_max_hog_history_ns

(So when trying this you dont have to reboot with this patch applied/unapplied, just set this value.)

Quoted 1 line

I'll perform other tests when I can rebuild with your fixed patch.

cool, thanks!

Ingo

#36 lore raw
In reply to Willy Tarreau
Quoted 3 lines · Willy Tarreau

Forking becomes very slow above a load of 100 it seems. Sometimes, the shell takes 2 or 3 seconds to return to prompt after I run "scheddos &"

this might be changed/impacted by the parent-requeue fix that is in the updated (for real, promise! ;) patch. Right now on CFS a forking parent shares its own run stats with the child 50%/50%. This means that heavy forkers are indeed penalized. Another logical choice would be 100%/0%: a child has to earn its own right.

i kept the 50%/50% rule from the old scheduler, but maybe it's a more pristine (and smaller/faster) approach to just not give new children any stats history to begin with. I've implemented an add-on patch that implements this, you can find it at:

http://redhat.com/~mingo/cfs-scheduler/sched-fair-fork.patch

Quoted 3 lines

Those are very promising results, I nearly observe the same responsiveness as I had on a solaris 10 with 10k running processes on a bigger machine.

cool and thanks for the feedback! (Btw., as another test you could also try to renice "scheddos" to +19. While that does not push the scheduler nearly as hard as nice 0, it is perhaps more indicative of how a truly abusive many-tasks workload would be run in practice.)

Ingo

#12 lore raw
In reply to Daniel Walker
Quoted 3 lines · Daniel Walker

One other thing, what happens in the case of slow, frequency changing, are/or inaccurate clocks .. Is the old sched_clock behavior still tolerated?

yeah, good question. Yesterday i did a quick testboot with that too, and it seemed to behave pretty OK with the low-res [jiffies based] sched_clock() too. Although in that case things are much more of an approximation and rounding/arithmetics artifacts are possible. CFS works best with a high-resolution cycle counter.

Ingo

#38 lore raw
In reply to Willy Tarreau
Quoted 3 lines · Willy Tarreau

Well, I'll stop heating the room for now as I get out of ideas about how to defeat it.

Ah, I found something nasty.
If I start large batches of processes like this :

$ for i in $(seq 1 1000); do ./scheddos2 4000 4000 & done

the ramp up slows down after 700-800 processes, but something very strange happens. If I'm under X, I can switch the focus to all xterms (the WM is still alive) but all xterms are frozen. On the console, after one moment I simply cannot switch to another VT anymore while I can still start commands locally. But "chvt 2" simply blocks. SysRq-K killed everything and restored full control. Dmesg shows lots of :
SAK: killed process xxxx (scheddos2): process_session(p)==tty->session.

I wonder if part of the problem would be too many processes bound to the same tty :-/

I'll investigate a bit.

Willy

#37 lore raw
In reply to Ingo Molnar
Quoted 13 lines · Ingo Molnar
Quoted 3 lines · Willy Tarreau

Forking becomes very slow above a load of 100 it seems. Sometimes, the shell takes 2 or 3 seconds to return to prompt after I run "scheddos &"

this might be changed/impacted by the parent-requeue fix that is in the updated (for real, promise! ;) patch. Right now on CFS a forking parent shares its own run stats with the child 50%/50%. This means that heavy forkers are indeed penalized. Another logical choice would be 100%/0%: a child has to earn its own right.

Quoted 6 lines

i kept the 50%/50% rule from the old scheduler, but maybe it's a more pristine (and smaller/faster) approach to just not give new children any stats history to begin with. I've implemented an add-on patch that implements this, you can find it at:

http://redhat.com/~mingo/cfs-scheduler/sched-fair-fork.patch

Not tried yet, it already looks better with the update and sched-fair-hog. Now xterm open "instantly" even with 1000 running processes.

Quoted 8 lines
Quoted 3 lines

Those are very promising results, I nearly observe the same responsiveness as I had on a solaris 10 with 10k running processes on a bigger machine.

cool and thanks for the feedback! (Btw., as another test you could also try to renice "scheddos" to +19. While that does not push the scheduler nearly as hard as nice 0, it is perhaps more indicative of how a truly abusive many-tasks workload would be run in practice.)

Good idea. The machine I'm typing from now has 1000 scheddos running at +19, and 12 gears at nice 0. Top keeps reporting different cpu usages for all gears, but I'm pretty sure that it's a top artifact now because the cumulated times are roughly identical :

14:33:13 up 13 min, 7 users, load average: 900.30, 443.75, 177.70
1088 processes: 80 sleeping, 1008 running, 0 zombie, 0 stopped

CPU0 states:  56.0% user  43.0% system   23.0% nice   0.0% iowait   0.0% idle
CPU1 states:  94.0% user   5.0% system    0.0% nice   0.0% iowait   0.0% idle
Mem:  1034764k av,  223788k used,  810976k free,       0k shrd,    7192k buff
       104400k active,              51904k inactive

Swap: 497972k av, 0k used, 497972k free 68020k cached

  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME CPU COMMAND
 1325 root      20   0 69240 9400  3740 R    27.6  0.9   4:46   1 X
 1412 willy     20   0  6284 2552  1740 R    14.2  0.2   1:09   1 glxgears
 1419 willy     20   0  6256 2384  1612 R    10.7  0.2   1:09   1 glxgears
 1409 willy     20   0  2824 1940   788 R     8.9  0.1   0:25   1 top
 1414 willy     20   0  6280 2544  1728 S     8.9  0.2   1:08   0 glxgears
 1415 willy     20   0  6256 2376  1600 R     8.9  0.2   1:07   1 glxgears
 1417 willy     20   0  6256 2384  1612 S     8.9  0.2   1:05   1 glxgears
 1420 willy     20   0  6284 2552  1740 R     8.9  0.2   1:07   1 glxgears
 1410 willy     20   0  6256 2372  1600 S     7.1  0.2   1:11   1 glxgears
 1413 willy     20   0  6260 2388  1612 S     7.1  0.2   1:08   0 glxgears
 1416 willy     20   0  6284 2544  1728 S     6.2  0.2   1:06   0 glxgears
 1418 willy     20   0  6252 2384  1612 S     6.2  0.2   1:09   0 glxgears
 1411 willy     20   0  6280 2548  1740 S     5.3  0.2   1:15   1 glxgears
 1421 willy     20   0  6280 2536  1728 R     5.3  0.2   1:05   1 glxgears
Quoted 1 line

From time to time, one of the 12 aligned gears will quickly perform a full

quarter of round while others slowly turn by a few degrees. In fact, while I don't know this process's CPU usage pattern, there's something useful in it : it allows me to visually see when process accelerate/deceleraet. What would be best would be just a clock requiring low X ressources and eating vast amounts of CPU between movements. It will help visually monitor CPU distribution without being too much impacted by X.

I've just added another 100 scheddos at nice 0, and the system is still amazingly usable. I just tried exchanging a 1-byte token between 188 "dd" processes which communicate through circular pipes. The context switch rate is rather high but this has no impact on the rest :

willy@pcw:c$ dd if=/tmp/fifo bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | dd bs=1 | (echo -n a;dd bs=1) | dd bs=1 of=/tmp/fifo

procs memory swap io system cpu
r b w swpd free buff cache si so bi bo in cs us sy id

1105  0  1      0 781108   8364  68180    0    0     0    12    5 82187 59 41  0
1114  0  1      0 781108   8364  68180    0    0     0     0    0 81528 58 42  0
1112  0  1      0 781108   8364  68180    0    0     0     0    1 80899 58 42  0
1113  0  1      0 781108   8364  68180    0    0     0     0   26 83466 58 42  0
1106  0  2      0 781108   8376  68168    0    0     0     8   91 83193 58 42  0
1107  0  1      0 781108   8376  68180    0    0     0     4    7 79951 58 42  0
1106  0  1      0 781108   8376  68180    0    0     0     0   46 80939 57 43  0
1114  0  1      0 781108   8376  68180    0    0     0     0   21 82019 56 44  0
1116  0  1      0 781108   8376  68180    0    0     0     0   16 85134 56 44  0
1114  0  3      0 781108   8388  68168    0    0     0    16   20 85871 56 44  0
1112  0  1      0 781108   8388  68168    0    0     0     0   15 80412 57 43  0
1112  0  1      0 781108   8388  68180    0    0     0     0  101 83002 58 42  0
1113  0  1      0 781108   8388  68180    0    0     0     0   25 82230 56 44  0

Playing with the sched_max_hog_history_ns does not seem to change anything. Maybe it's useful for other workloads. Anyway, I have nothing to complain about, because it's not common for me to be able to normally type a mail on a system with more than 1000 running processes ;-)

Also, mixed with this load, I have started injecting HTTP requests between two local processes. The load is stable at 7700 req/s (11800 when alone), and what I was interested in is the response time. It's perfectly stable between 9.0 and 9.4 ms with a standard deviation of about 6.0 ms. Those were varying a lot under stock scheduler, with some sessions sometimes pausing for seconds. (RSDL fixed this though).

Well, I'll stop heating the room for now as I get out of ideas about how to defeat it. I'm convinced. I'm impatient to read about Mike's feedback with his workload which behaves strangely on RSDL. If it works OK here, it will be the proof that heuristics should not be needed.

Congrats !
Willy

#39 lore raw
In reply to Willy Tarreau
Quoted 19 lines · Willy Tarreau
Quoted 3 lines · Willy Tarreau

Well, I'll stop heating the room for now as I get out of ideas about how to defeat it.

Ah, I found something nasty.
If I start large batches of processes like this :

$ for i in $(seq 1 1000); do ./scheddos2 4000 4000 & done

the ramp up slows down after 700-800 processes, but something very strange happens. If I'm under X, I can switch the focus to all xterms (the WM is still alive) but all xterms are frozen. On the console, after one moment I simply cannot switch to another VT anymore while I can still start commands locally. But "chvt 2" simply blocks. SysRq-K killed everything and restored full control. Dmesg shows lots of :
SAK: killed process xxxx (scheddos2): process_session(p)==tty->session.

Quoted 2 lines

I wonder if part of the problem would be too many processes bound to the same tty :-/

Does not seem easy to reproduce, it looks like some resource pools are kept pre-allocated after a first run, because if I kill scheddos during the ramp up then start it again, it can go further. The problem happens when the parent is forking. Also, I modified scheddos to close(0,1,2) and to perform the forks itself and it does not cause any problem, even with 4000 processes running. So I really suspect that the problem I encountered above was tty-related.

BTW, I've tried your fork patch. It definitely helps forking because it takes below one second to create 4000 processes, then the load slowly increases. As you said, the children have to earn their share, and I find that it makes it easier to conserve control of the whole system's stability.

Regards,
Willy

#80 lore raw
In reply to Ingo Molnar

13 Nis 2007 Cum tarihinde, Ingo Molnar şunları yazmıştı:

Quoted 5 lines

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

Currently im using Linus's current git + your extra patches + CFS for a while. Kaffeine constantly freezes (and uses %80+ CPU time) [1] if i seek forward/backward while its playing a video with some workload (checking out SVN repositories, compiling something). Stopping other process didn't help kaffeine so it stays freezed stated until i kill it.

I'm not sure whether its a xine-lib or kaffeine bug (cause mplayer didn't have that problem) but i can't reproduce this with mainline or mainline + sd-0.39.

[1] http://cekirdek.pardus.org.tr/~caglar/psaux

Signature · 4 lines
S.Çağlar Onur <[email protected]>
http://cekirdek.pardus.org.tr/~caglar/

Linux is like living in a teepee. No Windows, no Gates and an Apache in house!
#76 lore raw
In reply to Ingo Molnar
Quoted 3 lines · Ingo Molnar

i kept the 50%/50% rule from the old scheduler, but maybe it's a more pristine (and smaller/faster) approach to just not give new children any stats history to begin with. I've implemented an add-on patch that implements this, you can find it at:

http://redhat.com/~mingo/cfs-scheduler/sched-fair-fork.patch

I've been running my desktop (single-core Pentium-M w/2GB RAM, Kubuntu Dapper) with the new CFS for much of this morning now, with the odd switch back to the stock scheduler for comparison.

Here, CFS really works and feels better than the stock scheduler.

Even with a "make -j2" kernel rebuild happening (no manual renice, either!) things "just work" about as smoothly as ever. That's something which RSDL never achieved for me, though I have not retested RSDL beyond v0.34 or so.

Well done, Ingo! I *want* this as my default scheduler.

Things seemed slightly less smooth when I had the CPU hogs and fair-fork extension patches both applied.

I'm going to try again now with just the fair-fork added on.

Cheers

Mark

#81 lore raw
In reply to S.Çağlar Onur
Quoted 9 lines · S.Çağlar Onur
Quoted 2 lines

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

Currently im using Linus's current git + your extra patches + CFS for a while. Kaffeine constantly freezes (and uses %80+ CPU time) [1] if i seek forward/backward while its playing a video with some workload (checking out SVN repositories, compiling something). Stopping other process didn't help kaffeine so it stays freezed stated until i kill it.

hm, could you try to strace it and/or attach gdb to it and figure out what's wrong? (perhaps involving the Kaffeine developers too?) As long as it's not a kernel level crash i cannot see how the scheduler could directly cause this - other than by accident creating a scheduling pattern that triggers a user-space bug more often than with other schedulers.

Quoted 1 line

[1] http://cekirdek.pardus.org.tr/~caglar/psaux

looks quite weird!

Ingo

#40 lore raw
In reply to Willy Tarreau
Quoted 5 lines · Willy Tarreau

BTW, I've tried your fork patch. It definitely helps forking because it takes below one second to create 4000 processes, then the load slowly increases. As you said, the children have to earn their share, and I find that it makes it easier to conserve control of the whole system's stability.

ok, thanks for testing this out, i think i'll integrate this one back into the core. (I'm still unsure about the cpu-hog one.) And it saves some code-size too:

   text    data     bss     dec     hex filename
  23349    2705      24   26078    65de kernel/sched.o.cfs-v1
  23189    2705      24   25918    653e kernel/sched.o.cfs-before
  23052    2705      24   25781    64b5 kernel/sched.o.cfs-after
  23366    4001      24   27391    6aff kernel/sched.o.vanilla
  23671    4548      24   28243    6e53 kernel/sched.o.sd.v40

Ingo

#41 lore raw
In reply to Willy Tarreau
Quoted 17 lines · Willy Tarreau
Quoted 3 lines · Willy Tarreau

Well, I'll stop heating the room for now as I get out of ideas about how to defeat it.

Ah, I found something nasty.
If I start large batches of processes like this :

$ for i in $(seq 1 1000); do ./scheddos2 4000 4000 & done

the ramp up slows down after 700-800 processes, but something very strange happens. If I'm under X, I can switch the focus to all xterms (the WM is still alive) but all xterms are frozen. On the console, after one moment I simply cannot switch to another VT anymore while I can still start commands locally. But "chvt 2" simply blocks. SysRq-K killed everything and restored full control. Dmesg shows lots of :

Quoted 4 lines

SAK: killed process xxxx (scheddos2): process_session(p)==tty->session.

I wonder if part of the problem would be too many processes bound to the same tty :-/

hm, that's really weird. I've Cc:-ed the tty experts (Erik, Jiri, Alan), maybe this description rings a bell with them?

Ingo

#82 lore raw
In reply to Ingo Molnar

14 Nis 2007 Cts tarihinde, Ingo Molnar şunları yazmıştı:

Quoted 6 lines

hm, could you try to strace it and/or attach gdb to it and figure out what's wrong? (perhaps involving the Kaffeine developers too?) As long as it's not a kernel level crash i cannot see how the scheduler could directly cause this - other than by accident creating a scheduling pattern that triggers a user-space bug more often than with other schedulers.

...

futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = 0
futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = 0
futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = 0
futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = 0
futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = 0
futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = -1 EINTR (Interrupted system call)

--- SIGINT (Interrupt) @ 0 (0) ---
+++ killed by SIGINT +++

is where freeze occurs. Full log can be found at [1]

Quoted 3 lines
Quoted 1 line

[1] http://cekirdek.pardus.org.tr/~caglar/psaux

looks quite weird!

:)

[1] http://cekirdek.pardus.org.tr/~caglar/strace.kaffeine

Signature · 4 lines
S.Çağlar Onur <[email protected]>
http://cekirdek.pardus.org.tr/~caglar/

Linux is like living in a teepee. No Windows, no Gates and an Apache in house!
#42 lore raw
In reply to Ingo Molnar
Quoted 12 lines · Ingo Molnar
Quoted 10 lines · Willy Tarreau
Quoted 3 lines · Willy Tarreau

Well, I'll stop heating the room for now as I get out of ideas about how to defeat it.

Ah, I found something nasty.
If I start large batches of processes like this :

$ for i in $(seq 1 1000); do ./scheddos2 4000 4000 & done
Quoted 8 lines
Quoted 8 lines

the ramp up slows down after 700-800 processes, but something very strange happens. If I'm under X, I can switch the focus to all xterms (the WM is still alive) but all xterms are frozen. On the console, after one moment I simply cannot switch to another VT anymore while I can still start commands locally. But "chvt 2" simply blocks. SysRq-K killed everything and restored full control. Dmesg shows lots of :

SAK: killed process xxxx (scheddos2): process_session(p)==tty->session.

This. Yes. SAK is noisy and tells you everything it kills.

Quoted 5 lines
Quoted 2 lines

I wonder if part of the problem would be too many processes bound to the same tty :-/

hm, that's really weird. I've Cc:-ed the tty experts (Erik, Jiri, Alan), maybe this description rings a bell with them?

Is there any swapping going on?

I'm inclined to suspect that it is a problem that has more to do with the number of processes and has nothing to do with ttys.

Anyway you can easily rule out ttys by having your startup program detach from a controlling tty before you start everything.

I'm more inclined to guess something is reading /proc a lot, or doing something that holds the tasklist lock, a lot or something like that, if the problem isn't that you are being kicked into swap.

Eric

#43 lore raw

Hi Eric,

[...]

Quoted 10 lines
Quoted 8 lines
Quoted 8 lines

the ramp up slows down after 700-800 processes, but something very strange happens. If I'm under X, I can switch the focus to all xterms (the WM is still alive) but all xterms are frozen. On the console, after one moment I simply cannot switch to another VT anymore while I can still start commands locally. But "chvt 2" simply blocks. SysRq-K killed everything and restored full control. Dmesg shows lots of :

SAK: killed process xxxx (scheddos2): process_session(p)==tty->session.

This. Yes. SAK is noisy and tells you everything it kills.

OK, that's what I suspected, but I did not know if the fact that it talked about the session was systematic or related to any particular state when it killed the task.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I wonder if part of the problem would be too many processes bound to the same tty :-/

hm, that's really weird. I've Cc:-ed the tty experts (Erik, Jiri, Alan), maybe this description rings a bell with them?

Is there any swapping going on?

Not at all.

Quoted 2 lines

I'm inclined to suspect that it is a problem that has more to do with the number of processes and has nothing to do with ttys.

It is clearly possible. What I found strange is that I could still fork processes (eg: ls, dmesg|tail), ... but not switch to another VT anymore. It first happened under X with frozen xterms but a perfectly usable WM, then I reproduced it on pure console to rule out any potential X problem.

Quoted 6 lines

Anyway you can easily rule out ttys by having your startup program detach from a controlling tty before you start everything.

I'm more inclined to guess something is reading /proc a lot, or doing something that holds the tasklist lock, a lot or something like that, if the problem isn't that you are being kicked into swap.

Oh I'm sorry you were invited into the discussion without a first description of the context. I was giving a try to Ingo's new scheduler, and trying to reach corner cases with lots of processes competing for CPU.

I simply used a "for" loop in bash to fork 1000 processes, and this problem happened between 700-800 children. The program only uses a busy loop and a pause. I then changed my program to close 0,1,2 and perform the fork itself, and the problem vanished. So there are two differences here :

- bash not forking anymore
- far less FDs on /dev/tty1

At first, I had around 2200 fds on /dev/tty1, reason why I suspected something in this area.

I agree that this is not normal usage at all, I'm just trying to attack Ingo's scheduler to ensure it is more robust than the stock one. But sometimes brute force methods can make other sleeping problems pop up.

Thinking about it, I don't know if there are calls to schedule() while switching from tty1 to tty2. Alt-F2 had no effect anymore, and "chvt 2" simply blocked. It would have been possible that a schedule() call somewhere got starved due to the load, I don't know.

Thanks,
Willy

#44 lore raw
Quoted 47 lines · Willy Tarreau

Hi Eric,

[...]

Quoted 10 lines
Quoted 8 lines
Quoted 8 lines

the ramp up slows down after 700-800 processes, but something very strange happens. If I'm under X, I can switch the focus to all xterms (the WM is still alive) but all xterms are frozen. On the console, after one moment I simply cannot switch to another VT anymore while I can still start commands locally. But "chvt 2" simply blocks. SysRq-K killed everything and restored full control. Dmesg shows lots of :

SAK: killed process xxxx (scheddos2): process_session(p)==tty->session.

This. Yes. SAK is noisy and tells you everything it kills.

OK, that's what I suspected, but I did not know if the fact that it talked about the session was systematic or related to any particular state when it killed the task.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I wonder if part of the problem would be too many processes bound to the same tty :-/

hm, that's really weird. I've Cc:-ed the tty experts (Erik, Jiri, Alan), maybe this description rings a bell with them?

Is there any swapping going on?

Not at all.

Quoted 2 lines

I'm inclined to suspect that it is a problem that has more to do with the number of processes and has nothing to do with ttys.

It is clearly possible. What I found strange is that I could still fork processes (eg: ls, dmesg|tail), ... but not switch to another VT anymore. It first happened under X with frozen xterms but a perfectly usable WM, then I reproduced it on pure console to rule out any potential X problem.

Quoted 6 lines

Anyway you can easily rule out ttys by having your startup program detach from a controlling tty before you start everything.

I'm more inclined to guess something is reading /proc a lot, or doing something that holds the tasklist lock, a lot or something like that, if the problem isn't that you are being kicked into swap.

Oh I'm sorry you were invited into the discussion without a first description of the context. I was giving a try to Ingo's new scheduler, and trying to reach corner cases with lots of processes competing for CPU.

Quoted 7 lines

I simply used a "for" loop in bash to fork 1000 processes, and this problem happened between 700-800 children. The program only uses a busy loop and a pause. I then changed my program to close 0,1,2 and perform the fork itself, and the problem vanished. So there are two differences here :

- bash not forking anymore
- far less FDs on /dev/tty1

Yes. But with /dev/tty1 being the controlling terminal in both cases, as you haven't dropped your session, or disassociated your tty.

The bash problem may have something to setpgid or scheduling effects. Hmm. I just looked and setpgid does grab the tasklist lock for writing so we may possibly have some contention there.

Quoted 6 lines

At first, I had around 2200 fds on /dev/tty1, reason why I suspected something in this area.

I agree that this is not normal usage at all, I'm just trying to attack Ingo's scheduler to ensure it is more robust than the stock one. But sometimes brute force methods can make other sleeping problems pop up.

Yep. If we can narrow it down to one that would be interesting. Of course that also means when we start finding other possibly sleeping problems people are working in areas of code the don't normally touch, so we must investigate.

Quoted 4 lines

Thinking about it, I don't know if there are calls to schedule() while switching from tty1 to tty2. Alt-F2 had no effect anymore, and "chvt 2" simply blocked. It would have been possible that a schedule() call somewhere got starved due to the load, I don't know.

It looks like there is a call to schedule_work.

There are two pieces of the path. If you are switching in and out of a tty controlled by something like X. User space has to grant permission before the operation happens. Where there isn't a gate keeper I know it is cheaper but I don't know by how much, I suspect there is still a schedule happening in there.

Eric

#58 lore raw
In reply to Willy Tarreau
Quoted 3 lines · Willy Tarreau

It is clearly possible. What I found strange is that I could still fork processes (eg: ls, dmesg|tail), ... but not switch to another VT anymore.

Considering the patches in question, it's almost definitely just a CPU scheduling problem with starvation.

The VT switching is obviously done by the kernel, but the kernel will signal and wait for the "controlling process" for the VT. The most obvious case of that is X, of course, but even in text mode I think gpm will have taken control of the VT's it runs on (all of them), which means that when you initiate a VT switch, the kernel will actually signal the controlling process (gpm), and wait for it to acknowledge the switch.

If gpm doesn't get a timeslice for some reason (and it sounds like there may be some serious unfairness after "fork()"), your behaviour is explainable.

(NOTE! I've never actually looked at gpm sources or what it really does, so maybe I'm wrong, and it doesn't try to do the controlling VT thing, and something else is going on, but quite frankly, it sounds like the obvious candidate for this bug. Explaining it with some non-scheduler-related thing sounds unlikely, considering the patch in question).

Linus

#45 lore raw
In reply to Eric W. Biederman
Quoted 6 lines · Eric W. Biederman
Quoted 4 lines

Thinking about it, I don't know if there are calls to schedule() while switching from tty1 to tty2. Alt-F2 had no effect anymore, and "chvt 2" simply blocked. It would have been possible that a schedule() call somewhere got starved due to the load, I don't know.

It looks like there is a call to schedule_work.

so this goes over keventd, right?

Quoted 5 lines

There are two pieces of the path. If you are switching in and out of a tty controlled by something like X. User space has to grant permission before the operation happens. Where there isn't a gate keeper I know it is cheaper but I don't know by how much, I suspect there is still a schedule happening in there.

Could keventd perhaps be starved? Willy, to exclude this possibility, could you perhaps chrt keventd to RT priority? If events/0 is PID 5 then the command to set it to SCHED_FIFO:50 would be:

chrt -f -p 50 5

but ... events/0 is reniced to -5 by default, so it should definitely not be starved.

Ingo

#46 lore raw
Quoted 18 lines · Ingo Molnar
Quoted 6 lines · Eric W. Biederman
Quoted 4 lines

Thinking about it, I don't know if there are calls to schedule() while switching from tty1 to tty2. Alt-F2 had no effect anymore, and "chvt 2" simply blocked. It would have been possible that a schedule() call somewhere got starved due to the load, I don't know.

It looks like there is a call to schedule_work.

so this goes over keventd, right?

Quoted 5 lines

There are two pieces of the path. If you are switching in and out of a tty controlled by something like X. User space has to grant permission before the operation happens. Where there isn't a gate keeper I know it is cheaper but I don't know by how much, I suspect there is still a schedule happening in there.

Quoted 8 lines

Could keventd perhaps be starved? Willy, to exclude this possibility, could you perhaps chrt keventd to RT priority? If events/0 is PID 5 then the command to set it to SCHED_FIFO:50 would be:

chrt -f -p 50 5

but ... events/0 is reniced to -5 by default, so it should definitely not be starved.

Well, since I merged the fair-fork patch, I cannot reproduce (in fact, bash forks 1000 processes, then progressively execs scheddos, but it takes some time). So I'm rebuilding right now. But I think that Linus has an interesting clue about GPM and notification before switching the terminal. I think it was enabled in console mode. I don't know how that translates to frozen xterms, but let's attack the problems one at a time.

Willy

#47 lore raw
Quoted 28 lines · Willy Tarreau
Quoted 18 lines · Ingo Molnar
Quoted 6 lines · Eric W. Biederman
Quoted 4 lines

Thinking about it, I don't know if there are calls to schedule() while switching from tty1 to tty2. Alt-F2 had no effect anymore, and "chvt 2" simply blocked. It would have been possible that a schedule() call somewhere got starved due to the load, I don't know.

It looks like there is a call to schedule_work.

so this goes over keventd, right?

Quoted 5 lines

There are two pieces of the path. If you are switching in and out of a tty controlled by something like X. User space has to grant permission before the operation happens. Where there isn't a gate keeper I know it is cheaper but I don't know by how much, I suspect there is still a schedule happening in there.

Quoted 8 lines

Could keventd perhaps be starved? Willy, to exclude this possibility, could you perhaps chrt keventd to RT priority? If events/0 is PID 5 then the command to set it to SCHED_FIFO:50 would be:

chrt -f -p 50 5

but ... events/0 is reniced to -5 by default, so it should definitely not be starved.

Quoted 7 lines

Well, since I merged the fair-fork patch, I cannot reproduce (in fact, bash forks 1000 processes, then progressively execs scheddos, but it takes some time). So I'm rebuilding right now. But I think that Linus has an interesting clue about GPM and notification before switching the terminal. I think it was enabled in console mode. I don't know how that translates to frozen xterms, but let's attack the problems one at a time.

I think it is a good clue. However the intention of the mechanism is that only processes that change the video mode on a VT are supposed to use it. So I really don't think gpm is the culprit. However it easily could be something else that has similar characteristics.

I just realized we do have proof that schedule_work is actually working because SAK works, and we can't sanely do SAK from interrupt context so we call schedule work.

Eric

#27 lore raw
In reply to Ingo Molnar
Quoted 2 lines · Ingo Molnar

very much so! Both Con and Mike has contributed regularly to upstream sched.c:

The problem here is tha Con can get demotivated (and rather upset) when an idea gets proposed, like SchedPlug, only to have people be hostile to it and then sudden turn around an adopt this idea. It give the impression that you, in this specific case, were more interested in controlling a situation and the track of development instead of actually being inclusive of the development process with discussion and serious consideration, etc...

This is how the Linux community can be perceived as elitist. The old guard would serve the community better if people were more mindful and sensitive to developer issues. There was a particular speech that I was turned off by at OLS 2006 that pretty much pandering to the "old guard's" needs over newer developers. Since I'm a some what established engineer in -rt (being the only other person that mapped the lock hierarchy out for full preemptibility), I had the confidence to pretty much ignored it while previously this could have really upset me and be highly discouraging to a relatively new developer.

As Linux gets larger and larger this is going to be an increasing problem when folks come into the community with new ideas and the community will need to change if it intends to integrate these folks. IMO, a lot of these flame ware wouldn't need to exist if folks listent ot each other better and permit co-ownership of code like the scheduler since it needs multipule hands in it adapt to new loads and situations, etc...

I'm saying this nicely now since I can be nasty about it.

bill

#48 lore raw
In reply to Eric W. Biederman
Quoted 38 lines · Eric W. Biederman
Quoted 28 lines · Willy Tarreau
Quoted 18 lines · Ingo Molnar
Quoted 6 lines · Eric W. Biederman
Quoted 4 lines

Thinking about it, I don't know if there are calls to schedule() while switching from tty1 to tty2. Alt-F2 had no effect anymore, and "chvt 2" simply blocked. It would have been possible that a schedule() call somewhere got starved due to the load, I don't know.

It looks like there is a call to schedule_work.

so this goes over keventd, right?

Quoted 5 lines

There are two pieces of the path. If you are switching in and out of a tty controlled by something like X. User space has to grant permission before the operation happens. Where there isn't a gate keeper I know it is cheaper but I don't know by how much, I suspect there is still a schedule happening in there.

Quoted 8 lines

Could keventd perhaps be starved? Willy, to exclude this possibility, could you perhaps chrt keventd to RT priority? If events/0 is PID 5 then the command to set it to SCHED_FIFO:50 would be:

chrt -f -p 50 5

but ... events/0 is reniced to -5 by default, so it should definitely not be starved.

Quoted 7 lines

Well, since I merged the fair-fork patch, I cannot reproduce (in fact, bash forks 1000 processes, then progressively execs scheddos, but it takes some time). So I'm rebuilding right now. But I think that Linus has an interesting clue about GPM and notification before switching the terminal. I think it was enabled in console mode. I don't know how that translates to frozen xterms, but let's attack the problems one at a time.

Quoted 8 lines

I think it is a good clue. However the intention of the mechanism is that only processes that change the video mode on a VT are supposed to use it. So I really don't think gpm is the culprit. However it easily could be something else that has similar characteristics.

I just realized we do have proof that schedule_work is actually working because SAK works, and we can't sanely do SAK from interrupt context so we call schedule work.

Eric,

I can say that Linus, Ingo and you all got on the right track. I could reproduce, I got a hung tty around 1400 running processes. Fortunately, it was the one with the root shell which was reniced to -19.

I could strace chvt 2 :

20:44:23.761117 open("/dev/tty", O_RDONLY) = 3 <0.004000> 20:44:23.765117 ioctl(3, KDGKBTYPE, 0xbfa305a3) = 0 <0.024002> 20:44:23.789119 ioctl(3, VIDIOC_G_COMP or VT_ACTIVATE, 0x3) = 0 <0.000000> 20:44:23.789119 ioctl(3, VIDIOC_S_COMP or VT_WAITACTIVE <unfinished ...>

Then I applied Ingo's suggestion about changing keventd prio :

root@pcw:~# ps auxw|grep event
root         8  0.0  0.0     0    0 ?        SW<  20:31   0:00 [events/0]
root         9  0.0  0.0     0    0 ?        RW<  20:31   0:00 [events/1]
root@pcw:~# rtprio -s 1 -p 50 8 9     (I don't have chrt but it does the same)

My VT immediately switched as soon as I hit Enter. Everything's working fine again now. So the good news is that it's not a bug in the tty code, nor a deadlock.

Now, maybe keventd should get a higher prio ? It seems worrying to me that it may starve when it seems so much sensible.

Also, that may explain why I couldn't reproduce with the fork patch. Since all new processes got no runtime at first, their impact on existing ones must have been lower. But I think that if I had waited longer, I would have had the problem again (though I did not see it even under a load of 7800).

Regards,
Willy

#77 lore raw
In reply to Willy Tarreau
Quoted 6 lines · Willy Tarreau

Forking becomes very slow above a load of 100 it seems. Sometimes, the shell takes 2 or 3 seconds to return to prompt after I run "scheddos &"
Those are very promising results, I nearly observe the same responsiveness as I had on a solaris 10 with 10k running processes on a bigger machine. I would be curious what a mysql test result would look like now.

Where is scheddos?

-- wli

#78 lore raw
Quoted 9 lines · William Lee Irwin III
Quoted 6 lines · Willy Tarreau

Forking becomes very slow above a load of 100 it seems. Sometimes, the shell takes 2 or 3 seconds to return to prompt after I run "scheddos &"
Those are very promising results, I nearly observe the same responsiveness as I had on a solaris 10 with 10k running processes on a bigger machine. I would be curious what a mysql test result would look like now.

Where is scheddos?

I will send it to you off-list. I've been avoiding to publish it for a long time because the stock scheduler was *very* sensible to trivial attacks (freezes larger than 30s, impossible to log in). It's very basic, and I have no problem sending it to anyone who requests it, it's just that as long as some distros ship early 2.6 kernels I do not want it to appear on mailing list archives for anyone to grab it and annoy their admins for free.

Cheers,
Willy

#18 lore raw
In reply to William Lee Irwin III
Quoted 12 lines · William Lee Irwin III
Quoted 10 lines · Ingo Molnar

The CFS patch uses a completely different approach and implementation from RSDL/SD. My goal was to make CFS's interactivity quality exceed that of RSDL/SD, which is a high standard to meet :-) Testing feedback is welcome to decide this one way or another. [ and, in any case, all of SD's logic could be added via a kernel/sched_sd.c module as well, if Con is interested in such an approach. ] CFS's design is quite radical: it does not use runqueues, it uses a time-ordered rbtree to build a 'timeline' of future task execution, and thus has no 'array switch' artifacts (by which both the vanilla scheduler and RSDL/SD are affected).

Quoted 6 lines

A binomial heap would likely serve your purposes better than rbtrees. It's faster to have the next item to dequeue at the root of the tree structure rather than a leaf, for one. There are, of course, other priority queue structures (e.g. van Emde Boas) able to exploit the limited precision of the priority key for faster asymptotics, though actual performance is an open question.

Haven't looked at the scheduler code yet, but for a similar problem I use a time ring. The ring has Ns (2 power is better) slots (where tasks are queued - in my case they were som sort of timers), and it has a current base index (Ib), a current base time (Tb) and a time granularity (Tg). It also has a bitmap with bits telling you which slots contains queued tasks. An item (task) that has to be scheduled at time T, will be queued in the slot:

S = Ib + min((T - Tb) / Tg, Ns - 1);

Items with T longer than Ns*Tg will be scheduled in the relative last slot (chosing a proper Ns and Tg can minimize this).
Queueing is O(1) and de-queueing is O(Ns). You can play with Ns and Tg to suite to your needs.
This is a simple bench between time-ring (TR) and CFS queueing:

http://www.xmailserver.org/smart-queue.c

In my box (Dual Opteron 252):

davide@alien:~$ ./smart-queue -n 8            
CFS = 142.21 cycles/loop
TR  = 72.33 cycles/loop
davide@alien:~$ ./smart-queue -n 16
CFS = 188.74 cycles/loop
TR  = 83.79 cycles/loop
davide@alien:~$ ./smart-queue -n 32
CFS = 221.36 cycles/loop
TR  = 75.93 cycles/loop
davide@alien:~$ ./smart-queue -n 64
CFS = 242.89 cycles/loop
TR  = 81.29 cycles/loop

- Davide

#19 lore raw
Quoted 8 lines · Davide Libenzi

Haven't looked at the scheduler code yet, but for a similar problem I use a time ring. The ring has Ns (2 power is better) slots (where tasks are queued - in my case they were som sort of timers), and it has a current base index (Ib), a current base time (Tb) and a time granularity (Tg). It also has a bitmap with bits telling you which slots contains queued tasks. An item (task) that has to be scheduled at time T, will be queued in the slot:

S = Ib + min((T - Tb) / Tg, Ns - 1);

... mod Ns, of course ;)

- Davide

#117 lore raw
In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

Quoted 6 lines

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.

The casual observer will be completely confused by what on earth has happened here so let me try to demystify things for them.

1. I tried in vain some time ago to push a working extensable pluggable cpu scheduler framework (based on wli's work) for the linux kernel. It was perma-vetoed by Linus and Ingo (and Nick also said he didn't like it) as being absolutely the wrong approach and that we should never do that. Oddly enough the linux-kernel-mailing list was -dead- at the time and the discussion did not make it to the mailing list. Every time I've tried to forward it to the mailing list the spam filter decided to drop it so most people have not even seen this original veto-forever discussion.

2. Since then I've been thinking/working on a cpu scheduler design that takes away all the guesswork out of scheduling and gives very predictable, as fair as possible, cpu distribution and latency while preserving as solid interactivity as possible within those confines. For weeks now, Ingo has said that the interactivity regressions were showstoppers and we should address them, never mind the fact that the so-called regressions were purely "it slows down linearly with load" which to me is perfectly desirable behaviour. While this was not perma-vetoed, I predicted pretty accurately your intent was to veto it based on this.

People kept claiming scheduling problems were few and far between but what was really happening is users were terrified of lkml and instead used 1. windows and 2. 2.4 kernels. The problems were there.

So where are we now? Here is where your latest patch comes in.

As a solution to the many scheduling problems we finally all agree exist, you propose a patch that adds 1. a limited pluggable framework and 2. a fairness based cpu scheduler policy... o_O

So I should be happy at last now that the things I was promoting you are also promoting, right? Well I'll fill in the rest of the gaps and let other people decide how I should feel.

Quoted 2 lines

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

In the last 4 weeks I've spent time lying in bed drugged to the eyeballs and having trips in and out of hospitals for my condition. I appreciate greatly the sympathy and patience from people in this regard. However at one stage I virtually begged for support with my attempts and help with the code. Dmitry Adamushko is the only person who actually helped me with the code in the interim, while others poked sticks at it. Sure the sticks helped at times but the sticks always seemed to have their ends kerosene doused and flaming for reasons I still don't get. No other help was forthcoming.

Now that you're agreeing my direction was correct you've done the usual Linux kernel thing - ignore all my previous code and write your own version. Oh well, that I've come to expect; at least you get a copyright notice in the bootup and somewhere in the comments give me credit for proving it's possible. Let's give some other credit here too. William Lee Irwin provided the major architecture behind plugsched at my request and I simply finished the work and got it working. He is also responsible for many IRC discussions I've had about cpu scheduling fairness, designs, programming history and code help. Even though he did not contribute code directly to SD, his comments have been invaluable.

So let's look at the code.

kernel/sched.c
kernel/sched_fair.c
kernel/sched_rt.c

It turns out this is not a pluggable cpu scheduler framework at all, and I guess you didn't really promote it as such. It's a "modular scheduler core". Which means you moved code from sched.c into sched_fair.c and sched_rt.c. This abstracts out each _scheduling policy's_ functions into struct sched_class and allows each scheduling policy's functions to be in a separate file etc.

Ok so what it means is that instead of whole cpu schedulers being able to be plugged into this framework we can plug in only cpu scheduling policies.... hrm... So let's look on

-#define SCHED_NORMAL 0

Ok once upon a time we rename SCHED_OTHER which every other unix calls the standard policy 99.9% of applications used into a more meaningful name, SCHED_NORMAL. That's fine since all it did was change the description internally for those reading the code. Let's see what you've done now:

+#define SCHED_FAIR 0

You've renamed it again. This is, I don't know what exactly to call it, but an interesting way of making it look like there is now more choice. Well, whatever you call it, everything in linux spawned from init without specifying a policy still gets policy 0. This is SCHED_OTHER still, renamed SCHED_NORMAL and now SCHED_FAIR.

You encouraged me to create a sched_sd.c to add onto your design as well. Well, what do I do with that? I need to create another scheduling policy for that code to even be used. A separate scheduling policy requires a userspace change to even benefit from it. Even if I make that sched_sd.c patch, people cannot use SD as their default scheduler unless they hack SCHED_FAIR 0 to read SCHED_SD 0 or similar. The same goes for original staircase cpusched, nicksched, zaphod, spa_ws, ebs and so on.

So what you've achieved with your patch is - replaced the current scheduler with another one and moved it into another file. There is no choice, and no pluggability, just code trumping.

Do I support this? In this form.... no.

It's not that I don't like your new scheduler. Heck it's beautiful like most of your _serious_ code. It even comes with a catchy name that's bound to give people hard-ons (even though many schedulers aim to be completely fair, yours has been named that for maximum selling power). The complaint I have is that you are not providing quite what you advertise (on the modular front), or perhaps you're advertising it as such to make it look more appealing; I'm not sure.

Since we'll just end up with your code, don't pretend SCHED_NORMAL is anything different, and that this is anything other than your NIH (Not Invented Here) cpu scheduling policy rewrite which will probably end up taking it's position in mainline after yet another truckload of regression/performance tests and so on. I haven't seen an awful lot of comparisons with SD yet, just people jumping on your bandwagon which is fine I guess. Maybe a few tiny tests showing less than 5% variation in their fairness from what I can see. Either way, I already feel you've killed off SD... like pretty much everything else I've done lately. At least I no longer have to try and support my code mostly by myself.

In the interest of putting aside any ego concerns since this is about linux and not me...

Because... You are a hair's breadth away from producing something that I would support, which _does_ do what you say and produces the pluggability we're all begging for with only tiny changes to the code you've already done. Make Kconfig let you choose which sched_*.c gets built into the kernel, and make SCHED_OTHER choose which SCHED_* gets chosen as the default from Kconfig and even choose one of the alternative built in ones with boot parametersyour code has more clout than mine will (ie do exactly what plugsched does). Then we can have 7 schedulers in linux kernel within a few weeks. Oh no! This is the very thing Linus didn't want in specialisation with the cpu schedulers! Does this mean this idea will be vetoed yet again? In all likelihood, yes.

I guess I have lots to put into -ck still... sigh.

Quoted 1 line

Ingo

Signature · 1 line
-ck
#20 lore raw
In reply to Davide Libenzi
Quoted 1 line · William Lee Irwin III
Quoted 1 line

A binomial heap would likely serve your purposes better than rbtrees.

[...]

Quoted 11 lines · Davide Libenzi

Haven't looked at the scheduler code yet, but for a similar problem I use a time ring. The ring has Ns (2 power is better) slots (where tasks are queued - in my case they were som sort of timers), and it has a current base index (Ib), a current base time (Tb) and a time granularity (Tg). It also has a bitmap with bits telling you which slots contains queued tasks. An item (task) that has to be scheduled at time T, will be queued in the slot:
S = Ib + min((T - Tb) / Tg, Ns - 1);
Items with T longer than Ns*Tg will be scheduled in the relative last slot (chosing a proper Ns and Tg can minimize this).
Queueing is O(1) and de-queueing is O(Ns). You can play with Ns and Tg to suite to your needs.

I used a similar sort of queue in the virtual deadline scheduler I wrote in 2003 or thereabouts. CFS uses queue priorities with too high a precision to map directly to this (queue priorities are marked as "key" in the cfs code and should not be confused with task priorities). The elder virtual deadline scheduler used millisecond resolution and a rather different calculation for its equivalent of ->key, which explains how it coped with a limited priority space.

The two basic attacks on such large priority spaces are the near future vs. far future subdivisions and subdividing the priority space into (most often regular) intervals. Subdividing the priority space into intervals is the most obvious; you simply use some O(lg(n)) priority queue as the bucket discipline in the "time ring," queue by the upper bits of the queue priority in the time ring, and by the lower bits in the O(lg(n)) bucket discipline. The near future vs. far future subdivision is maintaining the first N tasks in a low-constant-overhead structure like a sorted list and the remainder in some other sort of queue structure intended to handle large numbers of elements gracefully. The distribution of queue priorities strongly influences which of the methods is most potent, though it should be clear the methods can be used in combination.

-- wli

#21 lore raw
Quoted 7 lines · William Lee Irwin III

The two basic attacks on such large priority spaces are the near future vs. far future subdivisions and subdividing the priority space into (most often regular) intervals. Subdividing the priority space into intervals is the most obvious; you simply use some O(lg(n)) priority queue as the bucket discipline in the "time ring," queue by the upper bits of the queue priority in the time ring, and by the lower bits in the O(lg(n)) bucket discipline.

Sure. If you really need sub-millisecond precision, you can replace the bucket's list_head with an rb_root. It may be not necessary though for a cpu scheduler (still, didn't read Ingo's code yet).

- Davide

#118 lore raw
In reply to Con Kolivas

On Sun, Apr 15, 2007 at 01:27:13PM +1000, Con Kolivas wrote:
...

Quoted 10 lines

Now that you're agreeing my direction was correct you've done the usual Linux kernel thing - ignore all my previous code and write your own version. Oh well, that I've come to expect; at least you get a copyright notice in the bootup and somewhere in the comments give me credit for proving it's possible. Let's give some other credit here too. William Lee Irwin provided the major architecture behind plugsched at my request and I simply finished the work and got it working. He is also responsible for many IRC discussions I've had about cpu scheduling fairness, designs, programming history and code help. Even though he did not contribute code directly to SD, his comments have been invaluable.

Hello folks,

I think the main failure I see here is that Con wasn't included in this design or privately in review process. There could have been better co-ownership of the code. This could also have been done openly on lkml (since this is kind of what this medium is about to significant degree) so that consensus can happen (Con can be reasoned with). It would have achieved the same thing but probably more smoothly if folks just listened, considered an idea and then, in this case, created something that would allow for experimentation from outsiders in a fluid fashion.

If these issues aren't fixed, you're going to stuck with the same kind of creeping elitism that has gradually killed the FreeBSD project and other BSDs. I can't comment on the code implementation. I'm focus on other things now that I'm at NetApp and I can't help out as much as I could. Being former BSDi, I had a first hand account of these issues as they played out.

A development process like this is likely to exclude smart people from wanting to contribute to Linux and folks should be conscious about this issues. It's basically a lot of code and concept that at least two individuals have worked on (wli and con) only to have it be rejected and then sudden replaced by code from a community gatekeeper. In this case, this results in both Con and Bill Irwin being woefully under utilized.

If I were one of these people. I'd be mighty pissed.

bill

#152 lore raw
In reply to Con Kolivas
Quoted 9 lines · Con Kolivas
Quoted 8 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

Quoted 7 lines
Quoted 4 lines

This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.

The casual observer will be completely confused by what on earth has happened here so let me try to demystify things for them.

[...]

Demystify what? The casual observer need only read either your attempt
at writing a scheduler, or my attempts at fixing the one we have, to see that it was high time for someone with the necessary skills to step in. Now progress can happen, which was _not_ happening before.

-Mike

#59 lore raw
In reply to Willy Tarreau
Quoted 4 lines · Willy Tarreau

Well, I'll stop heating the room for now as I get out of ideas about how to defeat it. I'm convinced. I'm impatient to read about Mike's feedback with his workload which behaves strangely on RSDL. If it works OK here, it will be the proof that heuristics should not be needed.

You mean the X + mp3 player + audio visualization test? X+Gforce visualization have problems getting half of my box in the presence of two other heavy cpu using tasks. Behavior is _much_ better than RSDL/SD, but the synchronous nature of X/client seems to be a problem.

With this scheduler, renicing X/client does cure it, whereas with SD it did not help one bit. (I know a trivial way to cure that, and this framework makes that possible without dorking up fairness as a general policy.)

-Mike

#153 lore raw
In reply to Mike Galbraith
Quoted 3 lines · Mike Galbraith

[...]

Demystify what? The casual observer need only read either your attempt

Here's the problem. You're a casual observer and obviously not paying attention.

Quoted 3 lines

at writing a scheduler, or my attempts at fixing the one we have, to see that it was high time for someone with the necessary skills to step in. Now progress can happen, which was _not_ happening before.

I think that's inaccurate and there are plenty of folks that have that technical skill and background. The scheduler code isn't a deep mystery and there are plenty of good kernel hackers out here across many communities. Ingo isn't the only person on this planet to have deep scheduler knowledge. Priority heaps are not new and Solaris has had a pluggable scheduler framework for years.

Con's characterization is something that I'm more prone to believe about how Linux kernel development works versus your view. I think it's a great shame to have folks like Bill Irwin and Con to have waste time trying to do something right only to have their ideas attack, then copied and held as the solution for this kind of technical problem as complete reversal of technical opinion as it suits a moment. This is just wrong in so many ways.

It outlines the problems with Linux kernel development and questionable elistism regarding ownership of certain sections of the kernel code.

I call it "churn squat" and instances like this only support that view which I would rather it be completely wrong and inaccurate instead.

bill

#154 lore raw
Quoted 12 lines · Bill Huey
Quoted 3 lines · Mike Galbraith

[...]

Demystify what? The casual observer need only read either your attempt

Here's the problem. You're a casual observer and obviously not paying attention.

Quoted 3 lines

at writing a scheduler, or my attempts at fixing the one we have, to see that it was high time for someone with the necessary skills to step in. Now progress can happen, which was _not_ happening before.

Quoted 5 lines

I think that's inaccurate and there are plenty of folks that have that technical skill and background. The scheduler code isn't a deep mystery and there are plenty of good kernel hackers out here across many communities. Ingo isn't the only person on this planet to have deep scheduler knowledge.

Ok <shrug>, I'm not paying attention, and you can't read. We're even. Have a nice life.

-Mike

#119 lore raw
In reply to Bill Huey (hui)
Quoted 6 lines · Bill Huey

Hello folks,

I think the main failure I see here is that Con wasn't included in this design or privately in review process. There could have been better co-ownership of the code. This could also have been done openly on lkml [...]

Bill, you come from a BSD background and you are still relatively new to Linux development, so i dont at all fault you for misunderstanding this situation, and fortunately i have a really easy resolution for your
worries: i did exactly that! :)

i wrote the first line of code of the CFS patch this week, 8am Wednesday morning, and released it to lkml 62 hours later, 22pm on Friday. (I've listed the file timestamps of my backup patches further below, for all the fine details.)

I prefer such early releases to lkml _alot_ more than any private review process. I released the CFS code about 6 hours after i thought "okay, this looks pretty good" and i spent those final 6 hours on testing it (making sure it doesnt blow up on your box, etc.), in the final 2 hours i showed it to two folks i could reach on IRC (Arjan and Thomas) and on various finishing touches. It doesnt get much faster than that and i definitely didnt want to sit on it even one day longer because i very much thought that Con and others should definitely see this work!

And i very much credited (and still credit) Con for the whole fairness angle:

||  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!

the 'design consultation' phase you are talking about is _NOW_! :)

I got the v1 code out to Con, to Mike and to many others ASAP. That's how you are able to comment on this thread and be part of the development process to begin with, in a 'private consultation' setup you'd not have had any opportunity to see _any_ of this.

In the BSD space there seem to be more 'political' mechanisms for development, but Linux is truly about doing things out in the open, and doing it immediately.

Okay? ;-)

Here's the timestamps of all my backups of the patch, from its humble 4K beginnings to the 100K first-cut v1 result:

-rw-rw-r-- 1 mingo mingo 4230 Apr 11 08:47 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 7653 Apr 11 09:12 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 7728 Apr 11 09:26 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 14416 Apr 11 10:08 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 24211 Apr 11 10:41 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 27878 Apr 11 10:45 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 33807 Apr 11 11:05 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 34524 Apr 11 11:09 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 39650 Apr 11 11:19 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 40231 Apr 11 11:34 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 40627 Apr 11 11:48 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 40638 Apr 11 11:54 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 42733 Apr 11 12:19 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 42817 Apr 11 12:31 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 43270 Apr 11 12:41 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 43531 Apr 11 12:48 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 44331 Apr 11 12:51 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 45173 Apr 11 12:56 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 45288 Apr 11 12:59 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 45368 Apr 11 13:06 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 45370 Apr 11 13:06 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 45815 Apr 11 13:14 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 45887 Apr 11 13:19 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 45914 Apr 11 13:25 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 45850 Apr 11 13:29 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 49196 Apr 11 13:39 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 64317 Apr 11 13:45 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 64403 Apr 11 13:52 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 65199 Apr 11 14:03 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 65199 Apr 11 14:07 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 68995 Apr 11 14:50 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 69919 Apr 11 15:23 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 71065 Apr 11 16:26 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 70642 Apr 11 16:28 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 72334 Apr 11 16:49 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 71624 Apr 11 17:01 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 71854 Apr 11 17:20 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 73571 Apr 11 17:42 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 74708 Apr 11 17:49 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 74708 Apr 11 17:51 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 75144 Apr 11 17:57 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 80722 Apr 11 18:19 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 80727 Apr 11 18:41 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 80727 Apr 11 18:59 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 89356 Apr 11 21:32 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 95278 Apr 12 08:36 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 97749 Apr 12 10:49 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 97687 Apr 12 10:58 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 97722 Apr 12 11:06 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 97933 Apr 12 11:22 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 98167 Apr 12 12:04 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 98167 Apr 12 12:09 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 100405 Apr 12 12:29 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 100380 Apr 12 12:50 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 101631 Apr 12 13:32 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 102293 Apr 12 14:12 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 102431 Apr 12 14:28 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 102502 Apr 12 14:53 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 102128 Apr 13 11:13 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 102473 Apr 13 12:12 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 102536 Apr 13 12:24 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 102481 Apr 13 12:30 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 103408 Apr 13 13:08 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 103441 Apr 13 13:31 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 104759 Apr 13 14:19 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 104815 Apr 13 14:39 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 104762 Apr 13 15:04 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 105978 Apr 13 16:18 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 105977 Apr 13 16:26 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 106761 Apr 13 17:08 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 106358 Apr 13 17:40 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 107802 Apr 13 19:04 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 104427 Apr 13 19:35 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 103927 Apr 13 19:40 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 101867 Apr 13 20:30 patches/sched-fair.patch -rw-rw-r-- 1 mingo mingo 101011 Apr 13 21:05 patches/sched-fair.patch

i hope this helps :)

Ingo

#60 lore raw
In reply to Mike Galbraith
Quoted 8 lines · Mike Galbraith
Quoted 5 lines · Willy Tarreau

Well, I'll stop heating the room for now as I get out of ideas about how to defeat it. I'm convinced. I'm impatient to read about Mike's feedback with his workload which behaves strangely on RSDL. If it works OK here, it will be the proof that heuristics should not be needed.

Quoted 7 lines

You mean the X + mp3 player + audio visualization test? X+Gforce visualization have problems getting half of my box in the presence of two other heavy cpu using tasks. Behavior is _much_ better than RSDL/SD, but the synchronous nature of X/client seems to be a problem.

With this scheduler, renicing X/client does cure it, whereas with SD it did not help one bit. [...]

thanks for testing it! I was quite worried about your setup - two tasks using up 50%/50% of CPU time, pitted against a kernel rebuild workload seems to be a hard workload to get right.

Quoted 2 lines

[...] (I know a trivial way to cure that, and this framework makes that possible without dorking up fairness as a general policy.)

great! Please send patches so i can add them (once you are happy with the solution) - i think your workload isnt special in any way and could hit other people too.

Ingo

#155 lore raw
In reply to Bill Huey (hui)
Quoted 8 lines · Bill Huey
Quoted 4 lines · Mike Galbraith

[...]

Demystify what? The casual observer need only read either your attempt

Here's the problem. You're a casual observer and obviously not paying attention.

guys, please calm down. Judging by the number of contributions to sched.c the main folks who are not 'observers' here and who thus have an unalienable right to be involved in a nasty flamewar about scheduler interactivity are Con, Mike, Nick and me ;-) Everyone else is just a happy bystander, ok? ;-)

Ingo

#61 lore raw
In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar
Quoted 2 lines · Mike Galbraith

[...] (I know a trivial way to cure that, and this framework makes that possible without dorking up fairness as a general policy.)

great! Please send patches so i can add them (once you are happy with the solution) - i think your workload isnt special in any way and could hit other people too.

I'll give it a shot. (have to read and actually understand your new code first though, then see if it's really viable)

-Mike

#120 lore raw
In reply to Ingo Molnar
Quoted 18 lines · Ingo Molnar

I prefer such early releases to lkml _alot_ more than any private review process. I released the CFS code about 6 hours after i thought "okay, this looks pretty good" and i spent those final 6 hours on testing it (making sure it doesnt blow up on your box, etc.), in the final 2 hours i showed it to two folks i could reach on IRC (Arjan and Thomas) and on various finishing touches. It doesnt get much faster than that and i definitely didnt want to sit on it even one day longer because i very much thought that Con and others should definitely see this work!

And i very much credited (and still credit) Con for the whole fairness angle:

||  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!

the 'design consultation' phase you are talking about is _NOW_! :)

Quoted 8 lines

I got the v1 code out to Con, to Mike and to many others ASAP. That's how you are able to comment on this thread and be part of the development process to begin with, in a 'private consultation' setup you'd not have had any opportunity to see _any_ of this.

In the BSD space there seem to be more 'political' mechanisms for development, but Linux is truly about doing things out in the open, and doing it immediately.

I can't even begin to talk about how screwed up BSD development is. Maybe another time privately.

Ok, Linux development and inclusiveness can be improved. I'm not trying to "call you out" (slang for accusing you with the sole intention to call you crazy in a highly confrontative manner). This is discussed publically here to bring this issue to light, open a communication channel as a means to resolve it.

Quoted 1 line

Okay? ;-)

It's cool. We're still getting to know each other professionally and it's okay to a certain degree to have a communication disconnect but only as long as it clears. Your productivity is amazing BTW. But here's the problem, there's this perception that NIH is the default mentality here in Linux.

Con feels that this kind of action is intentional and has a malicious quality to it as means of "churn squating" sections of the kernel tree. The perception here is that there is that there is this expectation that sections of the Linux kernel are intentionally "churn squated" to prevent any other ideas from creeping in other than of the owner of that subsytem (VM, scheduling, etc...) because of lack of modularity in the kernel. This isn't an API question but a question possibly general code quality and how maintenance () of it can .

This was predicted by folks and then this perception was *realized* when you wrote the equivalent kind of code that has technical overlap with SDL (this is just one dry example). To a person that is writing new code for Linux, having one of the old guards write equivalent code to that of a newcomer has the effect of displacing that person both with regards to code and responsibility with that. When this happens over and over again and folks get annoyed by it, it starts seeming that Linux development seems elitist.

I know this because I heard (read) Con's IRC chats all the time about these matters all of the time. This is not just his view but a view of other kernel folks that differing views as to. The closing talk at OLS 2006 was highly disturbing in many ways. It went "Christoph" is right everybody else is wrong which sends a highly negative message to new kernel developers that, say, don't work for RH directly or any of the other mainstream Linux companies. After a while, it starts seeming like this kind of behavior is completely intentional and that Linux is full of arrogant bastards.

What I would have done here was to contact Peter Williams, Bill Irwin and Con about what your doing and reach a common concensus about how to create something that would be inclusive of all of their ideas. Discussions can technically heated but that's ok, the discussion is happening and it brings down the wall of this perception. Bill and Con are on oftc.net/#offtopic2. Riel is there as well as Peter Zijlstra. It might be very useful, it might not be. Folks are all stubborn about there ideas and hold on to them for dear life. Effective leaders can deconstruct this hostility and animosity. I don't claim to be one.

Because of past hostility to something like schedplugin, the hostility and terseness of responses can be percieved simply as "I'm right, you're wrong" which is condescending. This effects discussion and outright destroys a constructive process if this happens continually since it reenforces that view of "You're an outsider, we don't care about you". Nobody is listening to each other at that point, folks get pissed. Then they think about "I'm going to NIH this person with patc X because he/she did the same here" which is dysfunctional.

Oddly enough, sometimes you're the best person to get a new idea into the tree. What's not happening here is communication. That takes sensitivity, careful listening which is a difficult skill, and then understanding of the characters involved to unify creative energies.

That's a very difficult thing to do for folks that are use to working solo. It take time to develop trust in those relationships so that a true collaboration can happen. I know that there is a lot of creativity in folks like Con and Bill. It would be wise to develop a dialog with them to see if they can offload some of your work for you (we all know you're really busy) yet have you be a key facilitator of their and your ideas. That's a really tough thing to do and it requires practice. Just imagine (assuming they can follow through) what could have positively happened if there collective knowledge was leveraged better. It's not all clear and rosy, but I think these people are more on your side that you might realized and it might be a good thing to discover that.

This is tough because I know the personalities involved and I know kind of how people function and malfunction in this discussion on a personal basis.

[We can continue privately. This not just about you but applicable to open source development in general]

The tone of this email is intellectually critical (not ment as personality attack) and calm. If I'm otherwise, them I'm a bastard. :)

bill

#121 lore raw
Quoted 3 lines · hui Bill Huey

The perception here is that there is that there is this expectation that sections of the Linux kernel are intentionally "churn squated" to prevent any other ideas from creeping in other than of the owner of that subsytem

Strangely enough, my perception is that Ingo is simply trying to address the issues Mike's testing discovered in RDSL and SD. It's not surprising Ingo made it a separate patch set as Con has repeatedly stated that the "problems" are in fact by design and won't be fixed.

#358 lore raw
In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

Quoted 8 lines

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.

[...]

I took a brief look at it. Have you tested priority inheritance?
As far as I can see rt_mutex_setprio doesn't have much effect on SCHED_FAIR/SCHED_BATCH. I am looking for a place where such a task change scheduler class when boosted in rt_mutex_setprio().

Esben

#122 lore raw
In reply to Pekka Enberg
Quoted 9 lines · Pekka Enberg
Quoted 3 lines · hui Bill Huey

The perception here is that there is that there is this expectation that sections of the Linux kernel are intentionally "churn squated" to prevent any other ideas from creeping in other than of the owner of that subsytem

Strangely enough, my perception is that Ingo is simply trying to address the issues Mike's testing discovered in RDSL and SD. It's not surprising Ingo made it a separate patch set as Con has repeatedly stated that the "problems" are in fact by design and won't be fixed.

That's not exactly the problem. There are people who work very hard to try to improve some areas of the kernel. They progress slowly, and acquire more and more skills. Sometimes they feel like they need to change some concepts and propose those changes which are required for them to go further, or to develop faster. Those are rejected. So they are constrained to work in a delimited perimeter from which it is difficult for them to escape.

Then, the same person who rejected their changes comes with something shiny new, better and which took him far less time. But he sort of broke the rules because what was forbidden to the first persons is suddenly permitted. Maybe for very good reasons, I'm not discussing that. The good reason should have been valid the first time too.

The fact is that when changes are rejected, we should not simply say "no", but explain why and define what would be acceptable. Some people here have excellent teaching skills for this, but most others do not. Anyway, the rules should be the same for everybody.

Also, there is what can be perceived as marketting here. Con worked on his idea with convictions, he took time to write some generous documentation, but he hit a wall where his concept was suboptimal on a given workload. But at least, all the work was oriented on a technical basis : design + code + doc.

Then, Ingo comes in with something looking amazingly better, with virtually no documentation, an appealing announcement, and a shiny advertising at boot. All this implemented without the constraints other people had to respect. It already looks like definitive work which will be merge as-is without many changes except a few bugfixes.

If those were two companies, the first one would simply have accused the second one of not having respected contracts and having employed heaving marketting to take the first place.

People here do not code for a living, they do it at least because they believe in what they are doing, and some of them want a bit of gratitude for their work. I've met people who were proud to say they implement this or that feature in the kernel, so it is something important for them. And being cited in an email is nothing compared to advertising at boot time.

When the discussion was blocked between Con and Mike concerning the design problems, it is where a new discussion should have taken place. Ingo could have publicly spoken with them about his ideas of killing the O(1) scheduler and replacing it with an rbtree-based one, and using part of Bill's work to speed up development.

It is far easier to resign when people explain what concepts are wrong and how they think they will do than when they suddenly present something out of nowhere which is already better.

And it's not specific to Ingo (though I think his ability to work that fast alone makes him tend to practise this more often than others).

Imagine if Con had worked another full week on his scheduler with better results on Mike's workload, but still not as good as Ingo's, and they both published at the same time. You certainly can imagine he would have preferred to be informed first that it was pointless to continue in that direction.

Now I hope he and Bill will get over this and accept to work on improving this scheduler, because I really find it smarter than a dumb O(1). I even agree with Mike that we now have a solid basis for future work. But for this, maybe a good starting point would be to remove the selfish printk at boot, revert useless changes (SCHED_NORMAL->SCHED_FAIR come to mind) and improve the documentation a bit so that people can work together on the new design, without feeling like their work will only server to promote X or Y.

Regards,
Willy

#359 lore raw
In reply to Esben Nielsen
Quoted 1 line · Esben Nielsen

I took a brief look at it. Have you tested priority inheritance?

yeah, you are right, it's broken at the moment, i'll fix it. But the good news is that i think PI could become cleaner via scheduling classes.

Quoted 3 lines

As far as I can see rt_mutex_setprio doesn't have much effect on SCHED_FAIR/SCHED_BATCH. I am looking for a place where such a task change scheduler class when boosted in rt_mutex_setprio().

i think via scheduling classes we dont have to do the p->policy and p->prio based gymnastics anymore, we can just have a clean look at p->sched_class and stack the original scheduling class into p->real_sched_class. It would probably also make sense to 'privatize' p->prio into the scheduling class. That way PI would be a pure property of sched_rt, and the PI scheduler would be driven purely by p->rt_priority, not by p->prio. That way all the normal_prio() kind of complications and interactions with SCHED_OTHER/SCHED_FAIR would be eliminated as well. What do you think?

Ingo

#123 lore raw
In reply to Willy Tarreau
Quoted 3 lines · Willy Tarreau

Ingo could have publicly spoken with them about his ideas of killing the O(1) scheduler and replacing it with an rbtree-based one, and using part of Bill's work to speed up development.

He did exactly that and he did it with a patch. Nothing new here. This is how development on LKML proceeds when you have two or more competing designs. There's absolutely no need to get upset or hurt your feelings over it. It's not malicious, it's how we do Linux development.

#313 lore raw
In reply to Con Kolivas

* Con Kolivas <[email protected]> wrote:

[ i'm quoting this bit out of order: ]

Quoted 4 lines

2. Since then I've been thinking/working on a cpu scheduler design that takes away all the guesswork out of scheduling and gives very predictable, as fair as possible, cpu distribution and latency while preserving as solid interactivity as possible within those confines.

yeah. I think you were right on target with this call. I've applied the sched.c change attached at the bottom of this mail to the CFS patch, if you dont mind. (or feel free to suggest some other text instead.)

Quoted 5 lines

1. I tried in vain some time ago to push a working extensable pluggable cpu scheduler framework (based on wli's work) for the linux kernel. It was perma-vetoed by Linus and Ingo (and Nick also said he didn't like it) as being absolutely the wrong approach and that we should never do that. [...]

i partially replied to that point to Will already, and i'd like to make it clear again: yes, i rejected plugsched 2-3 years ago (which already drifted away from wli's original codebase) and i would still reject it today.

First and foremost, please dont take such rejections too personally - i had my own share of rejections (and in fact, as i mentioned it in a previous mail, i had a fair number of complete project throwaways:
4g:4g, in-kernel Tux, irqrate and many others). I know that they can hurt and can demoralize, but if i dont like something it's my job to tell that.

Can i sum up your argument as: "you rejected plugsched, but then why on earth did you modularize portions of the scheduler in CFS? Isnt your position thus woefully inconsistent?" (i'm sure you would never put it this impolitely though, but i guess i can flame myself with impunity ;)

While having an inconsistent position isnt a terminal sin in itself, please realize that the scheduler classes code in CFS is quite different from plugsched: it was a result of what i saw to be technological pressure for _internal modularization_. (This internal/policy modularization aspect is something that Will said was present in his original plugsched code, but which aspect i didnt see in the plugsched patches that i reviewed.)

That possibility never even occured to me to until 3 days ago. You never raised it either AFAIK. No patches to simplify the scheduler that way were ever sent. Plugsched doesnt even touch the core load-balancer for example, and most of the time i spent with the modularization was to get the load-balancing details right. So it's really apples to oranges.

My view about plugsched: first please take a look at the latest plugsched code:

http://downloads.sourceforge.net/cpuse/plugsched-6.5-for-2.6.20.patch

  26 files changed, 8951 insertions(+), 1495 deletions(-)

As an experiment i've removed all the add-on schedulers (both the core and the include files, only kept the vanilla one) from the plugsched patch (and the makefile and kconfig complications, etc), to see the 'infrastructure cost', and it still gave:

  12 files changed, 1933 insertions(+), 1479 deletions(-)

that's the extra complication i didnt like 3 years ago and which i still dont like today. What the current plugsched code does is that it simplifies the adding of new experimental schedulers, but it doesnt really do what i wanted: to simplify the _scheduler itself_. Personally i'm still not primarily interested in having a large selection of schedulers, i'm mainly interested in a good and maintainable scheduler that works for people.

so the rejection was on these grounds, and i still very much stand by that position here and today: i didnt want to see the Linux scheduler landscape balkanized and i saw no technological reasons for the complication that external modularization brings.

the new scheding classes code in the CFS patch was not a result of "oh, i want to write a new scheduler, lets make schedulers pluggable" kind of thinking. That result was just a side-effect of it. (and as you correctly noted it, the CFS related modularization is incomplete).

Btw., the thing that triggered the scheduling classes code wasnt even plugsched or RSDL/SD, it was Mike's patches. Mike had an itch and he fixed it within the framework of the existing scheduler, and the end result behaved quite well when i threw various testloads on it.

But i felt a bit uncomfortable that it added another few hundred lines of code to an already complex sched.c. This felt unnatural so i mailed Mike that i'd attempt to clean these infrastructure aspects of sched.c up a bit so that it becomes more hackable to him. Thus 3 days ago, without having made up my mind about anything, i started this experiment (which ended up in the modularization and in the CFS scheduler) to simplify the code and to enable Mike to fix such itches in an easier way. By your logic Mike should in fact be quite upset about this: if the new code works out and proves to be useful then it obsoletes a whole lot of code of him!

Quoted 4 lines

For weeks now, Ingo has said that the interactivity regressions were showstoppers and we should address them, never mind the fact that the so-called regressions were purely "it slows down linearly with load" which to me is perfectly desirable behaviour. [...]

yes. For me the first thing when considering a large scheduler patch is:
"does a patch do what it claims" and "does it work". If those goals are met (and if it's a complete scheduler i actually try it quite extensively) then i look at the code cleanliness issues. Mike's patch was the first one that seemed to meet that threshold in my own humble testing, and CFS was a direct result of that.

note that i tried the same workloads with CFS and while it wasnt as good as mainline, it handled them better than SD. Mike reported the same, and Mark Lord (who too reported SD interactivity problems) reported success yesterday too.

(but .. CFS is a mere 2 days old so we cannot really tell anything with certainty yet.)

Quoted 6 lines

[...] However at one stage I virtually begged for support with my attempts and help with the code. Dmitry Adamushko is the only person who actually helped me with the code in the interim, while others poked sticks at it. Sure the sticks helped at times but the sticks always seemed to have their ends kerosene doused and flaming for reasons I still don't get. No other help was forthcoming.

i'm really sorry you got that impression.

in 2004 i had a good look at the staircase scheduler and said:

http://www.uwsg.iu.edu/hypermail/linux/kernel/0408.0/1146.html

"But in general i'm quite positive about the staircase scheduler."

and even tested it and gave you feedback:

http://lwn.net/Articles/96562/

i think i even told Andrew that i dont really like pluggable schedulers and if there's any replacement for the current scheduler then that would be a full replacement, and it would be the staircase scheduler.

Hey, i told this to you as recently as 1 month ago as well:

http://lkml.org/lkml/2007/3/8/54

"cool! I like this even more than i liked your original staircase
scheduler from 2 years ago :)"

Ingo

----------->

kernel/sched.c +1 -0
Index: linux/kernel/sched.c
===================================================================
@@ -16,6 +16,7 @@
  *		by Davide Libenzi, preemptible kernel bits by Robert Love.
  *  2003-09-03	Interactivity tuning by Con Kolivas.
  *  2004-04-02	Scheduler domains code by Nick Piggin
+ *  2007-04-15	Con Kolivas was dead right: fairness matters! :)
  */
 
#146 lore raw
In reply to Pekka Enberg
Quoted 9 lines · Pekka Enberg
Quoted 3 lines · hui Bill Huey

The perception here is that there is that there is this expectation that sections of the Linux kernel are intentionally "churn squated" to prevent any other ideas from creeping in other than of the owner of that subsytem

Strangely enough, my perception is that Ingo is simply trying to address the issues Mike's testing discovered in RDSL and SD. It's not surprising Ingo made it a separate patch set as Con has repeatedly stated that the "problems" are in fact by design and won't be fixed.

I won't get into the middle of this just yet, not having decided which dog I should bet on yet. I've been running 2.6.21-rc6 + Con's 0.40 patch for about 24 hours, its been generally usable, but gzip still causes lots of 5 to 10+ second lags when its running. I'm coming to the conclusion that gzip simply doesn't play well with others...

Amazing to me, the cpu its using stays generally below 80%, and often below 60%, even while the kmail composer has a full sentence in its buffer that it still hasn't shown me when I switch to the htop screen to check, and back to the kmail screen to see if its updated yet. The screen switch doesn't seem to lag so I don't think renicing x would be helpfull. Those are the obvious lags, and I'll build & reboot to the CFS patch at some point this morning (whats left of it that is :). And report in due time of course

Signature · 5 lines
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
knot in cables caused data stream to become twisted and kinked
#133 lore raw
In reply to Willy Tarreau
Quoted 8 lines · Willy Tarreau

Now I hope he and Bill will get over this and accept to work on improving this scheduler, because I really find it smarter than a dumb O(1). I even agree with Mike that we now have a solid basis for future work. But for this, maybe a good starting point would be to remove the selfish printk at boot, revert useless changes (SCHED_NORMAL->SCHED_FAIR come to mind) and improve the documentation a bit so that people can work together on the new design, without feeling like their work will only server to promote X or Y.

While I appreciate people coming to my defense, or at least the good intentions behind such, my only actual interest in pointing out 4-year-old work is getting some acknowledgment of having done something relevant at all. Sometimes it has "I told you so" value. At other times it's merely clarifying what went on when people refer to it since in a number of cases the patches are no longer extant, so they can't actually look at it to get an idea of what was or wasn't done. At other times I'm miffed about not being credited, whether I should've been or whether dead and buried code has an implementation of the same idea resurfacing without the author(s) having any knowledge of my prior work.

One should note that in this case, the first work of mine this trips over (scheduling classes) was never publicly posted as it was only a part of the original plugsched (an alternate scheduler implementation devised to demonstrate plugsched's flexibility with respect to scheduling policies), and a part that was dropped by subsequent maintainers. The second work of mine this trips over, a virtual deadline scheduler named "vdls," was also never publicly posted. Both are from around the same time period, which makes them approximately 4 years dead. Neither of the codebases are extant, having been lost in a transition between employers, though various people recall having been sent them privately, and plugsched survives in a mutated form as maintained by Peter Williams, who's been very good about acknowledging my original contribution.

If I care to become a direct participant in scheduler work, I can do so easily enough.

I'm not entirely sure what this is about a basis for future work. By and large one should alter the API's and data structures to fit the policy being implemented. While the array swapping was nice for algorithmically improving 2.4.x -style epoch expiry, most algorithms not based on the 2.4.x scheduler (in however mutated a form) should use a different queue structure, in fact, one designed around their policy's specific algorithmic needs. IOW, when one alters the scheduler, one should also alter the queue data structure appropriately. I'd not expect the priority queue implementation in cfs to continue to be used unaltered as it matures, nor would I expect any significant modification of the scheduler to necessarily use a similar one.

By and large I've been mystified as to why there is such a penchant for preserving the existing queue structures in the various scheduler patches floating around. I am now every bit as mystified at the point of view that seems to be emerging that a change of queue structure is particularly significant. These are all largely internal changes to sched.c, and as such, rather small changes in and of themselves. While they do tend to have user-visible effects, from this point of view even changing out every line of sched.c is effectively a micropatch.

Something more significant might be altering the schedule() API to take a mandatory description of the intention of the call to it, or breaking up schedule() into several different functions to distinguish between different sorts of uses of it to which one would then respond differently. Also more significant would be adding a new state beyond TASK_INTERRUPTIBLE, TASK_UNINTERRUPTIBLE, and TASK_RUNNING for some tasks to respond only to fatal signals, then sweeping TASK_UNINTERRUPTIBLE users to use the new state and handle those fatal signals. While not quite as ostentatious in their user-visible effects as SCHED_OTHER policy affairs, they are tremendously more work than switching out the implementation of a single C file, and so somewhat more respectable.

Even as scheduling semantics go, these are micropatches. So SCHED_OTHER changes a little. Where are the gang schedulers? Where are the batch schedulers (SCHED_BATCH is not truly such)? Where are the isochronous (frame) schedulers? I suppose there is some CKRM work that actually has a semantic impact despite being largely devoted to SCHED_OTHER, and there's some spufs gang scheduling going on, though not all that much. And to reiterate a point from other threads, even as SCHED_OTHER patches go, I see precious little verification that things like the semantics of nice numbers or other sorts of CPU bandwidth allocation between competing tasks of various natures are staying the same while other things are changed, or at least being consciously modified in such a fashion as to improve them. I've literally only seen one or two tests (and rather inflexible ones with respect to sleep and running time mixtures) with any sort of quantification of how CPU bandwidth is distributed get run on all this.

So from my point of view, there's a lot of churn and craziness going on in one tiny corner of the kernel and people don't seem to have a very solid grip on what effects their changes have or how they might potentially break userspace. So I've developed a sudden interest in regression testing of the scheduler in order to ensure that various sorts of semantics on which userspace relies are not broken, and am trying to spark more interest in general in nailing down scheduling semantics and verifying that those semantics are honored and remain honored by whatever future scheduler implementations might be merged.

Thus far, the laundry list of semantics I'd like to have nailed down are specifically:

(1) CPU bandwidth allocation according to nice numbers
(2) CPU bandwidth allocation among mixtures of tasks with varying sleep/wakeup behavior e.g. that consume some percentage of cpu in isolation, perhaps also varying the granularity of their sleep/wakeup patterns
(3) sched_yield(), so multitier userspace locking doesn't go haywire
(4) How these work with SMP; most people agree it should be mostly the same as it works on UP, but it's not being verified, as most testcases are barely SMP-aware if at all, and corner cases where proportionality breaks down aren't considered

The sorts of like explicit decisions I'd like to be made for these are:
(1) In a mixture of tasks with varying nice numbers, a given nice number corresponds to some share of CPU bandwidth. Implementations should not have the freedom to change this arbitrarily according to some intention.
(2) A given scheduler _implementation_ intends to distribute CPU bandwidth among mixtures of tasks that would each consume some percentage of the CPU in isolation varying across tasks in some particular pattern. For example, maybe some scheduler implementation assigns a share of 1/%cpu to a task that would consume %cpu in isolation, for a CPU bandwidth allocation of (1/%cpu)/(sum 1/%cpu(t)) as t ranges over all competing tasks (this is not to say that such a policy makes sense).
(3) sched_yield() is intended to result in some particular scheduling pattern in a given scheduler implementation. For instance, an implementation may intend that a set of CPU hogs calling sched_yield() between repeatedly printf()'ing their pid's will see their printf()'s come out in an approximately consistent order as the scheduler cycles between them.
(4) What an implementation intends to do with respect to SMP CPU bandwidth allocation when precise emulation of UP behavior is impossible, considering sched_yield() scheduling patterns when possible as well. For instance, perhaps an implementation intends to ensure equal CPU bandwidth among competing CPU-bound tasks of equal priority at all costs, and so triggers migration and/or load balancing to make it so. Or perhaps an implementation intends to ensure precise sched_yield() ordering at all costs even on SMP. Some sort of specification of the intention, then a verification that the intention is carried out in a testcase.

Also, if there's a semantic issue to be resolved, I want it to have something describing it and verifying it. For instance, characterizing whatever sort of scheduling artifacts queue-swapping causes in the mainline scheduler and then a testcase to demonstrate the artifact and its resolution in a given scheduler rewrite would be a good design statement and verification. For instance, if someone wants to go back to queue-swapping or other epoch expiry semantics, it would make them (and hopefully everyone else) conscious of the semantic issue the change raises, or possibly serve as a demonstration that the artifacts can be mitigated in some implementation retaining epoch expiry semantics.

As I become aware of more potential issues I'll add more to my laundry list, and I'll hammer out testcases as I go. My concern with the scheduler is that this sort of basic functionality may be significantly disturbed with no one noticing at all until a distro issues a prerelease and benchmarks go haywire, and furthermore that changes to this kind of basic behavior may be signs of things going awry, particularly as more churn happens.

So now that I've clarified my role in all this to date and my point of view on it, it should be clear that accepting something and working on some particular scheduler implementation don't make sense as suggestions to me.

-- wli

#139 lore raw
In reply to Willy Tarreau
Quoted 2 lines · Willy Tarreau

Ingo could have publicly spoken with them about his ideas of killing the O(1) scheduler and replacing it with an rbtree-based one, [...]

yes, that's precisely what i did, via a patchset :)

[ I can even tell you when it all started: i was thinking about Mike's
throttling patches while watching Manchester United beat the crap out of AS Roma (7 to 1 end result), Thuesday evening. I started coding it Wednesday morning and sent the patch Friday evening. I very much believe in low-latency when it comes to development too ;) ]

(if this had been done via a comittee then today we'd probably still be trying to find a suitable timeslot for the initial conference call where we'd discuss the election of a chair who would be tasked with writing up an initial document of feature requests, on which we'd take a vote, possibly this year already, because the matter is really urgent you know ;-)

Quoted 1 line

[...] and using part of Bill's work to speed up development.

ok, let me make this absolutely clear: i didnt use any bit of plugsched
- in fact the most difficult bits of the modularization was for areas of sched.c that plugsched never even touched AFAIK. (the load-balancer for example.)

Plugsched simply does something else: i modularized scheduling policies in essence that have to cooperate with each other, while plugsched modularized complete schedulers which are compile-time or boot-time selected, with no runtime cooperation between them. (one has to be selected at a time)

(and i have no trouble at all with crediting Will's work either: a few years ago i used Will's PID rework concepts for an NPTL related speedup and Will is very much credited for it in today's kernel/pid.c and he continued to contribute to it later on.)

(the tree walking bits of sched_fair.c were in fact derived from kernel/hrtimer.c, the rbtree code written by Thomas and me :-)

Ingo

#140 lore raw
Quoted 1 line · Willy Tarreau
Quoted 1 line

[...] and using part of Bill's work to speed up development.

Quoted 7 lines · Ingo Molnar

ok, let me make this absolutely clear: i didnt use any bit of plugsched
- in fact the most difficult bits of the modularization was for areas of sched.c that plugsched never even touched AFAIK. (the load-balancer for example.)
Plugsched simply does something else: i modularized scheduling policies in essence that have to cooperate with each other, while plugsched modularized complete schedulers which are compile-time or boot-time

Quoted 8 lines

selected, with no runtime cooperation between them. (one has to be selected at a time)
(and i have no trouble at all with crediting Will's work either: a few years ago i used Will's PID rework concepts for an NPTL related speedup and Will is very much credited for it in today's kernel/pid.c and he continued to contribute to it later on.)
(the tree walking bits of sched_fair.c were in fact derived from kernel/hrtimer.c, the rbtree code written by Thomas and me :-)

The extant plugsched patches have nothing to do with cfs; I suspect what everyone else is going on about is terminological confusion. The 4-year-old sample policy with scheduling classes for the original plugsched is something you had no way of knowing about, as it was never publicly posted. There isn't really anything all that interesting going on here, apart from pointing out that it's been done before.

-- wli

#151 lore raw
In reply to Bill Huey (hui)
Quoted 2 lines · In article <[email protected]> you wrote:

A development process like this is likely to exclude smart people from wanting to contribute to Linux and folks should be conscious about this issues.

Nobody is excluded, you can always have a next iteration.

Gruss
Bernd

#83 lore raw

Re: Kaffeine problem with CFS

In reply to S.Çağlar Onur
Quoted 17 lines · S.Çağlar Onur
Quoted 6 lines

hm, could you try to strace it and/or attach gdb to it and figure out what's wrong? (perhaps involving the Kaffeine developers too?) As long as it's not a kernel level crash i cannot see how the scheduler could directly cause this - other than by accident creating a scheduling pattern that triggers a user-space bug more often than with other schedulers.

...

futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = 0
futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = 0
futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = 0
futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = 0
futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = 0
futex(0x89ac218, FUTEX_WAIT, 2, NULL)   = -1 EINTR (Interrupted system call)
killed by SIGINT +++ renamed from SIGINT (Interrupt) @ 0 (0) --- +0 -0
Quoted 3 lines

is where freeze occurs. Full log can be found at [1]

[1] http://cekirdek.pardus.org.tr/~caglar/strace.kaffeine

thanks. This does has the appearance of a userspace race condition of some sorts. Can you trigger this hang with the patch below applied to the vanilla tree as well? (with no CFS patch applied)

if yes then this would suggest that Kaffeine has some sort of child-runs-first problem. (which CFS changes to parent-runs-first. Kaffeine starts a couple of threads and the futex calls are a sign of thread<->thread communication.)

[ i have also Cc:-ed the Kaffeine folks - maybe your strace gives them
an idea about what the problem could be :) ]

Ingo

---
 kernel/sched.c |   70 ++-------------------------------------------------------
 1 file changed, 3 insertions(+), 67 deletions(-)
kernel/sched.c +3 -67
Index: linux/kernel/sched.c
===================================================================
@@ -1653,77 +1653,13 @@ void fastcall sched_fork(struct task_str
  */
 void fastcall wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
 {
-	struct rq *rq, *this_rq;
 	unsigned long flags;
-	int this_cpu, cpu;
+	struct rq *rq;
 
 	rq = task_rq_lock(p, &flags);
 	BUG_ON(p->state != TASK_RUNNING);
-	this_cpu = smp_processor_id();
-	cpu = task_cpu(p);
-
-	/*
-	 * We decrease the sleep average of forking parents
-	 * and children as well, to keep max-interactive tasks
-	 * from forking tasks that are max-interactive. The parent
-	 * (current) is done further down, under its lock.
-	 */
-	p->sleep_avg = JIFFIES_TO_NS(CURRENT_BONUS(p) *
-		CHILD_PENALTY / 100 * MAX_SLEEP_AVG / MAX_BONUS);
-
-	p->prio = effective_prio(p);
-
-	if (likely(cpu == this_cpu)) {
-		if (!(clone_flags & CLONE_VM)) {
-			/*
-			 * The VM isn't cloned, so we're in a good position to
-			 * do child-runs-first in anticipation of an exec. This
-			 * usually avoids a lot of COW overhead.
-			 */
-			if (unlikely(!current->array))
-				__activate_task(p, rq);
-			else {
-				p->prio = current->prio;
-				p->normal_prio = current->normal_prio;
-				list_add_tail(&p->run_list, &current->run_list);
-				p->array = current->array;
-				p->array->nr_active++;
-				inc_nr_running(p, rq);
-			}
-			set_need_resched();
-		} else
-			/* Run child last */
-			__activate_task(p, rq);
-		/*
-		 * We skip the following code due to cpu == this_cpu
-	 	 *
-		 *   task_rq_unlock(rq, &flags);
-		 *   this_rq = task_rq_lock(current, &flags);
-		 */
-		this_rq = rq;
-	} else {
-		this_rq = cpu_rq(this_cpu);
-
-		/*
-		 * Not the local CPU - must adjust timestamp. This should
-		 * get optimised away in the !CONFIG_SMP case.
-		 */
-		p->timestamp = (p->timestamp - this_rq->most_recent_timestamp)
-					+ rq->most_recent_timestamp;
-		__activate_task(p, rq);
-		if (TASK_PREEMPTS_CURR(p, rq))
-			resched_task(rq->curr);
-
-		/*
-		 * Parent and child are on different CPUs, now get the
-		 * parent runqueue to update the parent's ->sleep_avg:
-		 */
-		task_rq_unlock(rq, &flags);
-		this_rq = task_rq_lock(current, &flags);
-	}
-	current->sleep_avg = JIFFIES_TO_NS(CURRENT_BONUS(current) *
-		PARENT_PENALTY / 100 * MAX_SLEEP_AVG / MAX_BONUS);
-	task_rq_unlock(this_rq, &flags);
+	__activate_task(p, rq);
+	task_rq_unlock(rq, &flags);
 }
 
 /*
#84 lore raw

Re: Kaffeine problem with CFS

Quoted 5 lines · Ingo Molnar
Quoted 1 line

[1] http://cekirdek.pardus.org.tr/~caglar/strace.kaffeine

thanks. This does has the appearance of a userspace race condition of some sorts. Can you trigger this hang with the patch below applied to the vanilla tree as well? (with no CFS patch applied)

oops, please use the patch below instead.

Ingo

---
 kernel/sched.c |   69 ++++-----------------------------------------------------
 1 file changed, 5 insertions(+), 64 deletions(-)
kernel/sched.c +5 -64
Index: linux/kernel/sched.c
===================================================================
@@ -1653,77 +1653,18 @@ void fastcall sched_fork(struct task_str
  */
 void fastcall wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
 {
-	struct rq *rq, *this_rq;
 	unsigned long flags;
-	int this_cpu, cpu;
+	struct rq *rq;
 
 	rq = task_rq_lock(p, &flags);
 	BUG_ON(p->state != TASK_RUNNING);
-	this_cpu = smp_processor_id();
-	cpu = task_cpu(p);
-
-	/*
-	 * We decrease the sleep average of forking parents
-	 * and children as well, to keep max-interactive tasks
-	 * from forking tasks that are max-interactive. The parent
-	 * (current) is done further down, under its lock.
-	 */
-	p->sleep_avg = JIFFIES_TO_NS(CURRENT_BONUS(p) *
-		CHILD_PENALTY / 100 * MAX_SLEEP_AVG / MAX_BONUS);
 
 	p->prio = effective_prio(p);
+	__activate_task(p, rq);
+	if (TASK_PREEMPTS_CURR(p, rq))
+		resched_task(rq->curr);
 
-	if (likely(cpu == this_cpu)) {
-		if (!(clone_flags & CLONE_VM)) {
-			/*
-			 * The VM isn't cloned, so we're in a good position to
-			 * do child-runs-first in anticipation of an exec. This
-			 * usually avoids a lot of COW overhead.
-			 */
-			if (unlikely(!current->array))
-				__activate_task(p, rq);
-			else {
-				p->prio = current->prio;
-				p->normal_prio = current->normal_prio;
-				list_add_tail(&p->run_list, &current->run_list);
-				p->array = current->array;
-				p->array->nr_active++;
-				inc_nr_running(p, rq);
-			}
-			set_need_resched();
-		} else
-			/* Run child last */
-			__activate_task(p, rq);
-		/*
-		 * We skip the following code due to cpu == this_cpu
-	 	 *
-		 *   task_rq_unlock(rq, &flags);
-		 *   this_rq = task_rq_lock(current, &flags);
-		 */
-		this_rq = rq;
-	} else {
-		this_rq = cpu_rq(this_cpu);
-
-		/*
-		 * Not the local CPU - must adjust timestamp. This should
-		 * get optimised away in the !CONFIG_SMP case.
-		 */
-		p->timestamp = (p->timestamp - this_rq->most_recent_timestamp)
-					+ rq->most_recent_timestamp;
-		__activate_task(p, rq);
-		if (TASK_PREEMPTS_CURR(p, rq))
-			resched_task(rq->curr);
-
-		/*
-		 * Parent and child are on different CPUs, now get the
-		 * parent runqueue to update the parent's ->sleep_avg:
-		 */
-		task_rq_unlock(rq, &flags);
-		this_rq = task_rq_lock(current, &flags);
-	}
-	current->sleep_avg = JIFFIES_TO_NS(CURRENT_BONUS(current) *
-		PARENT_PENALTY / 100 * MAX_SLEEP_AVG / MAX_BONUS);
-	task_rq_unlock(this_rq, &flags);
+	task_rq_unlock(rq, &flags);
 }
 
 /*
#157 lore raw
In reply to Bill Huey (hui)
Quoted 3 lines

It outlines the problems with Linux kernel development and questionable elistism regarding ownership of certain sections of the kernel code.

I have to step in and disagree here....

Linux is not about who writes the code.

Linux is about getting the best solution for a problem. Who wrote which line of the code is irrelevant in the big picture.

that often means that multiple implementations happen, and that the a darwinistic process decides that the best solution wins.

This darwinistic process often happens in the form of discussion, and that discussion can happen with words or with code. In this case it happened with a code proposal.

To make this specific: it has happened many times to me that when I solved an issue with code, someone else stepped in and wrote a different solution (although that was usually for smaller pieces). Was I upset about that? No! I was happy because my *problem got solved* in the best possible way.

Now this doesn't mean that people shouldn't be nice to each other, not cooperate or steal credits, but I don't get the impression that that is happening here. Ingo is taking part in the discussion with a counter proposal for discussion *on the mailing list*. What more do you want?? If you or anyone else can improve it or do better, take part of this discussion and show what you mean either in words or in code.

Your qualification of the discussion as a elitist takeover... I disagree with that. It's a *discussion*. Now if you agree that Ingo's patch is better technically, you and others should be happy about that because your problem is getting solved better. If you don't agree that his patch is better technically, take part in the technical discussion.

Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#147 lore raw
In reply to Gene Heskett
Quoted 12 lines · Gene Heskett
Quoted 10 lines · Pekka Enberg
Quoted 4 lines · hui Bill Huey

The perception here is that there is that there is this expectation that sections of the Linux kernel are intentionally "churn squated" to prevent any other ideas from creeping in other than of the owner of that subsytem

Strangely enough, my perception is that Ingo is simply trying to address the issues Mike's testing discovered in RDSL and SD. It's not surprising Ingo made it a separate patch set as Con has repeatedly stated that the "problems" are in fact by design and won't be fixed.

Quoted 5 lines

I won't get into the middle of this just yet, not having decided which dog I should bet on yet. I've been running 2.6.21-rc6 + Con's 0.40 patch for about 24 hours, its been generally usable, but gzip still causes lots of 5 to 10+ second lags when its running. I'm coming to the conclusion that gzip simply doesn't play well with others...

Actually Gene I think you're being bitten here by something I/O bound since the cpu usage never tops out. If that's the case and gzip is dumping truckloads of writes then you're suffering something that irks me even more than the scheduler in linux, and that's how much writes hurt just about everything else. Try your testcase with bzip2 instead (since that won't be i/o bound), or drop your dirty ratio to as low as possible which helps a little bit (5% is the minimum)

echo 5 > /proc/sys/vm/dirty_ratio

and finally try the braindead noop i/o scheduler as well.

echo noop > /sys/block/sda/queue/scheduler

(replace sda with your drive obviously).

I'd wager a big one that's what causes your gzip pain. If it wasn't for the fact that I've decided to all but give up ever trying to provide code for mainline again, trying my best to make writes hurt less on linux would be my next big thing [tm].

Oh and for the others watching, (points to vm hackers) I found a bug when playing with the dirty ratio code. If you modify it to allow it drop below 5% but still above the minimum in the vm code, stalls happen somewhere in the vm where nothing much happens for sometimes 20 or 30 seconds worst case scenario. I had to drop a patch in 2.6.19 that allowed the dirty ratio to be set ultra low because these stalls were gross.

Quoted 8 lines

Amazing to me, the cpu its using stays generally below 80%, and often below 60%, even while the kmail composer has a full sentence in its buffer that it still hasn't shown me when I switch to the htop screen to check, and back to the kmail screen to see if its updated yet. The screen switch doesn't seem to lag so I don't think renicing x would be helpfull. Those are the obvious lags, and I'll build & reboot to the CFS patch at some point this morning (whats left of it that is :). And report in due time of course

Signature · 1 line
-ck
#85 lore raw

Re: Kaffeine problem with CFS

In reply to Ingo Molnar

Hi,

2007/4/15, Ingo Molnar <[email protected]>:

Quoted 4 lines · Ingo Molnar
Quoted 2 lines
Quoted 2 lines

[1] http://cekirdek.pardus.org.tr/~caglar/strace.kaffeine

Could you try xine-ui or gxine? Because I suspect rather xine-lib for freezing issues. In any way I think a gdb backtrace would be much nicer - but if you can't reproduce the freeze issue with other xine based players and want to run kaffeine in gdb, you need to execute "gdb --args kaffeine --nofork".

Quoted 7 lines
Quoted 3 lines

thanks. This does has the appearance of a userspace race condition of some sorts. Can you trigger this hang with the patch below applied to the vanilla tree as well? (with no CFS patch applied)

oops, please use the patch below instead.

Ingo

<snip>

Christoph

#148 lore raw
In reply to Con Kolivas
Quoted 31 lines · Con Kolivas
Quoted 12 lines · Gene Heskett
Quoted 10 lines · Pekka Enberg
Quoted 4 lines · hui Bill Huey

The perception here is that there is that there is this expectation that sections of the Linux kernel are intentionally "churn squated" to prevent any other ideas from creeping in other than of the owner of that subsytem

Strangely enough, my perception is that Ingo is simply trying to address the issues Mike's testing discovered in RDSL and SD. It's not surprising Ingo made it a separate patch set as Con has repeatedly stated that the "problems" are in fact by design and won't be fixed.

Quoted 5 lines

I won't get into the middle of this just yet, not having decided which dog I should bet on yet. I've been running 2.6.21-rc6 + Con's 0.40 patch for about 24 hours, its been generally usable, but gzip still causes lots of 5 to 10+ second lags when its running. I'm coming to the conclusion that gzip simply doesn't play well with others...

Actually Gene I think you're being bitten here by something I/O bound since the cpu usage never tops out. If that's the case and gzip is dumping truckloads of writes then you're suffering something that irks me even more than the scheduler in linux, and that's how much writes hurt just about everything else. Try your testcase with bzip2 instead (since that won't be i/o bound), or drop your dirty ratio to as low as possible which helps a little bit (5% is the minimum)

echo 5 > /proc/sys/vm/dirty_ratio

and finally try the braindead noop i/o scheduler as well.

Quoted 8 lines

echo noop > /sys/block/sda/queue/scheduler

(replace sda with your drive obviously).

I'd wager a big one that's what causes your gzip pain. If it wasn't for the fact that I've decided to all but give up ever trying to provide code for mainline again, trying my best to make writes hurt less on linux would be my next big thing [tm].

Chuckle, possibly but then I'm not anything even remotely close to an expert here Con, just reporting what I get. And I just rebooted to 2.6.21-rc6 + sched-mike-5.patch for grins and giggles, or frowns and profanity as the case may call for.

Quoted 6 lines

Oh and for the others watching, (points to vm hackers) I found a bug when playing with the dirty ratio code. If you modify it to allow it drop below 5% but still above the minimum in the vm code, stalls happen somewhere in the vm where nothing much happens for sometimes 20 or 30 seconds worst case scenario. I had to drop a patch in 2.6.19 that allowed the dirty ratio to be set ultra low because these stalls were gross.

I think I'd need a bit of tutoring on how to do that. I recall that one other time, several weeks back, I thought I would try one of those famous echo this

Quoted 1 line

/proc/that ideas that went by on this list, but even though I was root,

apparently /proc was read-only AFAIWC.

Quoted 8 lines
Quoted 8 lines

Amazing to me, the cpu its using stays generally below 80%, and often below 60%, even while the kmail composer has a full sentence in its buffer that it still hasn't shown me when I switch to the htop screen to check, and back to the kmail screen to see if its updated yet. The screen switch doesn't seem to lag so I don't think renicing x would be helpfull. Those are the obvious lags, and I'll build & reboot to the CFS patch at some point this morning (whats left of it that is :). And report in due time of course

And now I wonder if I applied the right patch. This one feels good ATM, but I don't think its the CFS thingy. No, I'm sure of it now, none of the patches I've saved say a thing about CFS. Backtrack up the list time I guess, ignore me for the nonce.

Signature · 7 lines
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Microsoft: Re-inventing square wheels

   -- From a Slashdot.org post
#124 lore raw
In reply to Pekka J Enberg
Quoted 9 lines · Pekka J Enberg
Quoted 3 lines · Willy Tarreau

Ingo could have publicly spoken with them about his ideas of killing the O(1) scheduler and replacing it with an rbtree-based one, and using part of Bill's work to speed up development.

He did exactly that and he did it with a patch. Nothing new here. This is how development on LKML proceeds when you have two or more competing designs. There's absolutely no need to get upset or hurt your feelings over it. It's not malicious, it's how we do Linux development.

Yes. Exactly. This is what it's all about, this is what makes it work.

-Mike

#49 lore raw
In reply to Willy Tarreau
Quoted 7 lines · Willy Tarreau

Well, since I merged the fair-fork patch, I cannot reproduce (in fact, bash forks 1000 processes, then progressively execs scheddos, but it takes some time). So I'm rebuilding right now. But I think that Linus has an interesting clue about GPM and notification before switching the terminal. I think it was enabled in console mode. I don't know how that translates to frozen xterms, but let's attack the problems one at a time.

to debug this, could you try to apply this add-on as well:

http://redhat.com/~mingo/cfs-scheduler/sched-fair-print.patch

with this patch applied you should have a /proc/sched_debug file that prints all runnable tasks and other interesting info from the runqueue.

[ i've refreshed all the patches on the CFS webpage, so if this doesnt
apply cleanly to your current tree then you'll probably have to refresh one of the patches.]

The output should look like this:

Sched Debug Version: v0.01
now at 226761724575 nsecs

cpu: 0

   .nr_running            : 3
   .raw_weighted_load     : 384
   .nr_switches           : 13666
   .nr_uninterruptible    : 0
   .next_balance          : 4294947416
   .curr->pid             : 2179
   .rq_clock              : 241337421233
   .fair_clock            : 7503791206
   .wait_runtime          : 2269918379

runnable tasks:
task | PID | tree-key | -delta | waiting | switches
-----------------------------------------------------------------

 +            cat  2179 7501930066   -1861140    1861140         2
      loop_silent  2149 7503010354    -780852          0       911
      loop_silent  2148 7503510048    -281158     280753       918

now for your workload the list should be considerably larger. If there's starvation going on then the 'switches' field (number of context switches) of one of the tasks would never increase while you have this 'cannot switch consoles' problem.

maybe you'll have to unapply the fair-fork patch to make it trigger again. (fair-fork does not fix anything, so it probably just hides a real bug.)

(i'm meanwhile busy running your scheddos utilities to reproduce it locally as well :)

Ingo

#125 lore raw
In reply to Mike Galbraith
Quoted 8 lines · Mike Galbraith
Quoted 5 lines · Pekka J Enberg

He did exactly that and he did it with a patch. Nothing new here. This is how development on LKML proceeds when you have two or more competing designs. There's absolutely no need to get upset or hurt your feelings over it. It's not malicious, it's how we do Linux development.

Yes. Exactly. This is what it's all about, this is what makes it work.

I obviously agree, but I will also add that one of the most motivating things there *is* in open source is "personal pride".

It's a really good thing, and it means that if somebody shows that your code is flawed in some way (by, for example, making a patch that people claim gets better behaviour or numbers), any *good* programmer that actually cares about his code will obviously suddenly be very motivated to out-do the out-doer!

Does this mean that there will be tension and rivalry? Hell yes. But that's kind of the point. Life is a game, and if you aren't in it to win, what the heck are you still doing here?

As long as it's reasonably civil (I'm not personally a huge believer in being too polite or "politically correct", so I think the "reasonably" is more important than the "civil" part!), and as long as the end result is judged on TECHNICAL MERIT, it's all good.

We don't want to play politics. But encouraging peoples competitive feelings? Oh, yes.

Linus

#149 lore raw
In reply to Gene Heskett
Quoted 4 lines · Gene Heskett

Chuckle, possibly but then I'm not anything even remotely close to an expert here Con, just reporting what I get. And I just rebooted to 2.6.21-rc6 + sched-mike-5.patch for grins and giggles, or frowns and profanity as the case may call for.

Erm, that patch is embarrassingly buggy, so profanity should dominate.

-Mike

#50 lore raw
In reply to Ingo Molnar

Hi Ingo,

Quoted 11 lines · Ingo Molnar
Quoted 7 lines · Willy Tarreau

Well, since I merged the fair-fork patch, I cannot reproduce (in fact, bash forks 1000 processes, then progressively execs scheddos, but it takes some time). So I'm rebuilding right now. But I think that Linus has an interesting clue about GPM and notification before switching the terminal. I think it was enabled in console mode. I don't know how that translates to frozen xterms, but let's attack the problems one at a time.

Quoted 6 lines

to debug this, could you try to apply this add-on as well:

http://redhat.com/~mingo/cfs-scheduler/sched-fair-print.patch

with this patch applied you should have a /proc/sched_debug file that prints all runnable tasks and other interesting info from the runqueue.

I don't know if you have seen my mail from yesterday evening (here). I found that changing keventd prio fixed the problem. You may be interested in the description. I sent it at 21:01 (+200).

Quoted 3 lines

[ i've refreshed all the patches on the CFS webpage, so if this doesnt
apply cleanly to your current tree then you'll probably have to refresh one of the patches.]

Fine, I'll have a look. I already had to rediff the sched-fair-fork patch last time.

Quoted 16 lines

The output should look like this:

Sched Debug Version: v0.01
now at 226761724575 nsecs

cpu: 0

   .nr_running            : 3
   .raw_weighted_load     : 384
   .nr_switches           : 13666
   .nr_uninterruptible    : 0
   .next_balance          : 4294947416
   .curr->pid             : 2179
   .rq_clock              : 241337421233
   .fair_clock            : 7503791206
   .wait_runtime          : 2269918379
Quoted 6 lines

runnable tasks:
task | PID | tree-key | -delta | waiting | switches
-----------------------------------------------------------------

 +            cat  2179 7501930066   -1861140    1861140         2
      loop_silent  2149 7503010354    -780852          0       911
      loop_silent  2148 7503510048    -281158     280753       918

Nice.

Quoted 11 lines

now for your workload the list should be considerably larger. If there's starvation going on then the 'switches' field (number of context switches) of one of the tasks would never increase while you have this 'cannot switch consoles' problem.

maybe you'll have to unapply the fair-fork patch to make it trigger again. (fair-fork does not fix anything, so it probably just hides a real bug.)

(i'm meanwhile busy running your scheddos utilities to reproduce it locally as well :)

I discovered I had the frame-buffer enabled (I did not notice it first because I do not have the logo and the resolution is the same as text). It's matroxfb with a G400, if that can help. It may be possible that it needs some CPU that it cannot get to clear the display before switching, I don't know.

However I won't try this right now, I'm deep in userland at the moment.

Regards,
Willy

#126 lore raw
In reply to Linus Torvalds
Quoted 5 lines · Linus Torvalds

It's a really good thing, and it means that if somebody shows that your code is flawed in some way (by, for example, making a patch that people claim gets better behaviour or numbers), any *good* programmer that actually cares about his code will obviously suddenly be very motivated to out-do the out-doer!

"No one who cannot rejoice in the discovery of his own mistakes deserves to be called a scholar."

--Don Foster, "literary sleuth", on retracting his attribution of "A Funerall Elegye" to Shakespeare (it's more likely John Ford's work).

#51 lore raw
In reply to Willy Tarreau
Quoted 11 lines · Willy Tarreau
Quoted 7 lines

to debug this, could you try to apply this add-on as well:

http://redhat.com/~mingo/cfs-scheduler/sched-fair-print.patch

with this patch applied you should have a /proc/sched_debug file that prints all runnable tasks and other interesting info from the runqueue.

I don't know if you have seen my mail from yesterday evening (here). I found that changing keventd prio fixed the problem. You may be interested in the description. I sent it at 21:01 (+200).

ah, indeed i missed that mail - the response to the patches was quite overwhelming (and i naively thought people dont do Linux hacking over the weekends anymore ;).

so Linus was right: this was caused by scheduler starvation. I can see one immediate problem already: the 'nice offset' is not divided by nr_running as it should. The patch below should fix this but i have yet to test it accurately, this change might as well render nice levels unacceptably ineffective under high loads.

Ingo

--------->

---
 kernel/sched_fair.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched_fair.c +3 -1
Index: linux/kernel/sched_fair.c
===================================================================
@@ -31,7 +31,9 @@ static void __enqueue_task_fair(struct r
 	int leftmost = 1;
 	long long key;
 
-	key = rq->fair_clock - p->wait_runtime + p->nice_offset;
+	key = rq->fair_clock - p->wait_runtime;
+	if (unlikely(p->nice_offset))
+		key += p->nice_offset / rq->nr_running;
 
 	p->fair_key = key;
 
#52 lore raw
Quoted 5 lines · Ingo Molnar

so Linus was right: this was caused by scheduler starvation. I can see one immediate problem already: the 'nice offset' is not divided by nr_running as it should. The patch below should fix this but i have yet to test it accurately, this change might as well render nice levels unacceptably ineffective under high loads.

I've been suggesting testing CPU bandwidth allocation as influenced by nice numbers for a while now for a reason.

-- wli

#57 lore raw
In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

so Linus was right: this was caused by scheduler starvation. I can see one immediate problem already: the 'nice offset' is not divided by nr_running as it should. The patch below should fix this but i have yet to test it accurately, this change might as well render nice levels unacceptably ineffective under high loads.

erm, rather the updated patch below if you want to use this on a 32-bit system. But ... i think you should wait until i have all this re-tested.

Ingo

---
 include/linux/sched.h |    2 +-
 kernel/sched_fair.c   |    4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/sched.h +1 -1
Index: linux/include/linux/sched.h
===================================================================
@@ -839,7 +839,7 @@ struct task_struct {
 
 	s64 wait_runtime;
 	u64 exec_runtime, fair_key;
-	s64 nice_offset, hog_limit;
+	s32 nice_offset, hog_limit;
 
 	unsigned long policy;
 	cpumask_t cpus_allowed;
kernel/sched_fair.c +3 -1
Index: linux/kernel/sched_fair.c
===================================================================
@@ -31,7 +31,9 @@ static void __enqueue_task_fair(struct r
 	int leftmost = 1;
 	long long key;
 
-	key = rq->fair_clock - p->wait_runtime + p->nice_offset;
+	key = rq->fair_clock - p->wait_runtime;
+	if (unlikely(p->nice_offset))
+		key += p->nice_offset / (rq->nr_running + 1);
 
 	p->fair_key = key;
 
#53 lore raw
In reply to William Lee Irwin III
Quoted 9 lines · William Lee Irwin III
Quoted 5 lines · Ingo Molnar

so Linus was right: this was caused by scheduler starvation. I can see one immediate problem already: the 'nice offset' is not divided by nr_running as it should. The patch below should fix this but i have yet to test it accurately, this change might as well render nice levels unacceptably ineffective under high loads.

I've been suggesting testing CPU bandwidth allocation as influenced by nice numbers for a while now for a reason.

Oh I was very much testing "CPU bandwidth allocation as influenced by nice numbers" - it's one of the basic things i do when modifying the scheduler. An automated tool, while nice (all automation is nice) wouldnt necessarily show such bugs though, because here too it needed thousands of running tasks to trigger in practice. Any volunteers? ;)

Ingo

#314 lore raw
In reply to Ingo Molnar
Quoted 4 lines · Ingo Molnar

so the rejection was on these grounds, and i still very much stand by that position here and today: i didnt want to see the Linux scheduler landscape balkanized and i saw no technological reasons for the complication that external modularization brings.

But "balkanization" is a good thing. "Monoculture" is a bad thing.

Look at what happened with I/O scheduling. Opening things up to some new ideas by making it possible to select your I/O scheduler took us from 10 years of stagnation to healthy, competitive development, which gave us a substantially better I/O scheduler.

Look at what's happening right now with TCP congestion algorithms. We've had decades of tweaking Reno slightly now turned into a vibrant research area with lots of radical alternatives. A winner will eventually emerge and it will probably look quite a bit different than Reno.

Similar things have gone on since the beginning with filesystems on Linux. Being able to easily compare filesystems head to head has been immensely valuable in improving our 'core' Linux filesystems.

And what we've had up to now is a scheduler monoculture. Until Andrew put RSDL in -mm, if people wanted to experiment with other schedulers, they had to go well off the beaten path to do it. So all the people who've been hopelessy frustrated with the mainline scheduler go off to the -ck ghetto, or worse, stick with 2.4.

Whether your motivations have been protectionist or merely shortsighted, you've stomped pretty heavily on alternative scheduler development by completely rejecting the whole plugsched concept. If we'd opened up mainline to a variety of schedulers _3 years ago_, we'd probably have gotten to where we are today much sooner.

Hopefully, the next time Rik suggests pluggable page replacement algorithms, folks will actually seriously consider it.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#315 lore raw
Quoted 4 lines · Matt Mackall

Look at what happened with I/O scheduling. Opening things up to some new ideas by making it possible to select your I/O scheduler took us from 10 years of stagnation to healthy, competitive development, which gave us a substantially better I/O scheduler.

actually, 2-3 years ago we already had IO schedulers, and my opinion against plugsched back then (also shared by Nick and Linus) was very much considering them. There are at least 4 reasons why I/O schedulers are different from CPU schedulers:

1) CPUs are a non-persistent resource shared by _all_ tasks and workloads in the system. Disks are _persistent_ resources very much attached to specific workloads. (If tasks had to be 'persistent' to the CPU they were started on we'd have much different scheduling technology, and there would be much less complexity.) More analogous to CPU schedulers would perhaps be VM/MM schedulers, and those tend to be hard to modularize in a technologically sane way too. (and unlike disks there's no good generic way to attach VM/MM schedulers to particular workloads.) So it's apples to oranges.

in practice it comes down to having one good scheduler that runs all workloads on a system reasonably well. And given that a very large portion of system runs mixed workloads, the demand for one good scheduler is pretty high. While i can run with mixed IO schedulers just fine.

2) plugsched did not allow on the fly selection of schedulers, nor did it allow a per CPU selection of schedulers. IO schedulers you can change per disk, on the fly, making them much more useful in practice. Also, IO schedulers (while definitely not being slow!) are alot less performance sensitive than CPU schedulers.

3) I/O schedulers are pretty damn clean code, and plugsched, at least the last version i saw of it, didnt come even close.

4) the good thing that happened to I/O, after years of stagnation isnt I/O schedulers. The good thing that happened to I/O is called Jens Axboe. If you care about the I/O subystem then print that name out and hang it on the wall. That and only that is what mattered.

all in one, while there are definitely uses (embedded would like to have a smaller/different scheduler, etc.), the technical case for modularization for the sake of selectability is alot lower for CPU schedulers than it is for I/O schedulers.

nor was the non-modularity of some piece of code ever an impediment to competition. May i remind you of the pretty competitive SLAB allocator landscape, resulting in things like the SLOB allocator, written by yourself? ;-)

Ingo

#316 lore raw
Quoted 12 lines · Ingo Molnar
Quoted 4 lines · Matt Mackall

Look at what happened with I/O scheduling. Opening things up to some new ideas by making it possible to select your I/O scheduler took us from 10 years of stagnation to healthy, competitive development, which gave us a substantially better I/O scheduler.

actually, 2-3 years ago we already had IO schedulers, and my opinion against plugsched back then (also shared by Nick and Linus) was very much considering them. There are at least 4 reasons why I/O schedulers are different from CPU schedulers:

...

Quoted 2 lines

3) I/O schedulers are pretty damn clean code, and plugsched, at least the last version i saw of it, didnt come even close.

That's irrelevant. Plugsched was an attempt to get alternative schedulers exposure in mainline. I know, because I remember encouraging Bill to pursue it. Not only did you veto plugsched (which may have been a perfectly reasonable thing to do), but you also vetoed the whole concept of multiple schedulers in the tree too. "We don't want to balkanize the scheduling landscape".

And that latter part is what I'm claiming has set us back for years. It's not a technical argument but a strategic one. And it's just not a good strategy.

Quoted 4 lines

4) the good thing that happened to I/O, after years of stagnation isnt I/O schedulers. The good thing that happened to I/O is called Jens Axboe. If you care about the I/O subystem then print that name out and hang it on the wall. That and only that is what mattered.

Disagree. Things didn't actually get interesting until Nick showed up with AS and got it in-tree to demonstrate the huge amount of room we had for improvement. It took several iterations of AS and CFQ (with a couple complete rewrites) before CFQ began to look like the winner. The resulting time-sliced CFQ was fairly heavily influenced by the ideas in AS.

Similarly, things in scheduler land had been pretty damn boring until Con finally got Andrew to take one of his schedulers for a spin.

Quoted 4 lines

nor was the non-modularity of some piece of code ever an impediment to competition. May i remind you of the pretty competitive SLAB allocator landscape, resulting in things like the SLOB allocator, written by yourself? ;-)

Thankfully no one came out and said "we don't want to balkanize the allocator landscape" when I submitted it or I probably would have just dropped it, rather than painfully dragging it along out of tree for years. I'm not nearly the glutton for punishment that Con is. :-P

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#86 lore raw

Re: Kaffeine problem with CFS

In reply to Christoph Pfister

15 Nis 2007 Paz tarihinde, Christoph Pfister şunları yazmıştı:

Quoted 5 lines

Could you try xine-ui or gxine? Because I suspect rather xine-lib for freezing issues. In any way I think a gdb backtrace would be much nicer - but if you can't reproduce the freeze issue with other xine based players and want to run kaffeine in gdb, you need to execute "gdb --args kaffeine --nofork".

I just tested xine-ui and i can easily reproduce exact same problem with xine-ui also so you are right, it seems a xine-lib problem trigger by CFS changes.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

thanks. This does has the appearance of a userspace race condition of some sorts. Can you trigger this hang with the patch below applied to the vanilla tree as well? (with no CFS patch applied)

oops, please use the patch below instead.

Tomorrow i'll test that patch and also try to get a backtrace.

Cheers

Signature · 4 lines
S.Çağlar Onur <[email protected]>
http://cekirdek.pardus.org.tr/~caglar/

Linux is like living in a teepee. No Windows, no Gates and an Apache in house!
#361 lore raw
In reply to Ingo Molnar

Hi,

Quoted 7 lines · On Friday 13 April 2007 23:21:00 Ingo Molnar wrote:

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

Tested this on top of Linus' GIT tree but the system gets very unresponsive during high disk i/o using ext3 as filesystem but even writing a 300mb file to a usb disk (iPod actually) has the same affect.

Regards,
ismail

#127 lore raw
In reply to Jonathan Lundell
Quoted 10 lines · Jonathan Lundell
Quoted 8 lines · Linus Torvalds

It's a really good thing, and it means that if somebody shows that your
code is flawed in some way (by, for example, making a patch that people
claim gets better behaviour or numbers), any *good* programmer that actually cares about his code will obviously suddenly be very motivated to
out-do the out-doer!

Quoted 2 lines

"No one who cannot rejoice in the discovery of his own mistakes deserves to be called a scholar."

Lovely comment. I realise this is not truly directed at me but clearly in the context it has been said people will assume it is directed my way, so while we're all spinning lkml quality rhetoric, let me have a right of reply.

One thing I have never tried to do was to ignore bug reports. I'm forever joking that I keep pulling code out of my arse to improve what I've done. RSDL/SD was no exception; heck it had 40 iterations. The reason I could not reply to bug report A with "Oh that is problem B so I'll fix it with code C" was, as I've said many many times over, health related. I did indeed try to fix many of them without spending hours replying to sometimes unpleasant emails. If health wasn't an issue there might have been 1000 iterations of SD.

There was only ever _one_ thing that I was absolutely steadfast on as a concept that I refused to fix that people might claim was "a mistake I did not rejoice in to be a scholar". That was that the _correct_ behaviour for a scheduler is to be fair such that proportional slowdown with load is (using that awful pun) a feature, not a bug. Now there are people who will still disagree violently with me on that. SD attempted to be a fairness first virtual-deadline design. If I failed on that front, then so be it (and at least one person certainly has said in lovely warm fuzzy friendly communication that I'm a global failure on all fronts with SD). But let me point out now that Ingo's shiny new scheduler is a fairness-first virtual-deadline design which will have proportional slowdown with load. So it will have a very similar feature. I dare anyone to claim that proportional slowdown with load is a bug, because I will no longer feel like I'm standing alone with a BFG9000 trying to defend my standpoint. Others can take up the post at last.

Signature · 1 line
-ck
#362 lore raw
In reply to Ismail Dönmez
Quoted 5 lines · Ismail Dönmez

Hi,

Quoted 3 lines · On Friday 13 April 2007 23:21:00 Ingo Molnar wrote:

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

Quoted 8 lines
Quoted 4 lines

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

Tested this on top of Linus' GIT tree but the system gets very unresponsive during high disk i/o using ext3 as filesystem but even writing a 300mb file to a usb disk (iPod actually) has the same affect.

just to make sure; this exact same workload but with the stock scheduler does not have this effect?

if so, then it could well be that the scheduler is too fair for it's own good (being really fair inevitably ends up not batching as much as one should, and batching is needed to get any kind of decent performance out of disks nowadays)

Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#363 lore raw
Quoted 16 lines · On Monday 16 April 2007 02:23:08 Arjan van de Ven wrote:
Quoted 6 lines · Ismail Dönmez

Hi,

Quoted 3 lines · On Friday 13 April 2007 23:21:00 Ingo Molnar wrote:

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

Quoted 8 lines
Quoted 4 lines

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

Tested this on top of Linus' GIT tree but the system gets very unresponsive during high disk i/o using ext3 as filesystem but even writing a 300mb file to a usb disk (iPod actually) has the same affect.

Quoted 7 lines

just to make sure; this exact same workload but with the stock scheduler does not have this effect?

if so, then it could well be that the scheduler is too fair for it's own good (being really fair inevitably ends up not batching as much as one should, and batching is needed to get any kind of decent performance out of disks nowadays)

Tried with make install in kdepim (which made system sluggish with CFS) and the system is just fine (using CFQ).

Regards,
ismail

#322 lore raw
In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

2) plugsched did not allow on the fly selection of schedulers, nor did it allow a per CPU selection of schedulers. IO schedulers you can change per disk, on the fly, making them much more useful in practice. Also, IO schedulers (while definitely not being slow!) are alot less performance sensitive than CPU schedulers.

One of the reasons I never posted my own code is that it never met its own design goals, which absolutely included switching on the fly. I think Peter Williams may have done something about that. It was my hope to be able to do insmod sched_foo.ko until it became clear that the effort it was intended to assist wasn't going to get even the limited hardware access required, at which point I largely stopped working on it.

Quoted 2 lines · Ingo Molnar

3) I/O schedulers are pretty damn clean code, and plugsched, at least the last version i saw of it, didnt come even close.

I'm not sure what happened there. It wasn't a big enough patch to take hits in this area due to getting overwhelmed by the programming burden like some other efforts of mine. Maybe things started getting ugly once on-the-fly switching entered the picture. My guess is that Peter Williams will have to chime in here, since things have diverged enough from my one-time contribution 4 years ago.

-- wli

#22 lore raw
In reply to Davide Libenzi
Quoted 20 lines · Davide Libenzi

Haven't looked at the scheduler code yet, but for a similar problem I use a time ring. The ring has Ns (2 power is better) slots (where tasks are queued - in my case they were som sort of timers), and it has a current base index (Ib), a current base time (Tb) and a time granularity (Tg). It also has a bitmap with bits telling you which slots contains queued tasks. An item (task) that has to be scheduled at time T, will be queued in the slot:

S = Ib + min((T - Tb) / Tg, Ns - 1);

Items with T longer than Ns*Tg will be scheduled in the relative last slot (chosing a proper Ns and Tg can minimize this).
Queueing is O(1) and de-queueing is O(Ns). You can play with Ns and Tg to suite to your needs.
This is a simple bench between time-ring (TR) and CFS queueing:

http://www.xmailserver.org/smart-queue.c

In my box (Dual Opteron 252):

Quoted 12 lines
davide@alien:~$ ./smart-queue -n 8
CFS = 142.21 cycles/loop
TR  = 72.33 cycles/loop
davide@alien:~$ ./smart-queue -n 16
CFS = 188.74 cycles/loop
TR  = 83.79 cycles/loop
davide@alien:~$ ./smart-queue -n 32
CFS = 221.36 cycles/loop
TR  = 75.93 cycles/loop
davide@alien:~$ ./smart-queue -n 64
CFS = 242.89 cycles/loop
TR  = 81.29 cycles/loop

Hello all,

I cannot help myself to not report results with GAVL tree algorithm there as an another race competitor. I believe, that it is better solution for large priority queues than RB-tree and even heap trees. It could be disputable if the scheduler needs such scalability on the other hand. The AVL heritage guarantees lower height which results in shorter search times which could be profitable for other uses in kernel.

GAVL algorithm is AVL tree based, so it does not suffer from "infinite" priorities granularity there as TR does. It allows use for generalized case where tree is not fully balanced. This allows to cut the first item withour rebalancing. This leads to the degradation of the tree by one more level (than non degraded AVL gives) in maximum, which is still considerably better than RB-trees maximum.

http://cmp.felk.cvut.cz/~pisa/linux/smart-queue-v-gavl.c

The description behind the code is there

http://cmp.felk.cvut.cz/~pisa/ulan/gavl.pdf

The code is part of much more covering uLUt library

http://cmp.felk.cvut.cz/~pisa/ulan/ulut.pdf
http://sourceforge.net/project/showfiles.php?group_id=118937&package_id=130840

I have included all required GAVL code directly into smart-queue-v-gavl.c to provide it for easy testing.

There are tests run on my little dated computer - Duron 600 MHz. Test are run twice to suppress run order influence.

./smart-queue-v-gavl -n 1 -l 2000000
gavl_cfs = 55.66 cycles/loop
CFS = 88.33 cycles/loop
TR = 141.78 cycles/loop
CFS = 90.45 cycles/loop
gavl_cfs = 55.38 cycles/loop

./smart-queue-v-gavl -n 2 -l 2000000
gavl_cfs = 82.85 cycles/loop
CFS = 104.18 cycles/loop
TR = 145.21 cycles/loop
CFS = 102.74 cycles/loop
gavl_cfs = 82.05 cycles/loop

./smart-queue-v-gavl -n 4 -l 2000000
gavl_cfs = 137.45 cycles/loop
CFS = 156.47 cycles/loop
TR = 142.00 cycles/loop
CFS = 152.65 cycles/loop
gavl_cfs = 139.38 cycles/loop

./smart-queue-v-gavl -n 10 -l 2000000
gavl_cfs = 229.22 cycles/loop (WORSE)
CFS = 206.26 cycles/loop
TR = 140.81 cycles/loop
CFS = 208.29 cycles/loop
gavl_cfs = 223.62 cycles/loop (WORSE)

./smart-queue-v-gavl -n 100 -l 2000000
gavl_cfs = 257.66 cycles/loop
CFS = 329.68 cycles/loop
TR = 142.20 cycles/loop
CFS = 319.34 cycles/loop
gavl_cfs = 260.02 cycles/loop

./smart-queue-v-gavl -n 1000 -l 2000000
gavl_cfs = 258.41 cycles/loop
CFS = 393.04 cycles/loop
TR = 134.76 cycles/loop
CFS = 392.20 cycles/loop
gavl_cfs = 260.93 cycles/loop

./smart-queue-v-gavl -n 10000 -l 2000000
gavl_cfs = 259.45 cycles/loop
CFS = 605.89 cycles/loop
TR = 196.69 cycles/loop
CFS = 622.60 cycles/loop
gavl_cfs = 262.72 cycles/loop

./smart-queue-v-gavl -n 100000 -l 2000000
gavl_cfs = 258.21 cycles/loop
CFS = 845.62 cycles/loop
TR = 315.37 cycles/loop
CFS = 860.21 cycles/loop
gavl_cfs = 258.94 cycles/loop

The GAVL code has not been tuned by any "likely"/"unlikely" constructs. It brings even some other overhead from it generic design which is not necessary for this use - it keeps permanently even pointer to the last element, ensures, that the insertion order is preserved for same key values etc. But it still proves much better scalability then kernel used RB-tree code. On the other hand, it does not encode color/height in one of the pointers and requires additional field for height.

May it be, that difference is due some bug in my testing, then I would be interrested in correction. The test case is oversimplified probably. I have already run more different tests against GAVL code in the past to compare it with different tree and queues implementations and I have not found case with real performance degradation. On the other hand, there are cases for small items counts where GAVL is sometimes a little worse than others (array based heap-tree for example).

The GAVL code itself is used in more opensource and commercial projects and we have noticed no problems after one small fix at the time of the first release in 2004.

Best wishes

Pavel Pisa
e-mail: [email protected]
www: http://cmp.felk.cvut.cz/~pisa
work: http://www.pikron.com

#54 lore raw
In reply to Ingo Molnar
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

I've been suggesting testing CPU bandwidth allocation as influenced by nice numbers for a while now for a reason.

Quoted 5 lines · Ingo Molnar

Oh I was very much testing "CPU bandwidth allocation as influenced by nice numbers" - it's one of the basic things i do when modifying the scheduler. An automated tool, while nice (all automation is nice) wouldnt necessarily show such bugs though, because here too it needed thousands of running tasks to trigger in practice. Any volunteers? ;)

Worse comes to worse I might actually get around to doing it myself. Any more detailed descriptions of the test for a rainy day?

-- wli

#150 lore raw
In reply to Mike Galbraith
Quoted 9 lines · Mike Galbraith
Quoted 4 lines · Gene Heskett

Chuckle, possibly but then I'm not anything even remotely close to an expert here Con, just reporting what I get. And I just rebooted to 2.6.21-rc6 + sched-mike-5.patch for grins and giggles, or frowns and profanity as the case may call for.

Erm, that patch is embarrassingly buggy, so profanity should dominate.

-Mike

Chuckle, ROTFLMAO even.

I didn't run it that long as I immediately rebuilt and rebooted when I found I'd used the wrong patch, and in fact had tested that one and found it sub-optimal before I'd built and ran Con's -0.40 version. As for bugs of the type that make it to the screen or logs, I didn't see any. OTOH, my eyesight is slowly going downhill, now 20/25. It was 20/10 30 years ago. Now thats reason for profanity...

Signature · 6 lines
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Unix weanies are as bad at this as anyone.
             -- Larry Wall in <[email protected]>
#323 lore raw
In reply to William Lee Irwin III
Quoted 10 lines · William Lee Irwin III
Quoted 5 lines · Ingo Molnar

2) plugsched did not allow on the fly selection of schedulers, nor did it allow a per CPU selection of schedulers. IO schedulers you can change per disk, on the fly, making them much more useful in practice. Also, IO schedulers (while definitely not being slow!) are alot less performance sensitive than CPU schedulers.

One of the reasons I never posted my own code is that it never met its own design goals, which absolutely included switching on the fly. I think Peter Williams may have done something about that.

I didn't but some students did.

In a previous life, I did implement a runtime configurable CPU scheduling mechanism (implemented on True64, Solaris and Linux) that allowed schedulers to be loaded as modules at run time. This was released commercially on True64 and Solaris. So I know that it can be done.

I have thought about doing something similar for the SPA schedulers which differ in only small ways from each other but lack motivation.

Quoted 11 lines

It was my hope
to be able to do insmod sched_foo.ko until it became clear that the effort it was intended to assist wasn't going to get even the limited hardware access required, at which point I largely stopped working on it.

Quoted 2 lines · Ingo Molnar

3) I/O schedulers are pretty damn clean code, and plugsched, at least the last version i saw of it, didnt come even close.

Quoted 6 lines

I'm not sure what happened there. It wasn't a big enough patch to take hits in this area due to getting overwhelmed by the programming burden like some other efforts of mine. Maybe things started getting ugly once on-the-fly switching entered the picture. My guess is that Peter Williams will have to chime in here, since things have diverged enough from my one-time contribution 4 years ago.

From my POV, the current version of plugsched is considerably simpler than it was when I took the code over from Con as I put considerable effort into minimizing code overlap in the various schedulers.

I also put considerable effort into minimizing any changes to the load balancing code (something Ingo seems to think is a deficiency) and the result is that plugsched allows "intra run queue" scheduling to be easily modified WITHOUT effecting load balancing. To my mind scheduling and load balancing are orthogonal and keeping them that way simplifies things.

As Ingo correctly points out, plugsched does not allow different schedulers to be used per CPU but it would not be difficult to modify it so that they could. Although I've considered doing this over the years I decided not to as it would just increase the complexity and the amount of work required to keep the patch set going. About six months ago I decided to reduce the amount of work I was doing on plugsched (as it was obviously never going to be accepted) and now only publish patches against the vanilla kernel's major releases (and the only reason that I kept doing that is that the download figures indicated that about 80 users were interested in the experiment).

Peter
PS I no longer read LKML (due to time constraints) and would appreciate it if I could be CC'd on any e-mails suggesting scheduler changes.
PPS I'm just happy to see that Ingo has finally accepted that the vanilla scheduler was badly in need of fixing and don't really care who fixes it.
PPS Different schedulers for different aims (i.e. server or work station) do make a difference. E.g. the spa_svr scheduler in plugsched does about 1% better on kernbench than the next best scheduler in the bunch.
PPPS Con, fairness isn't always best as humans aren't very altruistic and we need to give unfair preference to interactive tasks in order to stop the users flinging their PCs out the window. But the current scheduler doesn't do this very well and is also not very good at fairness so needs to change. But the changes need to address interactive response and fairness not just fairness.

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#128 lore raw
In reply to Con Kolivas
Quoted 18 lines · Con Kolivas
Quoted 10 lines · Jonathan Lundell
Quoted 8 lines · Linus Torvalds

It's a really good thing, and it means that if somebody shows that your
code is flawed in some way (by, for example, making a patch that people
claim gets better behaviour or numbers), any *good* programmer that actually cares about his code will obviously suddenly be very motivated to
out-do the out-doer!

Quoted 2 lines

"No one who cannot rejoice in the discovery of his own mistakes deserves to be called a scholar."

Lovely comment. I realise this is not truly directed at me but clearly in the context it has been said people will assume it is directed my way, so while we're all spinning lkml quality rhetoric, let me have a right of reply.

Quoted 8 lines

One thing I have never tried to do was to ignore bug reports. I'm forever joking that I keep pulling code out of my arse to improve what I've done. RSDL/SD was no exception; heck it had 40 iterations. The reason I could not reply to bug report A with "Oh that is problem B so I'll fix it with code C" was, as I've said many many times over, health related. I did indeed try to fix many of them without spending hours replying to sometimes unpleasant emails. If health wasn't an issue there might have been 1000 iterations of SD.

Well what matters is the code and development. I don't think Ingo's scheduler is the final word, although I worry that Linus might jump the gun and merge something "just to give it a test", which we then get stuck with :P

I don't know how anybody can think Ingo's new scheduler is anything but a good thing (so long as it has to compete before being merged). And that's coming from someone who wants *their* scheduler to get merged... I think mine can compete ;) and if it can't, then I'd rather be using the scheduler that beats it.

Quoted 5 lines

There was only ever _one_ thing that I was absolutely steadfast on as a concept that I refused to fix that people might claim was "a mistake I did not rejoice in to be a scholar". That was that the _correct_ behaviour for a scheduler is to be fair such that proportional slowdown with load is (using that awful pun) a feature, not a bug.

If something is using more than a fair share of CPU time, over some macro period, in order to be interactive, then definitely it should get throttled. I've always maintained (since starting scheduler work) that the 2.6 scheduler is horrible because it allows these cases where some things can get more CPU time just by how they behave.

Glad people are starting to come around on that point.

So, on to something productive, we have 3 candidates for a new scheduler so far. How do we decide which way to go? (and yes, I still think switchable schedulers is wrong and a copout) This is one area where it is virtually impossible to discount any decent design on correctness/performance/etc. and even testing in -mm isn't really enough.

#317 lore raw
In reply to Matt Mackall
Quoted 7 lines · Matt Mackall
Quoted 4 lines · Ingo Molnar

4) the good thing that happened to I/O, after years of stagnation isnt I/O schedulers. The good thing that happened to I/O is called Jens Axboe. If you care about the I/O subystem then print that name out and hang it on the wall. That and only that is what mattered.

Quoted 6 lines

Disagree. Things didn't actually get interesting until Nick showed up with AS and got it in-tree to demonstrate the huge amount of room we had for improvement. It took several iterations of AS and CFQ (with a couple complete rewrites) before CFQ began to look like the winner. The resulting time-sliced CFQ was fairly heavily influenced by the ideas in AS.

Well to be fair, Jens had just implemented deadline, which got me interested ;)

Actually, I would still like to be able to deprecate deadline for AS, because AS has a tunable that you can switch to turn off read anticipation and revert to deadline behaviour (or very close to).

It would have been nice if CFQ were then a layer on top of AS that implemented priorities (or vice versa). And then AS could be deprecated and we'd be back to 1 primary scheduler.

Well CFQ seems to be going in the right direction with that, however some large users still find AS faster for some reason...

Anyway, moral of the story is that I think it would have been nice if we hadn't proliferated IO schedulers, however in practice it isn't easy to just layer features on top of each other, and also keeping deadline helped a lot to be able to debug and examine performance regressions and actually get code upstream. And this was true even when it was globally boottine switchable only.

I'd prefer if we kept a single CPU scheduler in mainline, because I think that simplifies analysis and focuses testing. I think we can have one that is good enough for everyone. But if the only other option for progress is that Linus or Andrew just pull one out of a hat, then I would rather merge all of them. Yes I think Con's scheduler should get a fair go, ditto for Ingo's, mine, and anyone else's.

Quoted 9 lines
Quoted 4 lines

nor was the non-modularity of some piece of code ever an impediment to competition. May i remind you of the pretty competitive SLAB allocator landscape, resulting in things like the SLOB allocator, written by yourself? ;-)

Thankfully no one came out and said "we don't want to balkanize the allocator landscape" when I submitted it or I probably would have just dropped it, rather than painfully dragging it along out of tree for years. I'm not nearly the glutton for punishment that Con is. :-P

I don't think this is a fault of the people or the code involved. We just didn't have much collective drive to replace the scheduler, and even less an idea of how to decide between any two of them.

I've kept nicksched around since 2003 or so and no hard feelings ;)

#324 lore raw
In reply to Peter Williams
Quoted 8 lines · William Lee Irwin III
Quoted 8 lines

One of the reasons I never posted my own code is that it never met its own design goals, which absolutely included switching on the fly. I think Peter Williams may have done something about that.
It was my hope
to be able to do insmod sched_foo.ko until it became clear that the effort it was intended to assist wasn't going to get even the limited hardware access required, at which point I largely stopped working on it.

Quoted 7 lines · Peter Williams

I didn't but some students did.
In a previous life, I did implement a runtime configurable CPU scheduling mechanism (implemented on True64, Solaris and Linux) that allowed schedulers to be loaded as modules at run time. This was released commercially on True64 and Solaris. So I know that it can be done. I have thought about doing something similar for the SPA schedulers which differ in only small ways from each other but lack motivation.

Driver models for scheduling are not so far out. AFAICS it's largely a tug-of-war over design goals, e.g. maintaining per-cpu runqueues and switching out intra-queue policies vs. switching out whole-system policies, SMP handling and all. Whether this involves load balancing depends strongly on e.g. whether you have per-cpu runqueues. A 2.4.x scheduler module, for instance, would not have a load balancer at all, as it has only one global runqueue. There are other sorts of policies wanting significant changes to SMP handling vs. the stock load balancing.

Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

I'm not sure what happened there. It wasn't a big enough patch to take hits in this area due to getting overwhelmed by the programming burden like some other efforts of mine. Maybe things started getting ugly once on-the-fly switching entered the picture. My guess is that Peter Williams will have to chime in here, since things have diverged enough from my one-time contribution 4 years ago.

Quoted 9 lines · Peter Williams

From my POV, the current version of plugsched is considerably simpler than it was when I took the code over from Con as I put considerable effort into minimizing code overlap in the various schedulers. I also put considerable effort into minimizing any changes to the load balancing code (something Ingo seems to think is a deficiency) and the result is that plugsched allows "intra run queue" scheduling to be easily modified WITHOUT effecting load balancing. To my mind scheduling and load balancing are orthogonal and keeping them that way simplifies things.

ISTR rearranging things for con in such a fashion that it no longer worked out of the box (though that wasn't the intention; restructuring it to be more suited to his purposes was) and that's what he worked off of afterward. I don't remember very well what changed there as I clearly invested less effort there than the prior versions. Now that I think of it, that may have been where the sample policy demonstrating scheduling classes was lost.

Quoted 10 lines · Peter Williams

As Ingo correctly points out, plugsched does not allow different schedulers to be used per CPU but it would not be difficult to modify it so that they could. Although I've considered doing this over the years I decided not to as it would just increase the complexity and the amount of work required to keep the patch set going. About six months ago I decided to reduce the amount of work I was doing on plugsched (as it was obviously never going to be accepted) and now only publish patches against the vanilla kernel's major releases (and the only reason that I kept doing that is that the download figures indicated that about 80 users were interested in the experiment).

That's a rather different goal from what I was going on about with it, so it's all diverged quite a bit. Where I had a significant need for mucking with the entire concept of how SMP was handled, this is rather different. At this point I'm questioning the relevance of my own work, though it was already relatively marginal as it started life as an attempt at a sort of debug patch to help gang scheduling (which is in itself a rather marginally relevant feature to most users) code along.

Quoted 6 lines · Peter Williams

PS I no longer read LKML (due to time constraints) and would appreciate it if I could be CC'd on any e-mails suggesting scheduler changes. PPS I'm just happy to see that Ingo has finally accepted that the vanilla scheduler was badly in need of fixing and don't really care who fixes it.
PPS Different schedulers for different aims (i.e. server or work

Quoted 8 lines

station) do make a difference. E.g. the spa_svr scheduler in plugsched does about 1% better on kernbench than the next best scheduler in the bunch. PPPS Con, fairness isn't always best as humans aren't very altruistic and we need to give unfair preference to interactive tasks in order to stop the users flinging their PCs out the window. But the current scheduler doesn't do this very well and is also not very good at fairness so needs to change. But the changes need to address interactive response and fairness not just fairness.

Kernel compiles not so useful a benchmark. SDET, OAST, AIM7, etc. are better ones. I'd not bother citing kernel compile results.

In any event, I'm not sure what to say about different schedulers for different aims. My intentions with plugsched were not centered around production usage or intra-queue policy. I'm relatively indifferent to the notion of having pluggable CPU schedulers, intra-queue or otherwise, in mainline. I don't see any particular harm in it, but neither am I particularly motivated to have it in. I had a rather strong sense of instrumentality about it, and since it became useless to me (at a conceptual level; the implementation was never finished ot the point of dynamic loading of scheduler modules) for assisting development on large systems via reboot avoidance by dint of it becoming clear that access to such was never going to happen, I've stopped looking at it.

-- wli

#129 lore raw
In reply to Nick Piggin
Quoted 5 lines · Nick Piggin

So, on to something productive, we have 3 candidates for a new scheduler so far. How do we decide which way to go? (and yes, I still think switchable schedulers is wrong and a copout) This is one area where it is virtually impossible to discount any decent design on correctness/performance/etc. and even testing in -mm isn't really enough.

We're in agreement! YAY!

Actually this is simpler than that. I'm taking SD out of the picture. It has served it's purpose of proving that we need to seriously address all the scheduling issues and did more than a half decent job at it. Unfortunately I also cannot sit around supporting it forever by myself. My own life is more important, so consider SD not even running the race any more.

I'm off to continue maintaining permanent-out-of-tree leisurely code at my own pace. What's more is, I think I'll just stick to staircase Gen I version blah and shelve SD and try to have fond memories of SD as an intellectual prompting exercise only.

Signature · 1 line
-ck
#130 lore raw
Quoted 15 lines · Con Kolivas
Quoted 5 lines · Nick Piggin

So, on to something productive, we have 3 candidates for a new scheduler so far. How do we decide which way to go? (and yes, I still think switchable schedulers is wrong and a copout) This is one area where it is virtually impossible to discount any decent design on correctness/performance/etc. and even testing in -mm isn't really enough.

We're in agreement! YAY!

Actually this is simpler than that. I'm taking SD out of the picture. It has served it's purpose of proving that we need to seriously address all the scheduling issues and did more than a half decent job at it. Unfortunately I also cannot sit around supporting it forever by myself. My own life is more important, so consider SD not even running the race any more.

Quoted 4 lines

I'm off to continue maintaining permanent-out-of-tree leisurely code at my own pace. What's more is, I think I'll just stick to staircase Gen I version blah and shelve SD and try to have fond memories of SD as an intellectual prompting exercise only.

Well I would hope that _if_ we decide to switch schedulers, then you get a chance to field something (and I hope you will decide to and have time to), and I hope we don't rush into the decision.

We've had the current scheduler for so many years now that it is much more important to make sure we take the time to do the right thing rather than absolutely have to merge a new scheduler right now ;)

#356 lore raw
In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar
Quoted 4 lines · Con Kolivas

2. Since then I've been thinking/working on a cpu scheduler design that takes away all the guesswork out of scheduling and gives very predictable, as fair as possible, cpu distribution and latency while preserving as solid interactivity as possible within those confines.

yeah. I think you were right on target with this call.

Yay thank goodness :) It's time to fix the damn cpu scheduler once and for all. Everyone uses this; it's no minor driver or $bigsmp or $bigram or $small_embedded_RT_hardware feature.

Quoted 7 lines

I've applied the
sched.c change attached at the bottom of this mail to the CFS patch, if you dont mind. (or feel free to suggest some other text instead.)

  *  2003-09-03	Interactivity tuning by Con Kolivas.
  *  2004-04-02	Scheduler domains code by Nick Piggin
+ *  2007-04-15	Con Kolivas was dead right: fairness matters! :)

LOL that's awful. I'd prefer something meaningful like "Work begun on replacing all interactivity tuning with a fair virtual-deadline design by Con Kolivas".

While you're at it, it's worth getting rid of a few slightly pointless name changes too. Don't rename SCHED_NORMAL yet again, and don't call all your things sched_fair blah_fair __blah_fair and so on. It means that anything else is by proxy going to be considered unfair. Leave SCHED_NORMAL as is, replace the use of the word _fair with _cfs. I don't really care how many copyright notices you put into our already noisy bootup but it's redundant since there is no choice; we all get the same cpu scheduler.

Quoted 10 lines
Quoted 5 lines

1. I tried in vain some time ago to push a working extensable pluggable cpu scheduler framework (based on wli's work) for the linux kernel. It was perma-vetoed by Linus and Ingo (and Nick also said he didn't like it) as being absolutely the wrong approach and that we should never do that. [...]

i partially replied to that point to Will already, and i'd like to make it clear again: yes, i rejected plugsched 2-3 years ago (which already drifted away from wli's original codebase) and i would still reject it today.

No that was just me being flabbergasted by what appeared to be you posting your own plugsched. Note nowhere in the 40 iterations of rsdl->sd did I ask/suggest for plugsched. I said in my first announcement my aim was to create a scheduling policy robust enough for all situations rather than fantastic a lot of the time and awful sometimes. There are plenty of people ready to throw out arguments for plugsched now and I don't have the energy to continue that fight (I never did really).

But my question still stands about this comment:

Quoted 2 lines

case, all of SD's logic could be added via a kernel/sched_sd.c module as well, if Con is interested in such an approach. ]

What exactly would be the purpose of such a module that governs nothing in particular? Since there'll be no pluggable scheduler by your admission it has no control over SCHED_NORMAL, and would require another scheduling policy for it to govern which there is no express way to use at the moment and people tend to just use the default without great effort.

Quoted 6 lines

First and foremost, please dont take such rejections too personally - i had my own share of rejections (and in fact, as i mentioned it in a previous mail, i had a fair number of complete project throwaways:
4g:4g, in-kernel Tux, irqrate and many others). I know that they can hurt and can demoralize, but if i dont like something it's my job to tell that.

Hmm? No that's not what this is about. Remember dynticks which was not originally my code but I tried to bring it up to mainline standard which I fought with for months? You came along with yet another rewrite from scratch and the flaws in the design I was working with were obvious so I instantly bowed down to that and never touched my code again. I didn't ask for credit back then, but obviously brought the requirement for a no idle tick implementation to the table.

Quoted 5 lines

My view about plugsched: first please take a look at the latest plugsched code:

http://downloads.sourceforge.net/cpuse/plugsched-6.5-for-2.6.20.patch

Quoted 8 lines
  26 files changed, 8951 insertions(+), 1495 deletions(-)

As an experiment i've removed all the add-on schedulers (both the core and the include files, only kept the vanilla one) from the plugsched patch (and the makefile and kconfig complications, etc), to see the 'infrastructure cost', and it still gave:

  12 files changed, 1933 insertions(+), 1479 deletions(-)

I do not see extra code per-se as being a bad thing. I've heard said a few times before "ever notice how when the correct solution is done it is a lot more code than the quick hack that ultimately fails?". Insert long winded discussion of perfect is the enemy of good here, _but_ I'm not arguing perfect versus good, I'm talking about solid code versus quick fix. Again, none of this comment is directed specifically at this implementation of plugsched, its code quality or intent, but using "extra code is bad" as an argument is not enough.

Quoted 12 lines

By your logic Mike should in fact be quite upset about this: if the new code works out and proves to be useful then it obsoletes a whole lot of code of him!

Quoted 6 lines

[...] However at one stage I virtually begged for support with my attempts and help with the code. Dmitry Adamushko is the only person who actually helped me with the code in the interim, while others poked sticks at it. Sure the sticks helped at times but the sticks always seemed to have their ends kerosene doused and flaming for reasons I still don't get. No other help was forthcoming.

Quoted 6 lines

Hey, i told this to you as recently as 1 month ago as well:

http://lkml.org/lkml/2007/3/8/54

"cool! I like this even more than i liked your original staircase
scheduler from 2 years ago :)"

Email has an awful knack of disguising intent so I took that on face value that you did like the idea :).

Above when I said "no other help was forthcoming" all I was hoping for was really simple obvious bugfixes to help me along while I was laid up in bed such as "I like what you're doing but oh your use of memset here is bogus, here is a one line patch". I wasn't specifically expecting you to fix my code; you've got truckloads of things you need to do.

It just reminds me that the concept of "release early, release often" doesn't actually work in the kernel. What is far more obvious is "release code only when it's so close to perfect that noone can argue against it" since most of the work is done by one person, otherwise someone will come out with a counterpatch that is _complete_ earlier but in all possibility not as good, it's just ready sooner. *NOTE* In no way am I saying your code is not as good as mine; I would have to say exactly the opposite is true pretty much always (<sarcasm>conversely then I doubt if I dropped you in my work environment you'd do as good a job as I do</sarcasm>). At one stage wli (again at my request) put together a quick hack to check for non-preemptible regions within the kernel. From that quick hack you adopted it and turned it into that beautiful latency tracer that is the cornerstone of the -rt tree testing. However, there are many instances I've seen good evolving code in the linux kernel be trumped by not-as-good but already-working alternatives written from scratch with no reference to the original work. This is the NIH (not invented here) mechanism I see happening that is worth objecting to.

What you may find most amusing is the very first iterations of RSDL looked _nothing_ like the mainline scheduler. There were all sorts of different structures, mechanisms, one priority array, plans to remove scheduler_tick entirely and so on. Most of those were never made for public consumption. I spent about half a dozen iterations of RSDL removing all of that and making it as close to the mainline design as possible, thus minimising the size of the patch, and to make it readily readable for most people familiar with the scheduler policy code in sched.c (all 5 of them). I should have just said bugger it and started everything from scratch with little to no reference to the original scheduler but found myself obliged to try to do things the minimal code patch size readable difference thingy that was valued in linux kernel development. I think the radically different approach would have been better in the long run. Trying to play ball I ruined it.

Either way I've decided for myself, my family, my career and my sanity I'm abandoning SD. I will shelve SD and try to have fond memories of SD as an intellectual prompting exercise only

Quoted 1 line

Ingo

Signature · 1 line
-ck
#158 lore raw
In reply to Arjan van de Ven
Quoted 4 lines · Arjan van de Ven

Now this doesn't mean that people shouldn't be nice to each other, not cooperate or steal credits, but I don't get the impression that that is happening here. Ingo is taking part in the discussion with a counter proposal for discussion *on the mailing list*. What more do you want??

Con should have been CCed from the first moment this was put into motion to limit the perception of exclusion. That was mistake number one and big time failures to understand this dynamic. After it was Con's idea. Why the hell he was excluded from Ingo's development process is baffling to me and him (most likely).

He put int a lot of effort into SDL and his experiences with scheduling should still be seriously considered in this development process even if he doesn't write a single line of code from this moment on.

What should have happened is that our very busy associate at RH by the name of Ingo Molnar should have leverage more of Con's and Bill's work and use them as a proxy for his own ideas. They would have loved to have contributed more and our very busy Ingo Molnar would have gotten a lot of his work and ideas implemented without him even opening a single source file for editting. They would have happily done this work for Ingo. Ingo could have been used for something else more important like making KVM less of a freaking ugly hack and we all would have benefitted from this.

He could have been working on SystemTap so that you stop losing accounts to Sun and Solaris 10's Dtrace. He could have been working with Riel to fix your butt ugly page scanning problem causing horrible contention via the Clock/Pro algorithm, etc... He could have been fixing the ugly futex rwsem mapping problem that's killing -rt and anything that uses Posix threads. He could have created a userspace thread control block (TCB) with Mr. Drepper so that we can turn off preemption in userspace (userspace per CPU local storage) and implement a very quick non-kernel crossing implementation of priority ceilings (userspace check for priority and flags at preempt_schedule() in the TCB) so that our -rt Posix API doesn't suck donkey shit... Need I say more ?

As programmers like Ingo get spread more thinly, he needs super smart folks like Bill Irwin and Con to help him out and learn to resist NIH folk's stuff out of some weird fear. When this happens, folks like Ingo must learn to "facilitate" development in addition to implementing it with those kind of folks.

This takes time and practice to entrust folks to do things for him. Ingo is the best method of getting new Linux kernel ideas and communicate them to Linus. His value goes beyond just just code and is often the biggest hammer we have in the Linux community to get stuff into the kernel. "Facilitation" of others is something that solo programmers must need when groups like the Linux kernel get larger and large every year.

Understand ? Are we in embarrassing agreement here ?

bill

#23 lore raw
In reply to Pavel Pisa
Quoted 17 lines · Pavel Pisa

I cannot help myself to not report results with GAVL tree algorithm there as an another race competitor. I believe, that it is better solution for large priority queues than RB-tree and even heap trees. It could be disputable if the scheduler needs such scalability on the other hand. The AVL heritage guarantees lower height which results in shorter search times which could be profitable for other uses in kernel.

GAVL algorithm is AVL tree based, so it does not suffer from "infinite" priorities granularity there as TR does. It allows use for generalized case where tree is not fully balanced. This allows to cut the first item withour rebalancing. This leads to the degradation of the tree by one more level (than non degraded AVL gives) in maximum, which is still considerably better than RB-trees maximum.

Quoted 1 line

http://cmp.felk.cvut.cz/~pisa/linux/smart-queue-v-gavl.c

Here are the results on my Opteron 252:

Testing N=1
gavl_cfs = 187.20 cycles/loop
CFS = 194.16 cycles/loop
TR = 314.87 cycles/loop
CFS = 194.15 cycles/loop
gavl_cfs = 187.15 cycles/loop

Testing N=2
gavl_cfs = 268.94 cycles/loop
CFS = 305.53 cycles/loop
TR = 313.78 cycles/loop
CFS = 289.58 cycles/loop
gavl_cfs = 266.02 cycles/loop

Testing N=4
gavl_cfs = 452.13 cycles/loop
CFS = 518.81 cycles/loop
TR = 311.54 cycles/loop
CFS = 516.23 cycles/loop
gavl_cfs = 450.73 cycles/loop

Testing N=8
gavl_cfs = 609.29 cycles/loop
CFS = 644.65 cycles/loop
TR = 308.11 cycles/loop
CFS = 667.01 cycles/loop
gavl_cfs = 592.89 cycles/loop

Testing N=16
gavl_cfs = 686.30 cycles/loop
CFS = 807.41 cycles/loop
TR = 317.20 cycles/loop
CFS = 810.24 cycles/loop
gavl_cfs = 688.42 cycles/loop

Testing N=32
gavl_cfs = 756.57 cycles/loop
CFS = 852.14 cycles/loop
TR = 301.22 cycles/loop
CFS = 876.12 cycles/loop
gavl_cfs = 758.46 cycles/loop

Testing N=64
gavl_cfs = 831.97 cycles/loop
CFS = 997.16 cycles/loop
TR = 304.74 cycles/loop
CFS = 1003.26 cycles/loop
gavl_cfs = 832.83 cycles/loop

Testing N=128
gavl_cfs = 897.33 cycles/loop
CFS = 1030.36 cycles/loop
TR = 295.65 cycles/loop
CFS = 1035.29 cycles/loop
gavl_cfs = 892.51 cycles/loop

Testing N=256
gavl_cfs = 963.17 cycles/loop
CFS = 1146.04 cycles/loop
TR = 295.35 cycles/loop
CFS = 1162.04 cycles/loop
gavl_cfs = 966.31 cycles/loop

Testing N=512
gavl_cfs = 1029.82 cycles/loop
CFS = 1218.34 cycles/loop
TR = 288.78 cycles/loop
CFS = 1257.97 cycles/loop
gavl_cfs = 1029.83 cycles/loop

Testing N=1024
gavl_cfs = 1091.76 cycles/loop
CFS = 1318.47 cycles/loop
TR = 287.74 cycles/loop
CFS = 1311.72 cycles/loop
gavl_cfs = 1093.29 cycles/loop

Testing N=2048
gavl_cfs = 1153.03 cycles/loop
CFS = 1398.84 cycles/loop
TR = 286.75 cycles/loop
CFS = 1438.68 cycles/loop
gavl_cfs = 1149.97 cycles/loop

There seem to be some difference from your numbers. This is with:

gcc version 4.1.2

and -O2. But then and Opteron can behave quite differentyl than a Duron on a bench like this ;)

- Davide

#357 lore raw
In reply to Con Kolivas

On Monday 16 April 2007, Con Kolivas wrote:

And I snipped, Sorry fellas.

Con's original submission was to me, quite an improvement. But I have to say it, and no denegration of your efforts is intended Con, but you did 'pull the trigger' and get this thing rolling by scratching the itch & drawing attention to an ugly lack of user interactivity that had crept into the 2.6 family. So from me to Con, a tip of the hat, and a deep bow in your direction, thank you. Now, you have done what you aimed to do, so please get well.

I've now been through most of an amanda session using Ingo's "CFS" and I have to say that it is another improvement over your 0.40 that's is just as obvious as your first patch was against the stock scheduler. No other scheduler yet has allowed the full utilization of the cpu, and maintained user interactivity as well as this one has, my cpu is running about 5 degrees F hotter just from this effect alone. gzip, if the rest of the system is in between tasks, is consistently showing around 95%, but let anything else stick up its hand, like procmail etc, and gzip now dutifully steps aside, dropping into the 40% range until procmail and spamd are done, at which point there is no rest for the wicked and the cpu never gets a chance to cool.

There was, just now, a pause of about 2 seconds, while amanda moved a tarball from the holding disk area on /dev/hda to the vtapes disk on /dev/hdd, so that would have been an I/O bound situation.

This one Ingo, even without any other patches and I think I did see one go by in this thread which I didn't apply, is a definite keeper. Sweet even.

Signature · 6 lines
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
A word to the wise is enough.
		-- Miguel de Cervantes
#159 lore raw
In reply to Bill Huey (hui)
Quoted 11 lines · Bill Huey
Quoted 4 lines · Arjan van de Ven

Now this doesn't mean that people shouldn't be nice to each other, not cooperate or steal credits, but I don't get the impression that that is happening here. Ingo is taking part in the discussion with a counter proposal for discussion *on the mailing list*. What more do you want??

Con should have been CCed from the first moment this was put into motion to limit the perception of exclusion. That was mistake number one and big time failures to understand this dynamic. After it was Con's idea. Why the hell he was excluded from Ingo's development process is baffling to me and him (most likely).

Ingo's scheduler is completely different to any I've seen proposed for Linux. And after he did an initial implementation, he did post it to everyone.

Maybe something he said offended someone, but the process followed is exactly how Linux kernel development works (ie. if you think you can do better, then write the code). Sometimes you can give suggestions, but other times if you come up with a different idea then it is better just to do it yourself.

Con's code is still out there. If it is better than Ingo's then it should win out. Nobody has a monopoly on schedulers or ideas or posting patches.

Quoted 14 lines

He put int a lot of effort into SDL and his experiences with scheduling should still be seriously considered in this development process even if he doesn't write a single line of code from this moment on.

What should have happened is that our very busy associate at RH by the name of Ingo Molnar should have leverage more of Con's and Bill's work and use them as a proxy for his own ideas. They would have loved to have contributed more and our very busy Ingo Molnar would have gotten a lot of his work and ideas implemented without him even opening a single source file for editting. They would have happily done this work for Ingo. Ingo could have been used for something else more important like making KVM less of a freaking ugly hack and we all would have benefitted from this.

Quoted 11 lines

He could have been working on SystemTap so that you stop losing accounts to Sun and Solaris 10's Dtrace. He could have been working with Riel to fix your butt ugly page scanning problem causing horrible contention via the Clock/Pro algorithm, etc... He could have been fixing the ugly futex rwsem mapping problem that's killing -rt and anything that uses Posix threads. He could have created a userspace thread control block (TCB) with Mr. Drepper so that we can turn off preemption in userspace (userspace per CPU local storage) and implement a very quick non-kernel crossing implementation of priority ceilings (userspace check for priority and flags at preempt_schedule() in the TCB) so that our -rt Posix API doesn't suck donkey shit... Need I say more ?

Well that's some pretty strong criticism of Linux and of someone who does a great deal to improve things... Let's stick to the topic of schedulers in this thread and try keeping it constructive.

#142 lore raw
In reply to Peter Williams
Quoted 2 lines · Peter Williams

Are your new patches available somewhere for easy download or do I have to try to dig them out of the mailing list archive? Or could you mail them to me separately? I'm keen to see how you new scheduler proposal works.

Forget about this. I found the patch.

After a quick look, I like a lot of what I see especially the removal of the dual arrays in the run queue.

Some minor suggestions:

1. having defined DEFAULT_PRIO in sched.h shouldn't you use it to initialize the task structure in init_task.h.
2. the on_rq field in the task structure is unnecessary as many years of experience with ingosched in plugsched indicates that !list_empty(&(p)->run_list does the job provided list_del_init() is used when dequeueing and there is no noticeable overhead incurred so there's no gain by caching the result. Also it removes the possibility of errors creeping in due the value of on_rq being inconsistent with the task's actual state.
3. having modular load balancing is a good idea but it should be decoupled form the scheduler and provided as a separate interface. This would enable different schedulers to use the same load balancer if they desired.
4. why rename SCHED_OTHER to SCHED_FAIR? SCHED_OTHER's supposed to be fair(ish) anyway.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#132 lore raw
In reply to a message not in the archive
Quoted 13 lines · Matthew Hawkins
Quoted 5 lines · Nick Piggin

So, on to something productive, we have 3 candidates for a new scheduler so
far. How do we decide which way to go? (and yes, I still think switchable schedulers is wrong and a copout)

I'm with you on that one. It sounds good as a concept however there's various kernel structures etc that simply cannot be altered at runtime, which throws away the only advantage I can see of plugsched - a test/debug framework.

Quoted 11 lines

I think the best way is for those working on this stuff to keep producing their separate patches against mainline and people being encouraged to test. THEN
(and here comes the fun part) subsystem maintainers have to be prepared to accept code that is not their own or that of their IRC buddies. I'm noticing this disturbing trend that Linux kernel development is becoming more and more like BSD where only the elite few ever get anywhere. Con Kolivas, having a medical not CS degree, bruises the egos of those with CS degrees when he comes up with fairly clean, working, and widely-tested implementations of things like the staircase scheduler, R(SD)L, SCHED_ISO, swap prefetch, etc. when they can't. We should be encouraging guys like

The thing is, it is really hard for anybody to change anything in page reclaim or CPU scheduler. A few people saying a change is good for them doesn't really mean anything because of the huge amount of diversity in usages.

I've got my own CPU scheduler for 4 years and I and a few others think it is better than mainline. I've tried to make many many VM changes that haven't gone in.

Add to that, I don't actually know or care what sort of education most kernel hackers have. I do know at least one of the more brilliant ones does not have a CS degree, and I was able to get quite a few things in before I had a degree (eg. rewrote IO scheduler and multiprocessor CPU scheduler).

Quoted 1 line

It's all about the patches, baby

I don't know what would give anyone the idea that it isn't... patches and numbers.

Nick

#143 lore raw
In reply to Peter Williams
Quoted 6 lines · Peter Williams
Quoted 2 lines · Peter Williams

Are your new patches available somewhere for easy download or do I have to try to dig them out of the mailing list archive? Or could you mail them to me separately? I'm keen to see how you new scheduler proposal works.

Forget about this. I found the patch.

Quoted 8 lines

After a quick look, I like a lot of what I see especially the removal of the dual arrays in the run queue.

Some minor suggestions:

1. having defined DEFAULT_PRIO in sched.h shouldn't you use it to initialize the task structure in init_task.h.
2. the on_rq field in the task structure is unnecessary as many years of experience with ingosched in plugsched indicates that !list_empty(&(p)->run_list does the job provided list_del_init() is used when dequeueing and there is no noticeable overhead incurred so there's no gain by caching the result. Also it removes the possibility of errors creeping in due the value of on_rq being inconsistent with the task's actual state.
3. having modular load balancing is a good idea but it should be decoupled form the scheduler and provided as a separate interface. This would enable different schedulers to use the same load balancer if they desired.
4. why rename SCHED_OTHER to SCHED_FAIR? SCHED_OTHER's supposed to be fair(ish) anyway.

One more quick comment. The claim that there is no concept of time slice in the new scheduler is only true in the sense of the rather arcane implementation of time slices extant in the O(1) scheduler. Your new parameter sched_granularity_ns is equivalent to the concept of time slice in most other kernels that I've peeked inside and computing literature in general (going back over several decades e.g. the magic garden).

Welcome to the mainstream,
Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#141 lore raw
In reply to Ingo Molnar
Quoted 12 lines · Ingo Molnar
Quoted 1 line · Willy Tarreau

Ingo could have publicly spoken with them about his ideas of killing the O(1) scheduler and replacing it with an rbtree-based one, [...]

yes, that's precisely what i did, via a patchset :)

[ I can even tell you when it all started: i was thinking about Mike's
throttling patches while watching Manchester United beat the crap out of AS Roma (7 to 1 end result), Thuesday evening. I started coding it Wednesday morning and sent the patch Friday evening. I very much believe in low-latency when it comes to development too ;) ]

Quoted 7 lines

(if this had been done via a comittee then today we'd probably still be trying to find a suitable timeslot for the initial conference call where we'd discuss the election of a chair who would be tasked with writing up an initial document of feature requests, on which we'd take a vote, possibly this year already, because the matter is really urgent you know ;-)

Quoted 1 line

[...] and using part of Bill's work to speed up development.

ok, let me make this absolutely clear: i didnt use any bit of plugsched
- in fact the most difficult bits of the modularization was for areas of sched.c that plugsched never even touched AFAIK. (the load-balancer for example.)

This sounds like your new scheduler intends to increase the coupling between scheduling and load balancing. I think that this would be a mistake and lead (down the track) to spiralling complexity as you make changes to the code to address the corner conditions that it will create.

Quoted 2 lines

Plugsched simply does something else: i modularized scheduling policies in essence that have to cooperate with each other, while plugsched modularized complete schedulers which are compile-time or boot-time selected, with no runtime cooperation between them. (one has to be selected at a time)

You can't really have more than one scheduler operating in the same priority range on the same CPU as they will be fighting each other trying to achieve their separate and not necessarily compatible (in fact highly likely to be incompatible) aims. Multiple schedulers on the same CPU have to have a pecking order just like SCHED_OTHER and real time policies. It wouldn't be hard to prove that SCHED_RR and SCHED_FIFO is a problem in waiting if ever someone tried to use them both on a highly real time system.

Quoted 6 lines

(and i have no trouble at all with crediting Will's work either: a few years ago i used Will's PID rework concepts for an NPTL related speedup and Will is very much credited for it in today's kernel/pid.c and he continued to contribute to it later on.)

(the tree walking bits of sched_fair.c were in fact derived from kernel/hrtimer.c, the rbtree code written by Thomas and me :-)

Ingo

Are your new patches available somewhere for easy download or do I have to try to dig them out of the mailing list archive? Or could you mail them to me separately? I'm keen to see how you new scheduler proposal works.

Thanks
Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#325 lore raw
In reply to William Lee Irwin III
Quoted 15 lines · William Lee Irwin III
Quoted 8 lines · William Lee Irwin III
Quoted 8 lines

One of the reasons I never posted my own code is that it never met its own design goals, which absolutely included switching on the fly. I think Peter Williams may have done something about that.
It was my hope
to be able to do insmod sched_foo.ko until it became clear that the effort it was intended to assist wasn't going to get even the limited hardware access required, at which point I largely stopped working on it.

Quoted 3 lines · Peter Williams

I didn't but some students did.
In a previous life, I did implement a runtime configurable CPU scheduling mechanism (implemented on True64, Solaris and Linux) that allowed schedulers to be loaded as modules at run time. This was released commercially on True64 and Solaris. So I know that it can be done. I have thought about doing something similar for the SPA schedulers which differ in only small ways from each other but lack motivation.

Quoted 9 lines

Driver models for scheduling are not so far out. AFAICS it's largely a tug-of-war over design goals, e.g. maintaining per-cpu runqueues and switching out intra-queue policies vs. switching out whole-system policies, SMP handling and all. Whether this involves load balancing depends strongly on e.g. whether you have per-cpu runqueues. A 2.4.x scheduler module, for instance, would not have a load balancer at all, as it has only one global runqueue. There are other sorts of policies wanting significant changes to SMP handling vs. the stock load balancing.

Well a single run queue removes the need for load balancing but has scalability issues on large systems. Personally, I think something in between would be the best solution i.e. multiple run queues but more than one CPU per run queue. I think that this would be a particularly good solution to the problems introduced by hyper threading and multi core systems and also NUMA systems. E.g. if all CPUs in a hyper thread package are using the one queue then the case where one CPU is trying to run a high priority task and the other a low priority task (i.e. the cases that the sleeping dependent mechanism tried to address) is less likely to occur.

By the way, I think that it's a very bad idea for the scheduling mechanism and the load balancing mechanism to be coupled. The anomalies that will be experienced and the attempts to make ad hoc fixes for them will lead to complexity spiralling out of control.

Quoted 14 lines
Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

I'm not sure what happened there. It wasn't a big enough patch to take hits in this area due to getting overwhelmed by the programming burden like some other efforts of mine. Maybe things started getting ugly once on-the-fly switching entered the picture. My guess is that Peter Williams will have to chime in here, since things have diverged enough from my one-time contribution 4 years ago.

Quoted 2 lines · Peter Williams

From my POV, the current version of plugsched is considerably simpler than it was when I took the code over from Con as I put considerable effort into minimizing code overlap in the various schedulers.
I also put considerable effort into minimizing any changes to the load balancing code (something Ingo seems to think is a deficiency) and the result is that plugsched allows "intra run queue" scheduling to be easily modified WITHOUT effecting load balancing. To my mind scheduling and load balancing are orthogonal and keeping them that way simplifies things.

Quoted 7 lines

ISTR rearranging things for con in such a fashion that it no longer worked out of the box (though that wasn't the intention; restructuring it to be more suited to his purposes was) and that's what he worked off of afterward. I don't remember very well what changed there as I clearly invested less effort there than the prior versions. Now that I think of it, that may have been where the sample policy demonstrating scheduling classes was lost.

I can't comment here as (as far as I can recall) I never saw your code and only became involved when Con posted his version of cpusched.

Quoted 7 lines · Peter Williams
Quoted 1 line

As Ingo correctly points out, plugsched does not allow different schedulers to be used per CPU but it would not be difficult to modify it so that they could. Although I've considered doing this over the years I decided not to as it would just increase the complexity and the amount of work required to keep the patch set going. About six months ago I decided to reduce the amount of work I was doing on plugsched (as it was obviously never going to be accepted) and now only publish patches against the vanilla kernel's major releases (and the only reason that I kept doing that is that the download figures indicated that about 80 users were interested in the experiment).

That's a rather different goal from what I was going on about with it, so it's all diverged quite a bit.

Yes, pragmatic considerations dictated a change of tack.

Quoted 3 lines

Where I had a significant need for
mucking with the entire concept of how SMP was handled, this is rather different.

Yes, I went with the idea of intra run queue scheduling being orthogonal to load balancing for two reasons:

1. I think that coupling them is a bad idea from the complexity POV, and
2. it's enough of a battle fighting for modifications to one bit of the code without trying to do it to two simultaneously.

Quoted 4 lines

At this point I'm questioning the relevance of my own work, though it was already relatively marginal as it started life as an attempt at a sort of debug patch to help gang scheduling (which is in itself a rather marginally relevant feature to most users) code along.

The main commercial plug in scheduler used with the run time loadable module scheduler that I mentioned earlier did gang scheduling (at the insistence of the Tru64 kernel folks). As this scheduler was a hierarchical "fair share" scheduler: i.e. allocating CPU "fairly" ("unfairly" really in according to an allocation policy) among higher level entities such as users, groups and applications as well as processes; it was fairly easy to make it a gang scheduler by modifying it to give all of a process's threads the same priority based on the process's CPU usage rather than different priorities based on the threads' usage rates. In fact, it would have been possible to select between gang and non gang on a per process basis if that was considered desirable.

The fact that threads and processes are distinct entities on Tru64 and Solaris made this easier to do on them than on Linux.

My experience with this scheduler leads me to believe that to achieve gang scheduling and fairness, etc. you need (usage) statistics based schedulers.

Quoted 10 lines · Peter Williams
Quoted 4 lines

PS I no longer read LKML (due to time constraints) and would appreciate it if I could be CC'd on any e-mails suggesting scheduler changes.
PPS I'm just happy to see that Ingo has finally accepted that the vanilla scheduler was badly in need of fixing and don't really care who fixes it.
PPS Different schedulers for different aims (i.e. server or work station) do make a difference. E.g. the spa_svr scheduler in plugsched does about 1% better on kernbench than the next best scheduler in the bunch.
PPPS Con, fairness isn't always best as humans aren't very altruistic and we need to give unfair preference to interactive tasks in order to stop the users flinging their PCs out the window. But the current scheduler doesn't do this very well and is also not very good at fairness so needs to change. But the changes need to address interactive response and fairness not just fairness.

Kernel compiles not so useful a benchmark. SDET, OAST, AIM7, etc. are better ones. I'd not bother citing kernel compile results.

spa_svr actually does its best work when the system isn't fully loaded as the type of improvement it strives to achieve (minimizing on queue wait time) hasn't got much room to manoeuvre when the system is fully loaded. Therefore, the fact that it's 1% better even in these circumstances is a good result and also indicates that the overhead for keeping the scheduling statistics it uses for its decision making is well spent. Especially, when you consider that the total available room for improvement on this benchmark is less than 3%.

To elaborate, the motivation for this scheduler was acquired from the observation of scheduling statistics (in particular, on queue wait time) on systems running at about 30% to 50% load. Theoretically, at these load levels there should be no such waiting but the statistics show that there is considerable waiting (sometimes as high as 30% to 50%). I put this down to "lack of serendipity" e.g. everyone sleeping at the same time and then trying to run at the same time would be complete lack of serendipity. On the other hand, if everyone is synced then there would be total serendipity.

Obviously, from the POV of a client, time the server task spends waiting on the queue adds to the response time for any request that has been made so reduction of this time on a server is a good thing(tm). Equally obviously, trying to achieve this synchronization by asking the tasks to cooperate with each other is not a feasible solution and some external influence needs to be exerted and this is what spa_svr does -- it nudges the scheduling order of the tasks in a way that makes them become well synced.

Unfortunately, this is not a good scheduler for an interactive system as it minimizes the response times for ALL tasks (and the system as a whole) and this can result in increased response time for some interactive tasks (clunkiness) which annoys interactive users. When you start fiddling with this scheduler to bring back "interactive unfairness" you kill a lot of its superior low overall wait time performance.

So this is why I think "horses for courses" schedulers are worth while.

Quoted 7 lines

In any event, I'm not sure what to say about different schedulers for different aims. My intentions with plugsched were not centered around production usage or intra-queue policy. I'm relatively indifferent to the notion of having pluggable CPU schedulers, intra-queue or otherwise, in mainline. I don't see any particular harm in it, but neither am I particularly motivated to have it in.

If you look at the struct sched_spa_child in the file include/linux/sched_spa.h you'll see that the interface for switching between the various SPA schedulers is quite small and making them runtime switchable would be easy (I haven't done this in cpusched as I wanted to keep the same interface for switching schedulers for all schedulers: i.e. all run time switchable or none run time switchable; as the main aim of plugsched had become a mechanism for evaluating different intra queue scheduling designs.)

Quoted 6 lines

I had a rather strong sense of
instrumentality about it, and since it became useless to me (at a conceptual level; the implementation was never finished ot the point of dynamic loading of scheduler modules) for assisting development on large systems via reboot avoidance by dint of it becoming clear that access to such was never going to happen, I've stopped looking at it.

I'll probably stop looking at this problem as well at least for the time being until all this new code has settled.

Peter
PS As I no longer read LKML, I haven't yet seen Ingo's or Con's or Nick's new schedulers yet so am unable to comment on their technical merits with respect to my comments above.

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#360 lore raw
In reply to Ingo Molnar
Quoted 13 lines · Ingo Molnar
Quoted 1 line · Esben Nielsen

I took a brief look at it. Have you tested priority inheritance?

yeah, you are right, it's broken at the moment, i'll fix it. But the good news is that i think PI could become cleaner via scheduling classes.

Quoted 3 lines

As far as I can see rt_mutex_setprio doesn't have much effect on SCHED_FAIR/SCHED_BATCH. I am looking for a place where such a task change scheduler class when boosted in rt_mutex_setprio().

Quoted 10 lines

i think via scheduling classes we dont have to do the p->policy and p->prio based gymnastics anymore, we can just have a clean look at p->sched_class and stack the original scheduling class into p->real_sched_class. It would probably also make sense to 'privatize' p->prio into the scheduling class. That way PI would be a pure property of sched_rt, and the PI scheduler would be driven purely by p->rt_priority, not by p->prio. That way all the normal_prio() kind of complications and interactions with SCHED_OTHER/SCHED_FAIR would be eliminated as well. What do you think?

Now I have not read your patch into detail. But agree it would be nice to have it more "OO" and remove cross references between schedulers. But first one should consider wether PI between SCHED_FAIR tasks or not is usefull or not. Does PI among dynamic priorities make sense at all? I think it
does: On heavy loaded systems where a nice 19 might not get the CPU for very long, a nice -20 task can be priority inverted for a very long time.
But I see no need it taking the dynamic part of the effective priorities into account. The current/old solution of mapping the static nice values into a global priority index which can incorporate the two scheduler classes is probably good enough - it just has to be "switched on" a again :-)

But what about other scheduler classes which some people want to add in the future? What about having a "cleaner design"?

My thought was to generalize the concept of 'priority' to be an
object (a struct prio) to be interpreted with help from a scheduler class instead of globally interpreted integer.

int compare_prio(struct prio *a, struct prio *b)

{
	if (a->sched_class->class_prio < b->sched_class->class_prio)
		return -1;

	if (a->sched_class->class_prio < b->sched_class->class_prio)
		return +1;


	return a->sched_class->compare_prio(a, b);

}

Problem 1: Performance.

Problem 2: Operations on a plist with these generalized priorities are not bounded because the number of different priorites are not bounded.

Problem 2 could be solved by using a combined plist (for rt priorities) and rbtree (for fair priorities) - making operations logarithmic just as the fair scheduler itself. But that would take more memory for every rtmutex.

I conclude that is too complicated and go on to the obvious idea:
Use a global priority index where each scheduler class get's it own range (rt: 0-99, fair 100-139 :-). Let the scheduler class have a function returning it instead of reading it directly from task_struct such that new scheduler classes can return their own numbers.

Esben

Quoted 2 lines

Ingo

#144 lore raw
In reply to Peter Williams
Quoted 3 lines · Peter Williams

One more quick comment. The claim that there is no concept of time slice in the new scheduler is only true in the sense of the rather arcane implementation of time slices extant in the O(1) scheduler.

yeah. AFAIK most other mainstream OSs also still often use similarly 'arcane' concepts (i'm here ignoring literature, you can find everything and its opposite suggested in literature) so i felt the need to point out the difference ;) After all Linux is about doing a better mainstream OS, it is not about beating the OS literature at lunacy ;-)

The precise statement would be: "there's no concept of giving out a time-slice to a task and sticking to it unless a higher-prio task comes along, nor is there a concept of having a low-res granularity ->time_slice thing. There is accurate accounting of how much CPU time a task used up, and there is a granularity setting that together gives the current task a fairness advantage of a given amount of nanoseconds - which has similar [but not equivalent] effects to traditional timeslices that most mainstream OSs use".

Quoted 4 lines

Your new parameter sched_granularity_ns is equivalent to the concept of time slice in most other kernels that I've peeked inside and computing literature in general (going back over several decades e.g. the magic garden).

note that you can set it to 0 and the box still functions - so sched_granularity_ns, while useful for performance/bandwidth workloads, isnt truly inherent to the design.

So in the announcement i just opted for a short sentence: "there's no concept of timeslices", albeit like most short stentences it's not a technically 100% accurate statement - but still it conveyed the intended information more effectively to the interested lkml reader than the longer version could ever have =B-)

Ingo

#145 lore raw
Quoted 7 lines · Ingo Molnar
Quoted 1 line · Peter Williams

One more quick comment. The claim that there is no concept of time slice in the new scheduler is only true in the sense of the rather arcane implementation of time slices extant in the O(1) scheduler.

yeah. AFAIK most other mainstream OSs also still often use similarly 'arcane' concepts (i'm here ignoring literature, you can find everything and its opposite suggested in literature) so i felt the need to point out the difference ;) After all Linux is about doing a better mainstream OS, it is not about beating the OS literature at lunacy ;-)

The precise statement would be: "there's no concept of giving out a time-slice to a task and sticking to it unless a higher-prio task comes along,

I would have said "no concept of using tile slices to implement nice" which always seemed strange to me.

If it really does what you just said then a (malicious or otherwise) CPU intensive task that never sleeps, once it got the CPU, would completely hog the CPU.

Quoted 3 lines

nor is there a concept of having a low-res granularity
->time_slice thing. There is accurate accounting of how much CPU time a
task used up, and there is a granularity setting that together gives the current task a fairness advantage of a given amount of nanoseconds - which has similar [but not equivalent] effects to traditional timeslices that most mainstream OSs use".

Most traditional OSes have more or less fixed time slices and do the scheduling by fiddling the dynamic priority.

Using total CPU used will also come to grief when used for long running tasks. Eventually, even very low bandwidth tasks will accumulate enough total CPU to look busy. The CPU bandwidth the task is using is what needs to be controlled.

Or have I not looked closely enough at what sched_granularity_ns does? Is it really a control for the decay rate of a CPU usage bandwidth metric?

Quoted 4 lines
Quoted 2 lines

Your new parameter sched_granularity_ns is equivalent to the concept of time slice in most other kernels that I've peeked inside and computing literature in general (going back over several decades e.g. the magic garden).

note that you can set it to 0 and the box still functions - so sched_granularity_ns, while useful for performance/bandwidth workloads, isnt truly inherent to the design.

Just like my SPA schedulers. But if you set it to zero you'll get a fairly high context switch rate with associated overhead, won't you?

Quoted 2 lines

So in the announcement i just opted for a short sentence: "there's no concept of timeslices", albeit like most short stentences it's not a technically 100% accurate statement - but still it conveyed the intended information more effectively to the interested lkml reader than the longer version could ever have =B-)

I hope that I implied that I was being picky :-) (I meant to -- imply I was being picky, that is).

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#156 lore raw
In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

guys, please calm down. Judging by the number of contributions to sched.c the main folks who are not 'observers' here and who thus have an unalienable right to be involved in a nasty flamewar about scheduler interactivity are Con, Mike, Nick and me ;-) Everyone else is just a happy bystander, ok? ;-)

just to make sure: this is a short (and incomplete) list of contributors related to scheduler interactivity code. The full list of contributors to sched.c includes many other people as well: Peter, Suresh, Christoph, Kenneth and many others. Even the git logs, which only span 2 years out of 15, already list 79 individual contributors to kernel/sched.c.

Ingo

#326 lore raw
In reply to Peter Williams
Quoted 9 lines · William Lee Irwin III
Quoted 9 lines

Driver models for scheduling are not so far out. AFAICS it's largely a tug-of-war over design goals, e.g. maintaining per-cpu runqueues and switching out intra-queue policies vs. switching out whole-system policies, SMP handling and all. Whether this involves load balancing depends strongly on e.g. whether you have per-cpu runqueues. A 2.4.x scheduler module, for instance, would not have a load balancer at all, as it has only one global runqueue. There are other sorts of policies wanting significant changes to SMP handling vs. the stock load balancing.

Quoted 10 lines · Peter Williams

Well a single run queue removes the need for load balancing but has scalability issues on large systems. Personally, I think something in between would be the best solution i.e. multiple run queues but more than one CPU per run queue. I think that this would be a particularly good solution to the problems introduced by hyper threading and multi core systems and also NUMA systems. E.g. if all CPUs in a hyper thread package are using the one queue then the case where one CPU is trying to run a high priority task and the other a low priority task (i.e. the cases that the sleeping dependent mechanism tried to address) is less likely to occur.

This wasn't meant to sing the praises of the 2.4.x scheduler; it was rather meant to point out that the 2.4.x scheduler, among others, is unimplementable within the framework if it assumes per-cpu runqueues. More plausibly useful single-queue schedulers would likely use a vastly different policy and attempt to carry out all queue manipulations via lockless operations.

Quoted 4 lines · Peter Williams

By the way, I think that it's a very bad idea for the scheduling mechanism and the load balancing mechanism to be coupled. The anomalies that will be experienced and the attempts to make ad hoc fixes for them will lead to complexity spiralling out of control.

This is clearly unavoidable in the case of gang scheduling. There is simply no other way to schedule N tasks which must all be run simultaneously when they run at all on N cpus of the system without such coupling and furthermore at an extremely intimate level, particularly when multiple competing gangs must be scheduled in such a fashion.

Quoted 3 lines · William Lee Irwin III
Quoted 3 lines

Where I had a significant need for
mucking with the entire concept of how SMP was handled, this is rather different.

Quoted 5 lines · Peter Williams

Yes, I went with the idea of intra run queue scheduling being orthogonal to load balancing for two reasons:
1. I think that coupling them is a bad idea from the complexity POV, and
2. it's enough of a battle fighting for modifications to one bit of the code without trying to do it to two simultaneously.

As nice as that sounds, such a code structure would've precluded the entire raison d'etre of the patch, i.e. gang scheduling.

Quoted 4 lines · William Lee Irwin III
Quoted 4 lines

At this point I'm questioning the relevance of my own work, though it was already relatively marginal as it started life as an attempt at a sort of debug patch to help gang scheduling (which is in itself a rather marginally relevant feature to most users) code along.

Quoted 9 lines · Peter Williams

The main commercial plug in scheduler used with the run time loadable module scheduler that I mentioned earlier did gang scheduling (at the insistence of the Tru64 kernel folks). As this scheduler was a hierarchical "fair share" scheduler: i.e. allocating CPU "fairly" ("unfairly" really in according to an allocation policy) among higher level entities such as users, groups and applications as well as processes; it was fairly easy to make it a gang scheduler by modifying it to give all of a process's threads the same priority based on the process's CPU usage rather than different priorities based on the

Quoted 8 lines

threads' usage rates. In fact, it would have been possible to select between gang and non gang on a per process basis if that was considered desirable.
The fact that threads and processes are distinct entities on Tru64 and Solaris made this easier to do on them than on Linux.
My experience with this scheduler leads me to believe that to achieve gang scheduling and fairness, etc. you need (usage) statistics based schedulers.

This does not appear to make sense unless it's based on an incorrect use of the term "gang scheduling." I'm referring to a gang as a set of tasks (typically restricted to threads of the same process) which must all be considered runnable or unrunnable simultaneously, and are for the sake of performance required to all actually be run simultaneously. This means a gang of N threads, when run, must run on N processors at once. A time and a set of processors must be chosen for any time interval where the gang is running. This interacts with load balancing by needing to choose the cpus to run the gang on, and also arranging for a set of cpus available for the gang to use to exist by means of migrating tasks off the chosen cpus.

Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

Kernel compiles not so useful a benchmark. SDET, OAST, AIM7, etc. are better ones. I'd not bother citing kernel compile results.

Quoted 8 lines · Peter Williams

spa_svr actually does its best work when the system isn't fully loaded as the type of improvement it strives to achieve (minimizing on queue wait time) hasn't got much room to manoeuvre when the system is fully loaded. Therefore, the fact that it's 1% better even in these circumstances is a good result and also indicates that the overhead for keeping the scheduling statistics it uses for its decision making is well spent. Especially, when you consider that the total available room for improvement on this benchmark is less than 3%.

None of these benchmarks require the system to be fully loaded. They are, on the other hand, vastly more realistic simulated workloads than kernel compiles, and furthermore are actually developed as benchmarks, with in some cases even measurements of variance, iteration to convergence, and similar such things that make them actually scientific.

Quoted 9 lines · Peter Williams

To elaborate, the motivation for this scheduler was acquired from the observation of scheduling statistics (in particular, on queue wait time) on systems running at about 30% to 50% load. Theoretically, at these load levels there should be no such waiting but the statistics show that there is considerable waiting (sometimes as high as 30% to 50%). I put this down to "lack of serendipity" e.g. everyone sleeping at the same time and then trying to run at the same time would be complete lack of serendipity. On the other hand, if everyone is synced then there would be total serendipity.

Quoted 8 lines

Obviously, from the POV of a client, time the server task spends waiting on the queue adds to the response time for any request that has been made so reduction of this time on a server is a good thing(tm). Equally obviously, trying to achieve this synchronization by asking the tasks to cooperate with each other is not a feasible solution and some external influence needs to be exerted and this is what spa_svr does -- it nudges the scheduling order of the tasks in a way that makes them become well synced.

This all sounds like a relatively good idea. So it's good for throughput vs. latency or otherwise not particularly interactive. No big deal, just use it where it makes sense.

Quoted 8 lines · Peter Williams

Unfortunately, this is not a good scheduler for an interactive system as it minimizes the response times for ALL tasks (and the system as a whole) and this can result in increased response time for some interactive tasks (clunkiness) which annoys interactive users. When you start fiddling with this scheduler to bring back "interactive unfairness" you kill a lot of its superior low overall wait time performance.
So this is why I think "horses for courses" schedulers are worth while.

I have no particular objection to using an appropriate scheduler for the system's workload. I also have little or no preference as to how that's accomplished overall. But I really think that if we want to push pluggable scheduling it should load schedulers as kernel modules on the fly and so on versus pure /proc/ tunables and a compiled-in set of alternatives.

Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

In any event, I'm not sure what to say about different schedulers for different aims. My intentions with plugsched were not centered around production usage or intra-queue policy. I'm relatively indifferent to the notion of having pluggable CPU schedulers, intra-queue or otherwise, in mainline. I don't see any particular harm in it, but neither am I particularly motivated to have it in.

Quoted 8 lines · Peter Williams

If you look at the struct sched_spa_child in the file include/linux/sched_spa.h you'll see that the interface for switching between the various SPA schedulers is quite small and making them runtime switchable would be easy (I haven't done this in cpusched as I wanted to keep the same interface for switching schedulers for all
schedulers: i.e. all run time switchable or none run time switchable; as the main aim of plugsched had become a mechanism for evaluating different intra queue scheduling designs.)

I remember actually looking at this, and I would almost characterize the differences between the SPA schedulers as a tunable parameter. I have a different concept of what pluggability means from how the SPA schedulers were switched, but no particular objection to the method given the commonalities between them.

-- wli

#55 lore raw
In reply to William Lee Irwin III
Quoted 9 lines · William Lee Irwin III
Quoted 5 lines · Ingo Molnar

Oh I was very much testing "CPU bandwidth allocation as influenced by nice numbers" - it's one of the basic things i do when modifying the scheduler. An automated tool, while nice (all automation is nice) wouldnt necessarily show such bugs though, because here too it needed thousands of running tasks to trigger in practice. Any volunteers? ;)

Worse comes to worse I might actually get around to doing it myself. Any more detailed descriptions of the test for a rainy day?

the main complication here is that the handling of nice levels is still typically a 2nd or 3rd degree design factor when writing schedulers. The reason isnt carelessness, the reason is simply that users typically only care about a single nice level: the one that all tasks run under by default.

Also, often there's just one or two good ways to attack the problem within a given scheduler approach and the quality of nice levels often suffers under other, more important design factors like performance.

This means that for example for the vanilla scheduler the distribution of CPU power depends on HZ, on the number of tasks and on the scheduling pattern. The distribution of CPU power amongst nice levels is basically a function of _everything_. That makes any automated test pretty challenging. Both with SD and with CFS there's a good chance to actually formalize the meaning of nice levels, but i'd not go as far as to mandate any particular behavior by rigidly saying "pass this automated tool, else ...", other than "make nice levels resonable". All the other more formal CPU resource limitation techniques are then a matter of CKRM-alike patches, which offer much more finegrained mechanisms than pure nice levels anyway.

so to answer your question: it's pretty much freely defined. Make up your mind about it and figure out the ways how people use nice levels and think about which aspects of that experience are worth testing for intelligently.

Ingo

#364 lore raw
In reply to Ismail Dönmez
Quoted 4 lines · Ismail Dönmez

Tested this on top of Linus' GIT tree but the system gets very unresponsive during high disk i/o using ext3 as filesystem but even writing a 300mb file to a usb disk (iPod actually) has the same affect.

hm. Is this an SMP system+kernel by any chance?

Ingo

#365 lore raw
Quoted 7 lines · On Monday 16 April 2007 14:58:54 Ingo Molnar wrote:
Quoted 4 lines · Ismail Dönmez

Tested this on top of Linus' GIT tree but the system gets very unresponsive during high disk i/o using ext3 as filesystem but even writing a 300mb file to a usb disk (iPod actually) has the same affect.

hm. Is this an SMP system+kernel by any chance?

Nope the kernel and the system is UP.

Regards,
ismail

#327 lore raw
In reply to William Lee Irwin III
Quoted 23 lines · William Lee Irwin III
Quoted 9 lines · William Lee Irwin III
Quoted 9 lines

Driver models for scheduling are not so far out. AFAICS it's largely a tug-of-war over design goals, e.g. maintaining per-cpu runqueues and switching out intra-queue policies vs. switching out whole-system policies, SMP handling and all. Whether this involves load balancing depends strongly on e.g. whether you have per-cpu runqueues. A 2.4.x scheduler module, for instance, would not have a load balancer at all, as it has only one global runqueue. There are other sorts of policies wanting significant changes to SMP handling vs. the stock load balancing.

Quoted 1 line · Peter Williams

Well a single run queue removes the need for load balancing but has scalability issues on large systems. Personally, I think something in between would be the best solution i.e. multiple run queues but more than one CPU per run queue. I think that this would be a particularly good solution to the problems introduced by hyper threading and multi core systems and also NUMA systems. E.g. if all CPUs in a hyper thread package are using the one queue then the case where one CPU is trying to run a high priority task and the other a low priority task (i.e. the cases that the sleeping dependent mechanism tried to address) is less likely to occur.

This wasn't meant to sing the praises of the 2.4.x scheduler; it was rather meant to point out that the 2.4.x scheduler, among others, is unimplementable within the framework if it assumes per-cpu runqueues. More plausibly useful single-queue schedulers would likely use a vastly different policy and attempt to carry out all queue manipulations via lockless operations.

On Mon, Apr 16, 2007 at 03:09:31PM +1000, Peter Williams wrote:

Quoted 8 lines
Quoted 1 line

By the way, I think that it's a very bad idea for the scheduling mechanism and the load balancing mechanism to be coupled. The anomalies that will be experienced and the attempts to make ad hoc fixes for them will lead to complexity spiralling out of control.

This is clearly unavoidable in the case of gang scheduling. There is simply no other way to schedule N tasks which must all be run simultaneously when they run at all on N cpus of the system without such coupling and furthermore at an extremely intimate level, particularly when multiple competing gangs must be scheduled in such a fashion.

I can't see the logic here or why you would want to do such a thing. It certainly doesn't coincide with what I interpret "gang scheduling" to mean.

Quoted 7 lines
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines

Where I had a significant need for
mucking with the entire concept of how SMP was handled, this is rather different.

Quoted 7 lines
Quoted 3 lines · Peter Williams

Yes, I went with the idea of intra run queue scheduling being orthogonal to load balancing for two reasons:
1. I think that coupling them is a bad idea from the complexity POV, and
2. it's enough of a battle fighting for modifications to one bit of the code without trying to do it to two simultaneously.

As nice as that sounds, such a code structure would've precluded the entire raison d'etre of the patch, i.e. gang scheduling.

Not for what I understand "gang scheduling" to mean. As I understand it the constraints of gang scheduling are no where near as strict as you seem to think they are. And for what it's worth I don't think that what you think it means is in any sense a reasonable target.

Quoted 8 lines
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines

At this point I'm questioning the relevance of my own work, though it was already relatively marginal as it started life as an attempt at a sort of debug patch to help gang scheduling (which is in itself a rather marginally relevant feature to most users) code along.

Quoted 7 lines
Quoted 3 lines · Peter Williams

The main commercial plug in scheduler used with the run time loadable module scheduler that I mentioned earlier did gang scheduling (at the insistence of the Tru64 kernel folks). As this scheduler was a hierarchical "fair share" scheduler: i.e. allocating CPU "fairly" ("unfairly" really in according to an allocation policy) among higher level entities such as users, groups and applications as well as processes; it was fairly easy to make it a gang scheduler by modifying it to give all of a process's threads the same priority based on the process's CPU usage rather than different priorities based on the threads' usage rates. In fact, it would have been possible to select between gang and non gang on a per process basis if that was considered desirable. The fact that threads and processes are distinct entities on Tru64 and Solaris made this easier to do on them than on Linux.
My experience with this scheduler leads me to believe that to achieve gang scheduling and fairness, etc. you need (usage) statistics based schedulers.

This does not appear to make sense unless it's based on an incorrect use of the term "gang scheduling."

It's become obvious that we mean different things.

Quoted 10 lines

I'm referring to a gang as a set of
tasks (typically restricted to threads of the same process) which must all be considered runnable or unrunnable simultaneously, and are for the sake of performance required to all actually be run simultaneously. This means a gang of N threads, when run, must run on N processors at once. A time and a set of processors must be chosen for any time interval where the gang is running. This interacts with load balancing by needing to choose the cpus to run the gang on, and also arranging for a set of cpus available for the gang to use to exist by means of migrating tasks off the chosen cpus.

Sounds like a job for the load balancer NOT the scheduler.

Also I can't see you meeting such strict constraints without making the tasks all SCHED_FIFO.

Quoted 45 lines
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

Kernel compiles not so useful a benchmark. SDET, OAST, AIM7, etc. are better ones. I'd not bother citing kernel compile results.

Quoted 1 line · Peter Williams

spa_svr actually does its best work when the system isn't fully loaded as the type of improvement it strives to achieve (minimizing on queue wait time) hasn't got much room to manoeuvre when the system is fully loaded. Therefore, the fact that it's 1% better even in these circumstances is a good result and also indicates that the overhead for keeping the scheduling statistics it uses for its decision making is well spent. Especially, when you consider that the total available room for improvement on this benchmark is less than 3%.

None of these benchmarks require the system to be fully loaded. They are, on the other hand, vastly more realistic simulated workloads than kernel compiles, and furthermore are actually developed as benchmarks, with in some cases even measurements of variance, iteration to convergence, and similar such things that make them actually scientific.

Quoted 2 lines · Peter Williams

To elaborate, the motivation for this scheduler was acquired from the observation of scheduling statistics (in particular, on queue wait time) on systems running at about 30% to 50% load. Theoretically, at these load levels there should be no such waiting but the statistics show that there is considerable waiting (sometimes as high as 30% to 50%). I put this down to "lack of serendipity" e.g. everyone sleeping at the same time and then trying to run at the same time would be complete lack of serendipity. On the other hand, if everyone is synced then there would be total serendipity. Obviously, from the POV of a client, time the server task spends waiting on the queue adds to the response time for any request that has been made so reduction of this time on a server is a good thing(tm). Equally obviously, trying to achieve this synchronization by asking the tasks to cooperate with each other is not a feasible solution and some external influence needs to be exerted and this is what spa_svr does -- it nudges the scheduling order of the tasks in a way that makes them become well synced.

This all sounds like a relatively good idea. So it's good for throughput vs. latency or otherwise not particularly interactive. No big deal, just use it where it makes sense.

Quoted 2 lines · Peter Williams

Unfortunately, this is not a good scheduler for an interactive system as it minimizes the response times for ALL tasks (and the system as a whole) and this can result in increased response time for some interactive tasks (clunkiness) which annoys interactive users. When you start fiddling with this scheduler to bring back "interactive unfairness" you kill a lot of its superior low overall wait time performance. So this is why I think "horses for courses" schedulers are worth while.

I have no particular objection to using an appropriate scheduler for the system's workload. I also have little or no preference as to how that's accomplished overall. But I really think that if we want to push pluggable scheduling it should load schedulers as kernel modules on the fly and so on versus pure /proc/ tunables and a compiled-in set of alternatives.

Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

In any event, I'm not sure what to say about different schedulers for different aims. My intentions with plugsched were not centered around production usage or intra-queue policy. I'm relatively indifferent to the notion of having pluggable CPU schedulers, intra-queue or otherwise, in mainline. I don't see any particular harm in it, but neither am I particularly motivated to have it in.

Quoted 8 lines
Quoted 1 line · Peter Williams

If you look at the struct sched_spa_child in the file include/linux/sched_spa.h you'll see that the interface for switching between the various SPA schedulers is quite small and making them runtime switchable would be easy (I haven't done this in cpusched as I wanted to keep the same interface for switching schedulers for all schedulers: i.e. all run time switchable or none run time switchable; as the main aim of plugsched had become a mechanism for evaluating different intra queue scheduling designs.)

I remember actually looking at this, and I would almost characterize the differences between the SPA schedulers as a tunable parameter. I have a different concept of what pluggability means from how the SPA schedulers were switched, but no particular objection to the method given the commonalities between them.

Yes, that's the way I look at them (in fact, in Zaphod that's exactly what they were -- i.e. Zaphod could be made to behave like various SPA schedulers by fiddling its run time parameters). They illustrate (to my mind) that once you get rid of the O(1) scheduler and replace it with a simple mechanism such as SPA (where there's a small number of points where the scheduling discipline gets to do its thing rather than being interspersed willy nilly throughout the rest of the code) adding run time switchable "horses for courses" scheduler disciplines becomes simple. I think that the simplifications in Ingo's new scheduler (whose scheduling classes now look a lot like Solaris's and its predecessor OSes' scheduler classes) may make it possible to have switchable scheduling disciplines within a scheduling class.

I think that something similar (i.e. switchability) could be done for load balancing so that different load balancers could be used when required. By keeping this load balancing functionality orthogonal to the intra run queue scheduling disciplines you increase the number of options available.

As I see it, if the scheduling discipline in use does its job properly within a run queue and the load balancer does its job of keeping the weighted load/demand on each run queue roughly equal (except where it has to do otherwise for your version of "gang scheduling") then the overall outcome will meet expectations. Note that I talk of run queues not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#56 lore raw
In reply to Ingo Molnar
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

Worse comes to worse I might actually get around to doing it myself. Any more detailed descriptions of the test for a rainy day?

Quoted 5 lines · Ingo Molnar

the main complication here is that the handling of nice levels is still typically a 2nd or 3rd degree design factor when writing schedulers. The reason isnt carelessness, the reason is simply that users typically only care about a single nice level: the one that all tasks run under by default.

I'm a bit unconvinced here. Support for prioritization is a major scheduler feature IMHO.

Quoted 6 lines · Ingo Molnar

Also, often there's just one or two good ways to attack the problem within a given scheduler approach and the quality of nice levels often suffers under other, more important design factors like performance. This means that for example for the vanilla scheduler the distribution of CPU power depends on HZ, on the number of tasks and on the scheduling pattern. The distribution of CPU power amongst nice levels is basically

Quoted 8 lines

a function of _everything_. That makes any automated test pretty challenging. Both with SD and with CFS there's a good chance to actually formalize the meaning of nice levels, but i'd not go as far as to mandate any particular behavior by rigidly saying "pass this automated tool, else ...", other than "make nice levels resonable". All the other more formal CPU resource limitation techniques are then a matter of CKRM-alike patches, which offer much more finegrained mechanisms than pure nice levels anyway.

Some of the issues with respect to the number of tasks and scheduling patterns can be made part of the test; one can furthermore insist that the system be quiescent in a variety of ways. I'm not convinced that formalization of nice levels is a bad idea. They're the standard UNIX prioritization facility, and it should work with some definite value of "work."

Even supposing one doesn't care to bolt down the semantics of nice levels, there should at least be some awareness of what those semantics are and when and how they're changing. So in that respect a test for CPU bandwidth distribution according to nice level remains valuable even supposing that the semantics aren't required to be rigidly fixed.

As far as CKRM goes, I'm wild about it. I wish things would get in shape to be merged (if they're not already) and merged ASAP on that front. I think with so much agreement in concept we can work with changing out implementations as-needed with it sitting in mainline once the the user API/ABI is decided upon, and I think it already is.

I'm not entirely convinced CKRM answers this, though. If the scheduler can't support nice levels, how is it supposed to support prioritization or CPU bandwidth allocation according to CKRM configurations? I'm relatively certain schedulers must be able to support prioritization with deterministic CPU bandwidth as essential functionality. This is, of course, not to say my certainty about things sets the standards for what testcases are considered meaningful and valid.

Quoted 4 lines · Ingo Molnar

so to answer your question: it's pretty much freely defined. Make up your mind about it and figure out the ways how people use nice levels and think about which aspects of that experience are worth testing for intelligently.

Looking for usage cases is a good idea; I'll do that before coding any testcase for nice semantics.

-- wli

#318 lore raw
In reply to Nick Piggin
Quoted 2 lines · Nick Piggin

I'd prefer if we kept a single CPU scheduler in mainline, because I think that simplifies analysis and focuses testing.

I think you'll find something like 80-90% of the testing will be done on the default choice, even if other choices exist. So you really won't have much of a problem here.

But when the only choice for other schedulers is to go out-of-tree, then only 1% of the people will try it out and those people are guaranteed to be the ones who saw scheduling problems in mainline. So the alternative won't end up getting any testing on many of the workloads that work fine in mainstream so their feedback won't tell you very much at all.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#321 lore raw
In reply to Matt Mackall
Quoted 9 lines · Matt Mackall

That's irrelevant. Plugsched was an attempt to get alternative schedulers exposure in mainline. I know, because I remember encouraging Bill to pursue it. Not only did you veto plugsched (which may have been a perfectly reasonable thing to do), but you also vetoed the whole concept of multiple schedulers in the tree too. "We don't want to balkanize the scheduling landscape".
And that latter part is what I'm claiming has set us back for years. It's not a technical argument but a strategic one. And it's just not a good strategy.

[... excellent post trimmed...]

These are some rather powerful arguments. I think I'll actually start looking at plugsched again.

-- wli

#134 lore raw
In reply to William Lee Irwin III
Quoted 5 lines · William Lee Irwin III

The sorts of like explicit decisions I'd like to be made for these are:
(1) In a mixture of tasks with varying nice numbers, a given nice number corresponds to some share of CPU bandwidth. Implementations should not have the freedom to change this arbitrarily according to some intention.

The first question that comes to my mind is whether nice levels should be linear or not. I would lean towards nonlinear as it allows a wider range (although of course at the expense of precision). Maybe something like "each nice level gives X times the cpu of the previous"? I think a value of X somewhere between 1.15 and 1.25 might be reasonable.

What about also having something that looks at latency, and how latency changes with niceness?

What about specifying the timeframe over which the cpu bandwidth is measured? I currently have a system where the application designers would like it to be totally fair over a period of 1 second. As you can imagine, mainline doesn't do very well in this case.

Chris

#135 lore raw
Quoted 5 lines · William Lee Irwin III
Quoted 5 lines

The sorts of like explicit decisions I'd like to be made for these are:
(1) In a mixture of tasks with varying nice numbers, a given nice number corresponds to some share of CPU bandwidth. Implementations should not have the freedom to change this arbitrarily according to some intention.

Quoted 11 lines · Chris Friesen

The first question that comes to my mind is whether nice levels should be linear or not. I would lean towards nonlinear as it allows a wider range (although of course at the expense of precision). Maybe something like "each nice level gives X times the cpu of the previous"? I think a value of X somewhere between 1.15 and 1.25 might be reasonable. What about also having something that looks at latency, and how latency changes with niceness?
What about specifying the timeframe over which the cpu bandwidth is measured? I currently have a system where the application designers would like it to be totally fair over a period of 1 second. As you can imagine, mainline doesn't do very well in this case.

It's unclear how latency enters the picture as the semantics of nice levels relevant to such are essentially priority preemption, which is not particularly easy to mess up. I suppose tests to ensure priority preemption occurs properly are in order.

I don't really have a preference regarding specific semantics for nice numbers, just that they should be deterministic and specified somewhere. It's not really for us to decide what those semantics are as it's more of a userspace ABI/API issue.

The timeframe is also relevant, but I suspect it's more of a performance metric than a strict requirement.

-- wli

#350 lore raw
In reply to Peter Williams
Quoted 1 line · Peter Williams

To my mind scheduling and load balancing are orthogonal and keeping them that way simplifies things.

Scuse me if I jump in here, but doesn't the load balancer need some way to figure out a) when to run, and b) which tasks to pull and where to push them?

I suppose you could abstract this into a per-scheduler API, but to me at least these are the hard parts of the load balancer...

Chris

#366 lore raw
In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

I would suggest to drop the tsc.c change. The "small errors" can be really large on some systems and you can also see large backward jumps. I have a proper (but complicated) solution pending
in ftp://ftp.firstfloor.org/pub/ak/x86_64/quilt/sched-clock-share

BTW with all this CPU time measurement it would be really nice to report it to the user too. It seems a bit bizarre that the scheduler keeps track of ns, but top only knows jiffies with large sampling errors.

-Andi

#367 lore raw
Quoted 8 lines · Andi Kleen
Quoted 4 lines

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

I would suggest to drop the tsc.c change. The "small errors" can be really large on some systems and you can also see large backward jumps.

actually, i designed the CFS code assuming a per-CPU TSC (with no global synchronization), not assuming any globally sync TSC. In fact i wrote it on such systems: a CoreDuo2 box that has stops the TSC in C3 and the different cores have wildly different TSC values and a dual-core Athlon64 that quickly drifts its TSC. So i'll keep the sched_clock() change for now.

Quoted 4 lines

BTW with all this CPU time measurement it would be really nice to report it to the user too. It seems a bit bizarre that the scheduler keeps track of ns, but top only knows jiffies with large sampling errors.

yeah - i'll fix that too if someone doesnt beat me at it.

Ingo

#368 lore raw
Quoted 2 lines

actually, i designed the CFS code assuming a per-CPU TSC (with no global synchronization), not assuming any globally sync TSC. In fact i wrote it

That already worked in the old scheduler (just in a hackish way)

Quoted 4 lines

on such systems: a CoreDuo2 box that has stops the TSC in C3 and the different cores have wildly different TSC values and a dual-core Athlon64 that quickly drifts its TSC. So i'll keep the sched_clock() change for now.

The problem is not CPU synchronized TSC, but TSC with varying frequency on a single CPU like on the A64.

The old implementation can lose really badly on that because it mixes measurements at different frequencies together without individual scaling.

The error gets worse the longer the system runs.

Quoted 6 lines
Quoted 4 lines

BTW with all this CPU time measurement it would be really nice to report it to the user too. It seems a bit bizarre that the scheduler keeps track of ns, but top only knows jiffies with large sampling errors.

yeah - i'll fix that too if someone doesnt beat me at it.

I've been pondering for some time if doubling the NMI watchdog as a ring 0 counter for this is worth it. So far I'm still undecided (and it's moot now since it's disabled by default :/)

-Andi

#328 lore raw
In reply to Peter Williams
Quoted 3 lines · Peter Williams

Note that I talk of run queues
not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

For instance, there are architectures where several "CPUs" (instruction stream decoders feeding execution pipelines) share parts of a cache hierarchy ("chip-level multitasking"). On these machines, you may want to co-schedule a "real" processing task on one pipeline with a "cache warming" task on the other pipeline -- but only for tasks whose memory access patterns have been sufficiently analyzed to write the "cache warming" task code. Some other tasks may want to idle the second pipeline so they can use the full cache-to-RAM bandwidth. Yet other tasks may be genuinely CPU-intensive (or I/O bound but so context-heavy that it's not worth yielding the CPU during quick I/Os), and hence perfectly happy to run concurrently with an unrelated task on the other pipeline.

There are other architectures where several "hardware threads" fight over parts of a cache hierarchy (sometimes bizarrely described as "sharing" the cache, kind of the way most two-year-olds "share" toys). On these machines, one instruction pipeline can't help the other along cache-wise, but it sure can hurt. A scheduler designed, tested, and tuned principally on one of these architectures (hint:
"hyperthreading") will probably leave a lot of performance on the floor on processors in the former category.

In the not-so-distant future, we're likely to see architectures with dynamically reconfigurable interconnect between instruction issue units and execution resources. (This is already quite feasible on, say, Virtex4 FX devices with multiple PPC cores, or Altera FPGAs with as many Nios II cores as fit on the chip.) Restoring task context may involve not just MMU swaps and FPU instructions (with state-dependent hidden costs) but processsor reconfiguration. Achieving "fairness" according to any standard that a platform integrator cares about (let alone an end user) will require a fairly detailed model of the hidden costs associated with different sorts of task switch.

So if you are interested in schedulers for some reason other than a paycheck, let the distros worry about 5% improvements on x86[_64]. Get hold of some different "hardware" -- say:
- a Xilinx ML410 if you've got $3K to blow and want to explore
reconfigurable processors;
- a SunFire T2000 if you've got $11K and want to mess with a CMT
system that's actually shipping;
- a QEMU-simulated massively SMP x86 if you're poor but clever
enough to implement funky cross-core cache effects yourself; or
- a cycle-accurate simulator from Gaisler or Virtio if you want a
real research project.
Then go explore some more interesting regions of parameter space and see what the demands on mainline Linux will look like in a few years.

Cheers,
- Michael

#160 lore raw
In reply to Mike Galbraith
Quoted 14 lines · Mike Galbraith
Quoted 13 lines · Con Kolivas
Quoted 12 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.

Quoted 7 lines
Quoted 1 line

The casual observer will be completely confused by what on earth has happened here so let me try to demystify things for them.

[...]

Demystify what? The casual observer need only read either your attempt
at writing a scheduler, or my attempts at fixing the one we have, to see that it was high time for someone with the necessary skills to step in.

Make that "someone with the necessary clout".

Quoted 2 lines

Now progress can happen, which was _not_ happening before.

This is true.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#351 lore raw
In reply to Chris Friesen
Quoted 5 lines · Chris Friesen
Quoted 1 line · Peter Williams

To my mind scheduling and load balancing are orthogonal and keeping them that way simplifies things.

Scuse me if I jump in here, but doesn't the load balancer need some way to figure out a) when to run, and b) which tasks to pull and where to push them?

Yes but both of these are independent of the scheduler discipline in force.

Quoted 2 lines

I suppose you could abstract this into a per-scheduler API, but to me at least these are the hard parts of the load balancer...

Load balancing needs to be based on the static priorities (i.e. nice or real time priority) of the runnable tasks not the dynamic priorities. If the load balancer manages to keep the weighted (according to static priority) load and distribution of priorities within the loads on the CPUs roughly equal and the scheduler does a good job of ensuring fairness, interactive responsiveness etc. for the tasks within a CPU then the result will be good system performance within the constraints set by the sys admins use of real time priorities and nice.

The smpnice modifications to the load balancer were meant to give it the appropriate behaviour and what we need to fix now is the intra CPU scheduling.

Even if the load balancer isn't yet perfect perfecting it can be done separately to fixing the scheduler preferably with as little interdependency as possible. Probably the only contribution to load balancing that the scheduler really needs to make is the calculating of the average weighted load on each of the CPUs (or run queues if there's more than one CPU per runqueue).

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#24 lore raw
In reply to Davide Libenzi
Quoted 107 lines · Davide Libenzi
Quoted 17 lines · Pavel Pisa

I cannot help myself to not report results with GAVL tree algorithm there as an another race competitor. I believe, that it is better solution for large priority queues than RB-tree and even heap trees. It could be disputable if the scheduler needs such scalability on the other hand. The AVL heritage guarantees lower height which results in shorter search times which could be profitable for other uses in kernel.

GAVL algorithm is AVL tree based, so it does not suffer from "infinite" priorities granularity there as TR does. It allows use for generalized case where tree is not fully balanced. This allows to cut the first item withour rebalancing. This leads to the degradation of the tree by one more level (than non degraded AVL gives) in maximum, which is still considerably better than RB-trees maximum.

Quoted 1 line

http://cmp.felk.cvut.cz/~pisa/linux/smart-queue-v-gavl.c

Here are the results on my Opteron 252:

Testing N=1
gavl_cfs = 187.20 cycles/loop
CFS = 194.16 cycles/loop
TR = 314.87 cycles/loop
CFS = 194.15 cycles/loop
gavl_cfs = 187.15 cycles/loop

Testing N=2
gavl_cfs = 268.94 cycles/loop
CFS = 305.53 cycles/loop
TR = 313.78 cycles/loop
CFS = 289.58 cycles/loop
gavl_cfs = 266.02 cycles/loop

Testing N=4
gavl_cfs = 452.13 cycles/loop
CFS = 518.81 cycles/loop
TR = 311.54 cycles/loop
CFS = 516.23 cycles/loop
gavl_cfs = 450.73 cycles/loop

Testing N=8
gavl_cfs = 609.29 cycles/loop
CFS = 644.65 cycles/loop
TR = 308.11 cycles/loop
CFS = 667.01 cycles/loop
gavl_cfs = 592.89 cycles/loop

Testing N=16
gavl_cfs = 686.30 cycles/loop
CFS = 807.41 cycles/loop
TR = 317.20 cycles/loop
CFS = 810.24 cycles/loop
gavl_cfs = 688.42 cycles/loop

Testing N=32
gavl_cfs = 756.57 cycles/loop
CFS = 852.14 cycles/loop
TR = 301.22 cycles/loop
CFS = 876.12 cycles/loop
gavl_cfs = 758.46 cycles/loop

Testing N=64
gavl_cfs = 831.97 cycles/loop
CFS = 997.16 cycles/loop
TR = 304.74 cycles/loop
CFS = 1003.26 cycles/loop
gavl_cfs = 832.83 cycles/loop

Testing N=128
gavl_cfs = 897.33 cycles/loop
CFS = 1030.36 cycles/loop
TR = 295.65 cycles/loop
CFS = 1035.29 cycles/loop
gavl_cfs = 892.51 cycles/loop

Testing N=256
gavl_cfs = 963.17 cycles/loop
CFS = 1146.04 cycles/loop
TR = 295.35 cycles/loop
CFS = 1162.04 cycles/loop
gavl_cfs = 966.31 cycles/loop

Testing N=512
gavl_cfs = 1029.82 cycles/loop
CFS = 1218.34 cycles/loop
TR = 288.78 cycles/loop
CFS = 1257.97 cycles/loop
gavl_cfs = 1029.83 cycles/loop

Testing N=1024
gavl_cfs = 1091.76 cycles/loop
CFS = 1318.47 cycles/loop
TR = 287.74 cycles/loop
CFS = 1311.72 cycles/loop
gavl_cfs = 1093.29 cycles/loop

Testing N=2048
gavl_cfs = 1153.03 cycles/loop
CFS = 1398.84 cycles/loop
TR = 286.75 cycles/loop
CFS = 1438.68 cycles/loop
gavl_cfs = 1149.97 cycles/loop

Quoted 6 lines

There seem to be some difference from your numbers. This is with:

gcc version 4.1.2

and -O2. But then and Opteron can behave quite differentyl than a Duron on a bench like this ;)

Thanks for testing, but yours numbers are more correct than my first report. My numbers seemed to be over-optimistic even to me, In the fact I have been surprised that difference is so high. But I have tested bad version of code without GAVL_FAFTER option set. The code pushed to the web page has been the correct one. I have not get to look into case until now because I have busy day to prepare some Linux based labs at university.

Without GAVL_FAFTER option, insert operation does fail if item with same key is already inserted (intended feature of the code) and as result of that, not all items have been inserted in the test. The meaning of GAVL_FAFTER is find/insert after all items with the same key value. Default behavior is operate on unique keys in tree and reject duplicates.

My results are even worse for GAVL than yours.
It is possible to try tweak code and optimize it more (likely/unlikely/do not keep last ptr etc) for this actual usage. May it be, that I try this exercise, but I do not expect that the result after tuning would be so much better, that it would outweight some redesign work. I could see some advantages of AVL still, but it has its own drawbacks with need of separate height field and little worse delete in the middle timing.

So excuse me for disturbance. I have been only curious how GAVL code would behave in the comparison of other algorithms and I did not kept my premature enthusiasm under the lock.

Best wishes

Pavel Pisa

./smart-queue-v-gavl -n 4
gavl_cfs = 279.02 cycles/loop
CFS = 200.87 cycles/loop
TR = 229.55 cycles/loop
CFS = 201.23 cycles/loop
gavl_cfs = 276.08 cycles/loop

./smart-queue-v-gavl -n 8
gavl_cfs = 310.92 cycles/loop
CFS = 288.45 cycles/loop
TR = 192.46 cycles/loop
CFS = 284.94 cycles/loop
gavl_cfs = 357.02 cycles/loop

./smart-queue-v-gavl -n 16
gavl_cfs = 350.45 cycles/loop
CFS = 354.01 cycles/loop
TR = 189.79 cycles/loop
CFS = 320.08 cycles/loop
gavl_cfs = 387.43 cycles/loop

./smart-queue-v-gavl -n 32
gavl_cfs = 419.23 cycles/loop
CFS = 406.88 cycles/loop
TR = 198.10 cycles/loop
CFS = 398.15 cycles/loop
gavl_cfs = 412.57 cycles/loop

./smart-queue-v-gavl -n 64
gavl_cfs = 442.81 cycles/loop
CFS = 429.62 cycles/loop
TR = 235.40 cycles/loop
CFS = 389.54 cycles/loop
gavl_cfs = 433.56 cycles/loop

./smart-queue-v-gavl -n 128
gavl_cfs = 358.20 cycles/loop
CFS = 605.49 cycles/loop
TR = 236.01 cycles/loop
CFS = 458.50 cycles/loop
gavl_cfs = 455.05 cycles/loop

./smart-queue-v-gavl -n 256
gavl_cfs = 529.72 cycles/loop
CFS = 530.98 cycles/loop
TR = 193.75 cycles/loop
CFS = 533.75 cycles/loop
gavl_cfs = 471.47 cycles/loop

./smart-queue-v-gavl -n 512
gavl_cfs = 525.80 cycles/loop
CFS = 550.63 cycles/loop
TR = 188.71 cycles/loop
CFS = 549.81 cycles/loop
gavl_cfs = 494.73 cycles/loop

./smart-queue-v-gavl -n 1024
gavl_cfs = 544.91 cycles/loop
CFS = 561.68 cycles/loop
TR = 230.97 cycles/loop
CFS = 522.68 cycles/loop
gavl_cfs = 542.40 cycles/loop

./smart-queue-v-gavl -n 2048
gavl_cfs = 567.46 cycles/loop
CFS = 581.85 cycles/loop
TR = 229.69 cycles/loop
CFS = 585.41 cycles/loop
gavl_cfs = 563.22 cycles/loop

#136 lore raw
In reply to Chris Friesen
Quoted 9 lines · Chris Friesen
Quoted 5 lines · William Lee Irwin III

The sorts of like explicit decisions I'd like to be made for these are:
(1) In a mixture of tasks with varying nice numbers, a given nice number corresponds to some share of CPU bandwidth. Implementations should not have the freedom to change this arbitrarily according to some intention.

The first question that comes to my mind is whether nice levels should be linear or not.

No. That squishes one end of the table too much. It needs to be (approximately) piecewise linear around nice == 0. Here's the mapping I use in my entitlement based schedulers:

#define NICE_TO_LP(nice) ((nice >=0) ? (20 - (nice)) : (20 + (nice) * (nice)))

It has the (good) feature that a nice == 19 task has 1/20th the entitlement of a nice == 0 task and a nice == -20 task has 21 times the entitlement of a nice == 0 task. It's not strictly linear for negative nice values but is very cheap to calculate and quite easy to invert if necessary.

Quoted 6 lines

I would lean towards nonlinear as it allows a wider
range (although of course at the expense of precision). Maybe something like "each nice level gives X times the cpu of the previous"? I think a value of X somewhere between 1.15 and 1.25 might be reasonable.

What about also having something that looks at latency, and how latency changes with niceness?

What about specifying the timeframe over which the cpu bandwidth is measured? I currently have a system where the application designers would like it to be totally fair over a period of 1 second.

Have you tried the spa_ebs scheduler? The half life is no longer a run time configurable parameter (as making it highly adjustable results in less efficient code) but it could be adjusted to be approximately equivalent to 0.5 seconds by changing some constants in the code.

Quoted 2 lines

As you can
imagine, mainline doesn't do very well in this case.

You should look back through the plugsched patches where many of these ideas have been experimented with.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#161 lore raw
In reply to Peter Williams
Quoted 7 lines · Peter Williams
Quoted 4 lines · Mike Galbraith

Demystify what? The casual observer need only read either your attempt
at writing a scheduler, or my attempts at fixing the one we have, to see that it was high time for someone with the necessary skills to step in.

Make that "someone with the necessary clout".

No, I was brutally honest to both of us, but quite correct.

Quoted 4 lines
Quoted 2 lines

Now progress can happen, which was _not_ happening before.

This is true.

Yup, and progress _is_ happening now, quite rapidly.

-Mike

#319 lore raw
In reply to Matt Mackall
Quoted 8 lines · Matt Mackall
Quoted 2 lines · Nick Piggin

I'd prefer if we kept a single CPU scheduler in mainline, because I think that simplifies analysis and focuses testing.

I think you'll find something like 80-90% of the testing will be done on the default choice, even if other choices exist. So you really won't have much of a problem here.

Quoted 6 lines

But when the only choice for other schedulers is to go out-of-tree, then only 1% of the people will try it out and those people are guaranteed to be the ones who saw scheduling problems in mainline. So the alternative won't end up getting any testing on many of the workloads that work fine in mainstream so their feedback won't tell you very much at all.

Yeah I concede that perhaps it is the only way to get things going any further. But how do we decide if and when the current scheduler should be demoted from default, and which should replace it?

#162 lore raw
In reply to Mike Galbraith
Quoted 9 lines · Mike Galbraith
Quoted 7 lines · Peter Williams
Quoted 4 lines · Mike Galbraith

Demystify what? The casual observer need only read either your attempt
at writing a scheduler, or my attempts at fixing the one we have, to see that it was high time for someone with the necessary skills to step in.

Make that "someone with the necessary clout".

Quoted 8 lines

No, I was brutally honest to both of us, but quite correct.

Quoted 4 lines
Quoted 2 lines

Now progress can happen, which was _not_ happening before.

This is true.

Yup, and progress _is_ happening now, quite rapidly.

Progress as in progress on Ingo's scheduler. I still don't know how we'd decide when to replace the mainline scheduler or with what.

I don't think we can say Ingo's is better than the alternatives, can we? If there is some kind of bakeoff, then I'd like one of Con's designs to be involved, and mine, and Peter's...

Maybe the progress is that more key people are becoming open to the idea of changing the scheduler.

#329 lore raw
In reply to Michael K. Edwards
Quoted 5 lines · Michael K. Edwards
Quoted 3 lines · Peter Williams

Note that I talk of run queues
not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

Quoted 7 lines

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

Why? If you do that, then your load balancer just becomes less flexible because it is harder to have tasks run on one or the other.

You can have single-runqueue-per-domain behaviour (or close to) just by relaxing all restrictions on idle load balancing within that domain. It is harder to go the other way and place any per-cpu affinity or restirctions with multiple cpus on a single runqueue.

Quoted 4 lines

For instance, there are architectures where several "CPUs" (instruction stream decoders feeding execution pipelines) share parts of a cache hierarchy ("chip-level multitasking"). On these machines, you may want to co-schedule a "real" processing task on one pipeline

Quoted 8 lines

with a "cache warming" task on the other pipeline -- but only for tasks whose memory access patterns have been sufficiently analyzed to write the "cache warming" task code. Some other tasks may want to idle the second pipeline so they can use the full cache-to-RAM bandwidth. Yet other tasks may be genuinely CPU-intensive (or I/O bound but so context-heavy that it's not worth yielding the CPU during quick I/Os), and hence perfectly happy to run concurrently with an unrelated task on the other pipeline.

We can do all that now with load balancing, affinities or by shutting down threads dynamically.

Quoted 20 lines

There are other architectures where several "hardware threads" fight over parts of a cache hierarchy (sometimes bizarrely described as "sharing" the cache, kind of the way most two-year-olds "share" toys). On these machines, one instruction pipeline can't help the other along cache-wise, but it sure can hurt. A scheduler designed, tested, and tuned principally on one of these architectures (hint:
"hyperthreading") will probably leave a lot of performance on the floor on processors in the former category.

In the not-so-distant future, we're likely to see architectures with dynamically reconfigurable interconnect between instruction issue units and execution resources. (This is already quite feasible on, say, Virtex4 FX devices with multiple PPC cores, or Altera FPGAs with as many Nios II cores as fit on the chip.) Restoring task context may involve not just MMU swaps and FPU instructions (with state-dependent hidden costs) but processsor reconfiguration. Achieving "fairness" according to any standard that a platform integrator cares about (let alone an end user) will require a fairly detailed model of the hidden costs associated with different sorts of task switch.

Quoted 13 lines

So if you are interested in schedulers for some reason other than a paycheck, let the distros worry about 5% improvements on x86[_64]. Get hold of some different "hardware" -- say:
- a Xilinx ML410 if you've got $3K to blow and want to explore
reconfigurable processors;
- a SunFire T2000 if you've got $11K and want to mess with a CMT
system that's actually shipping;
- a QEMU-simulated massively SMP x86 if you're poor but clever
enough to implement funky cross-core cache effects yourself; or
- a cycle-accurate simulator from Gaisler or Virtio if you want a
real research project.
Then go explore some more interesting regions of parameter space and see what the demands on mainline Linux will look like in a few years.

There are no doubt improvements to be made, but they are generally intended to be able to be done within the sched-domains framework. I am not aware of a particular need that would be impossible to do using that topology hierarchy and per-CPU runqueues, and there are added complications involved with multiple CPUs per runqueue.

#163 lore raw
In reply to Nick Piggin
Quoted 8 lines · Nick Piggin
Quoted 1 line · Mike Galbraith

Yup, and progress _is_ happening now, quite rapidly.

Progress as in progress on Ingo's scheduler. I still don't know how we'd decide when to replace the mainline scheduler or with what.

I don't think we can say Ingo's is better than the alternatives, can we?

No, that would require massive performance testing of all alternatives.

Quoted 2 lines

If there is some kind of bakeoff, then I'd like one of Con's designs to be involved, and mine, and Peter's...

The trouble with a bakeoff is that it's pretty darn hard to get people to test in the first place, and then comes weighting the subjective and hard performance numbers. If they're close in numbers, do you go with the one which starts the least flamewars or what?

Quoted 2 lines

Maybe the progress is that more key people are becoming open to the idea of changing the scheduler.

Could be. All was quiet for quite a while, but when RSDL showed up, it aroused enough interest to show that scheduling woes is on folks radar.

-Mike

#164 lore raw
Quoted 12 lines · Mike Galbraith
Quoted 8 lines · Nick Piggin
Quoted 1 line · Mike Galbraith

Yup, and progress _is_ happening now, quite rapidly.

Progress as in progress on Ingo's scheduler. I still don't know how we'd decide when to replace the mainline scheduler or with what.

I don't think we can say Ingo's is better than the alternatives, can we?

No, that would require massive performance testing of all alternatives.

Quoted 7 lines
Quoted 2 lines

If there is some kind of bakeoff, then I'd like one of Con's designs to be involved, and mine, and Peter's...

The trouble with a bakeoff is that it's pretty darn hard to get people to test in the first place, and then comes weighting the subjective and hard performance numbers. If they're close in numbers, do you go with the one which starts the least flamewars or what?

I don't know how you'd do it. I know you wouldn't count people telling you how good they are (getting people to tell you how bad they are, and whether others do better in a given situation might be slightly move viable).

But we have to choose somehow. I'd hope that is going to be based solely on the results and technical properties of the code, so... if we were to somehow determine that the results are exactly the same, we'd go for the the simpler one, wouldn't we?

Quoted 5 lines
Quoted 2 lines

Maybe the progress is that more key people are becoming open to the idea of changing the scheduler.

Could be. All was quiet for quite a while, but when RSDL showed up, it aroused enough interest to show that scheduling woes is on folks radar.

Well I know people have had woes with the scheduler for ever (I guess that isn't going to change :P). I think people generally lost a bit of interest in trying to improve the situation because of the upstream problem.

#176 lore raw

Re: [Announce] [patch] Modular Scheduler Core and Completely FairScheduler [CFS]

In reply to Mike Galbraith
Quoted 15 lines · Mike Galbraith

Subject: Re: [Announce] [patch] Modular Scheduler Core and Completely
FairScheduler [CFS]

Quoted 8 lines · Nick Piggin
Quoted 1 line · Mike Galbraith

Yup, and progress _is_ happening now, quite rapidly.

Progress as in progress on Ingo's scheduler. I still don't know how we'd decide when to replace the mainline scheduler or with what.

I don't think we can say Ingo's is better than the alternatives, can we?

No, that would require massive performance testing of all alternatives.

Quoted 7 lines
Quoted 2 lines

If there is some kind of bakeoff, then I'd like one of Con's designs to be involved, and mine, and Peter's...

The trouble with a bakeoff is that it's pretty darn hard to get people to test in the first place, and then comes weighting the subjective and hard performance numbers. If they're close in numbers, do you go with the one which starts the least flamewars or what?

it's especially hard if the people doing the testing need to find the latest patch and apply it.

even having a compile-time option to switch between them at least means that the testers can have confidence that the various patches haven't bitrotted.

boot time options would be even better, but I understand from previous discussions I've watched that this is performance critical enough that the overhead of this would throw off the results.

David Lang

#178 lore raw
In reply to Nick Piggin
Quoted 12 lines · Nick Piggin
Quoted 11 lines · Mike Galbraith
Quoted 5 lines · Peter Williams
Quoted 3 lines · Mike Galbraith

Demystify what? The casual observer need only read either your attempt
at writing a scheduler, or my attempts at fixing the one we have, to see that it was high time for someone with the necessary skills to step in.

Make that "someone with the necessary clout".

No, I was brutally honest to both of us, but quite correct.

Quoted 3 lines
Quoted 2 lines

Now progress can happen, which was _not_ happening before.

This is true.

Quoted 8 lines
Quoted 1 line

Yup, and progress _is_ happening now, quite rapidly.

Progress as in progress on Ingo's scheduler. I still don't know how we'd decide when to replace the mainline scheduler or with what.

I don't think we can say Ingo's is better than the alternatives, can we? If there is some kind of bakeoff, then I'd like one of Con's designs to be involved, and mine, and Peter's...

I myself was thinking of this as the chance for a much needed simplification of the scheduling code and if this can be done with the result being "reasonable" it then gives us the basis on which to propose improvements based on the ideas of others such as you mention.

As the size of the cpusched indicates, trying to evaluate alternative proposals based on the current O(1) scheduler is fraught. Hopefully, this initiative can fix this problem. Then we just need Ingo to listen to suggestions and he's showing signs of being willing to do this :-)

Quoted 3 lines

Maybe the progress is that more key people are becoming open to the idea of changing the scheduler.

That too.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#330 lore raw
In reply to Nick Piggin
Quoted 13 lines · Nick Piggin
Quoted 11 lines · Michael K. Edwards
Quoted 3 lines · Peter Williams

Note that I talk of run queues
not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

Quoted 7 lines

Why? If you do that, then your load balancer just becomes less flexible because it is harder to have tasks run on one or the other.

You can have single-runqueue-per-domain behaviour (or close to) just by relaxing all restrictions on idle load balancing within that domain. It is harder to go the other way and place any per-cpu affinity or restirctions with multiple cpus on a single runqueue.

Allowing N (where N can be one or greater) CPUs per run queue actually increases flexibility as you can still set N to 1 to get the current behaviour.

One advantage of allowing multiple CPUs per run queue would be at the smaller end of the system scale i.e. a PC with a single hyper threading chip (i.e. 2 CPUs) would not need to worry about load balancing at all if both CPUs used the one runqueue and all the nasty side effects that come with hyper threading would be minimized at the same time.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#179 lore raw
In reply to Peter Williams
Quoted 22 lines · Peter Williams
Quoted 12 lines · Nick Piggin
Quoted 11 lines · Mike Galbraith
Quoted 5 lines · Peter Williams
Quoted 3 lines · Mike Galbraith

Demystify what? The casual observer need only read either your attempt
at writing a scheduler, or my attempts at fixing the one we have, to see that it was high time for someone with the necessary skills to step in.

Make that "someone with the necessary clout".

No, I was brutally honest to both of us, but quite correct.

Quoted 3 lines
Quoted 2 lines

Now progress can happen, which was _not_ happening before.

This is true.

Quoted 8 lines
Quoted 1 line

Yup, and progress _is_ happening now, quite rapidly.

Progress as in progress on Ingo's scheduler. I still don't know how we'd decide when to replace the mainline scheduler or with what.

I don't think we can say Ingo's is better than the alternatives, can we? If there is some kind of bakeoff, then I'd like one of Con's designs to be involved, and mine, and Peter's...

Quoted 7 lines

I myself was thinking of this as the chance for a much needed simplification of the scheduling code and if this can be done with the result being "reasonable" it then gives us the basis on which to propose improvements based on the ideas of others such as you mention.

As the size of the cpusched indicates, trying to evaluate alternative proposals based on the current O(1) scheduler is fraught. Hopefully,

I don't know why. The problem is that you can't really evaluate good proposals by looking at the code (you can say that one is bad, ie. the current one, which has a huge amount of temporal complexity and is explicitly unfair), but it is pretty hard to say one behaves well.

And my scheduler for example cuts down the amount of policy code and code size significantly. I haven't looked at Con's ones for a while, but I believe they are also much more straightforward than mainline...

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

#331 lore raw
In reply to Peter Williams
Quoted 17 lines · Peter Williams
Quoted 16 lines · Nick Piggin
Quoted 11 lines · Michael K. Edwards
Quoted 3 lines · Peter Williams

Note that I talk of run queues
not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

Why? If you do that, then your load balancer just becomes less flexible because it is harder to have tasks run on one or the other.

Quoted 8 lines
Quoted 4 lines

You can have single-runqueue-per-domain behaviour (or close to) just by relaxing all restrictions on idle load balancing within that domain. It is harder to go the other way and place any per-cpu affinity or restirctions with multiple cpus on a single runqueue.

Allowing N (where N can be one or greater) CPUs per run queue actually increases flexibility as you can still set N to 1 to get the current behaviour.

But you add extra code for that on top of what we have, and are also prevented from making per-cpu assumptions.

And you can get N CPUs per runqueue behaviour by having them in a domain with no restrictions on idle balancing. So where does your increased flexibilty come from?

Quoted 5 lines

One advantage of allowing multiple CPUs per run queue would be at the smaller end of the system scale i.e. a PC with a single hyper threading chip (i.e. 2 CPUs) would not need to worry about load balancing at all if both CPUs used the one runqueue and all the nasty side effects that come with hyper threading would be minimized at the same time.

I don't know about that -- the current load balancer already minimises the nasty multi threading effects. SMT is very important for IBM's chips for example, and they've never had any problem with that side of it since it was introduced and bugs ironed out (at least, none that I've heard).

#180 lore raw
In reply to Nick Piggin

Hi Nick,

On Tue, Apr 17, 2007 at 06:29:54AM +0200, Nick Piggin wrote:
(...)

Quoted 6 lines

And my scheduler for example cuts down the amount of policy code and code size significantly. I haven't looked at Con's ones for a while, but I believe they are also much more straightforward than mainline...

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

Of course, if this is the case, the question will be raised. But as a general rule, I don't see much potential in O(1) to finely tune scheduling according to several criteria. In O(logN), you can adjust scheduling in realtime at a very low cost. Better processing of varying priorities or fork() comes to mind.

Regards,
Willy

#332 lore raw
In reply to Nick Piggin
Quoted 30 lines · Nick Piggin
Quoted 13 lines · Peter Williams
Quoted 12 lines · Nick Piggin
Quoted 11 lines · Michael K. Edwards
Quoted 3 lines · Peter Williams

Note that I talk of run queues
not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

Quoted 8 lines
Quoted 7 lines

Why? If you do that, then your load balancer just becomes less flexible because it is harder to have tasks run on one or the other.

You can have single-runqueue-per-domain behaviour (or close to) just by relaxing all restrictions on idle load balancing within that domain. It is harder to go the other way and place any per-cpu affinity or restirctions with multiple cpus on a single runqueue.

Allowing N (where N can be one or greater) CPUs per run queue actually increases flexibility as you can still set N to 1 to get the current behaviour.

But you add extra code for that on top of what we have, and are also prevented from making per-cpu assumptions.

And you can get N CPUs per runqueue behaviour by having them in a domain with no restrictions on idle balancing. So where does your increased flexibilty come from?

Quoted 8 lines
Quoted 1 line

One advantage of allowing multiple CPUs per run queue would be at the smaller end of the system scale i.e. a PC with a single hyper threading chip (i.e. 2 CPUs) would not need to worry about load balancing at all if both CPUs used the one runqueue and all the nasty side effects that come with hyper threading would be minimized at the same time.

I don't know about that -- the current load balancer already minimises the nasty multi threading effects. SMT is very important for IBM's chips for example, and they've never had any problem with that side of it since it was introduced and bugs ironed out (at least, none that I've heard).

There's a lot of ugly code in the load balancer that is only there to overcome the side effects of SMT and dual core. A lot of it was put there by Intel employees trying to make load balancing more friendly to their systems. What I'm suggesting is that an N CPUs per runqueue is a better way of achieving that end. I may (of course) be wrong but I think that the idea deserves more consideration than you're willing to give it.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#182 lore raw
In reply to Nick Piggin
Quoted 6 lines · Peter Williams
Quoted 6 lines

I myself was thinking of this as the chance for a much needed simplification of the scheduling code and if this can be done with the result being "reasonable" it then gives us the basis on which to propose improvements based on the ideas of others such as you mention. As the size of the cpusched indicates, trying to evaluate alternative proposals based on the current O(1) scheduler is fraught. Hopefully,

Quoted 9 lines · Nick Piggin

I don't know why. The problem is that you can't really evaluate good proposals by looking at the code (you can say that one is bad, ie. the current one, which has a huge amount of temporal complexity and is explicitly unfair), but it is pretty hard to say one behaves well. And my scheduler for example cuts down the amount of policy code and code size significantly. I haven't looked at Con's ones for a while, but I believe they are also much more straightforward than mainline... For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

All things are not equal; they all have different properties. I like getting rid of the queue-swapping artifacts as ebs and cfs have done, as the artifacts introduced there are nasty IMNSHO. I'm queueing up a demonstration of epoch expiry scheduling artifacts as a testcase, albeit one with no pass/fail semantics for its results, just detecting scheduler properties.

That said, inequality/inequivalence is not a superiority/inferiority ranking per se. What needs to come out of these discussions is a set of standards which a candidate for mainline must pass to be considered correct and a set of performance metrics by which to rank them. Video game framerates and some sort of way to automate window wiggle tests sound like good ideas, but automating such is beyond my userspace programming abilities. An organization able to devote manpower to devising such testcases will likely have to get involved for them to happen, I suspect.

On a random note, limitations on kernel address space make O(lg(n)) effectively O(1), albeit with large upper bounds on the worst case and an expected case much faster than the worst case.

-- wli

#181 lore raw
In reply to Willy Tarreau
Quoted 8 lines · Willy Tarreau

Hi Nick,

On Tue, Apr 17, 2007 at 06:29:54AM +0200, Nick Piggin wrote:
(...)

Quoted 4 lines

And my scheduler for example cuts down the amount of policy code and code size significantly. I haven't looked at Con's ones for a while, but I believe they are also much more straightforward than mainline...

Quoted 6 lines
Quoted 2 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

Of course, if this is the case, the question will be raised. But as a general rule, I don't see much potential in O(1) to finely tune scheduling according to several criteria.

What do you mean? By what criteria?

Quoted 3 lines

In O(logN), you can adjust scheduling in
realtime at a very low cost. Better processing of varying priorities or fork() comes to mind.

The main problem as I see it is choosing which task to run next and how much time to run it for. And given that there are typically far less than 58 (the number of priorities in nicksched) runnable tasks for a desktop system, I don't find it at all constraining to quantize my "next runnable" criteria onto that size of key.

Even if you do expect a huge number of runnable tasks, you would hope for fewer interactive ones toward the higher end of the priority scale.

Handwaving or even detailed design descriptions is simply not the best way to decide on a new scheduler, is all I'm saying.

#333 lore raw
In reply to Peter Williams
Quoted 7 lines · Peter Williams

There's a lot of ugly code in the load balancer that is only there to overcome the side effects of SMT and dual core. A lot of it was put there by Intel employees trying to make load balancing more friendly to their systems. What I'm suggesting is that an N CPUs per runqueue is a better way of achieving that end. I may (of course) be wrong but I think that the idea deserves more consideration than you're willing to give it.

This may be a good one to ask Ingo about, as he did significant performance work on per-core runqueues for SMT. While I did write per-node runqueue code for NUMA at some point in the past, I did no tuning or other performance work on it, only functionality.

I've actually dealt with kernels using elder versions of Ingo's code for per-core runqueues on SMT, but was never called upon to examine that particular code for either performance or stability, so I'm largely ignorant of what the perceived outcome of it was.

-- wli

#183 lore raw
In reply to William Lee Irwin III
Quoted 19 lines · William Lee Irwin III
Quoted 6 lines · Peter Williams
Quoted 6 lines

I myself was thinking of this as the chance for a much needed simplification of the scheduling code and if this can be done with the result being "reasonable" it then gives us the basis on which to propose improvements based on the ideas of others such as you mention. As the size of the cpusched indicates, trying to evaluate alternative proposals based on the current O(1) scheduler is fraught. Hopefully,

Quoted 9 lines · Nick Piggin

I don't know why. The problem is that you can't really evaluate good proposals by looking at the code (you can say that one is bad, ie. the current one, which has a huge amount of temporal complexity and is explicitly unfair), but it is pretty hard to say one behaves well. And my scheduler for example cuts down the amount of policy code and code size significantly. I haven't looked at Con's ones for a while, but I believe they are also much more straightforward than mainline... For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

Quoted 1 line

All things are not equal; they all have different properties. I like

Exactly. So we have to explore those properties and evaluate performance (in all meanings of the word). That's only logical.

Quoted 3 lines

On a random note, limitations on kernel address space make O(lg(n)) effectively O(1), albeit with large upper bounds on the worst case and an expected case much faster than the worst case.

Yeah. O(n!) is also O(1) if you can put an upper bound on n ;)

#334 lore raw
In reply to Peter Williams
Quoted 22 lines · Peter Williams
Quoted 14 lines · Nick Piggin

But you add extra code for that on top of what we have, and are also prevented from making per-cpu assumptions.

And you can get N CPUs per runqueue behaviour by having them in a domain with no restrictions on idle balancing. So where does your increased flexibilty come from?

Quoted 5 lines

One advantage of allowing multiple CPUs per run queue would be at the smaller end of the system scale i.e. a PC with a single hyper threading chip (i.e. 2 CPUs) would not need to worry about load balancing at all if both CPUs used the one runqueue and all the nasty side effects that come with hyper threading would be minimized at the same time.

Quoted 6 lines

I don't know about that -- the current load balancer already minimises the nasty multi threading effects. SMT is very important for IBM's chips for example, and they've never had any problem with that side of it since it was introduced and bugs ironed out (at least, none that I've heard).

Quoted 3 lines

There's a lot of ugly code in the load balancer that is only there to overcome the side effects of SMT and dual core. A lot of it was put there by Intel employees trying to make load balancing more friendly to

I agree that some of that has exploded complexity. I have some thoughts about better approaches for some of those things, but basically been stuck working on VM problems for a while.

Quoted 4 lines

their systems. What I'm suggesting is that an N CPUs per runqueue is a better way of achieving that end. I may (of course) be wrong but I think that the idea deserves more consideration than you're willing to give it.

Put it this way: it is trivial to group the load balancing stats of N CPUs with their own runqueues. Just put them under a domain and take the sum. The domain essentially takes on the same function as a single queue with N CPUs under it. Anything _further_ you can do with individual runqueues (like naturally adding an affinity pressure ranging from nothing to absolute) are things that you don't trivially get with 1:N approach. AFAIKS.

So I will definitely give any idea consideration, but I just need to be shown where the benefit comes from.

#305 lore raw
In reply to Nick Piggin
Quoted 21 lines · Nick Piggin
Quoted 20 lines · Peter Williams
Quoted 19 lines · Nick Piggin
Quoted 5 lines · Mike Galbraith
Quoted 4 lines · Peter Williams
Quoted 3 lines · Mike Galbraith

Demystify what? The casual observer need only read either your attempt
at writing a scheduler, or my attempts at fixing the one we have, to see that it was high time for someone with the necessary skills to step in.

Quoted 7 lines
Quoted 1 line

Make that "someone with the necessary clout".

No, I was brutally honest to both of us, but quite correct.

Quoted 3 lines
Quoted 2 lines

Now progress can happen, which was _not_ happening before.

This is true.

Yup, and progress _is_ happening now, quite rapidly.

Progress as in progress on Ingo's scheduler. I still don't know how we'd decide when to replace the mainline scheduler or with what.

I don't think we can say Ingo's is better than the alternatives, can we? If there is some kind of bakeoff, then I'd like one of Con's designs to be involved, and mine, and Peter's...

Quoted 8 lines
Quoted 3 lines

I myself was thinking of this as the chance for a much needed simplification of the scheduling code and if this can be done with the result being "reasonable" it then gives us the basis on which to propose improvements based on the ideas of others such as you mention.

As the size of the cpusched indicates, trying to evaluate alternative proposals based on the current O(1) scheduler is fraught. Hopefully,

I don't know why. The problem is that you can't really evaluate good proposals by looking at the code (you can say that one is bad, ie. the current one, which has a huge amount of temporal complexity and is explicitly unfair), but it is pretty hard to say one behaves well.

I meant that it's indicative of the amount of work that you have to do to implement a new scheduling discipline for evaluation.

Quoted 3 lines

And my scheduler for example cuts down the amount of policy code and code size significantly.

Yours is one of the smaller patches mainly because you perpetuate (or you did in the last one I looked at) the (horrible to my eyes) dual array (active/expired) mechanism. That this idea was bad should have been apparent to all as soon as the decision was made to excuse some tasks from being moved from the active array to the expired array. This essentially meant that there would be circumstances where extreme unfairness (to the extent of starvation in some cases) -- the very things that the mechanism was originally designed to ensure (as far as I can gather). Right about then in the development of the O(1) scheduler alternative solutions should have been sought.

Other hints that it was a bad idea was the need to transfer time slices between children and parents during fork() and exit().

This disregard for the dual array mechanism has prevented me from looking at the rest of your scheduler in any great detail so I can't comment on any other ideas that may be in there.

Quoted 2 lines

I haven't looked at Con's ones for a while,
but I believe they are also much more straightforward than mainline...

I like Con's scheduler (partly because it uses a single array) but mainly because it's nice and simple. However, his earlier schedulers were prone to starvation (admittedly, only if you went out of your way to make it happen) and I tried to convince him to use the anti starvation mechanism in my SPA schedulers but was unsuccessful. I haven't looked at his latest scheduler that sparked all this furore so can't comment on it.

Quoted 3 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

In the highly unlikely event that you can't separate them on technical grounds, Occam's razor recommends choosing the simplest solution. :-)

To digress, my main concern is that load balancing is being lumped in with this new change. It's becoming "accept this beg lump of new code or nothing". I'd rather see a good fix to the intra runqueue/CPU scheduler problem implemented first and then if there really are any outstanding problems with the load balancer attack them later. Them all being mixed up together gives me a nasty deja vu of impending disaster.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#165 lore raw
In reply to Nick Piggin
Quoted 3 lines · Nick Piggin

Well I know people have had woes with the scheduler for ever (I guess that isn't going to change :P). I think people generally lost a bit of interest in trying to improve the situation because of the upstream problem.

Yes.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#184 lore raw
In reply to Nick Piggin
Quoted 1 line · William Lee Irwin III
Quoted 1 line

All things are not equal; they all have different properties. I like

Quoted 2 lines · Nick Piggin

Exactly. So we have to explore those properties and evaluate performance (in all meanings of the word). That's only logical.

Any chance you'd be willing to put down a few thoughts on what sorts of standards you'd like to set for both correctness (i.e. the bare minimum a scheduler implementation must do to be considered valid beyond not oopsing) and performance metrics (i.e. things that produce numbers for each scheduler you can compare to say "this scheduler is better than this other scheduler at this.").

-- wli

#306 lore raw
In reply to Peter Williams
Quoted 7 lines · Peter Williams
Quoted 2 lines · Nick Piggin

And my scheduler for example cuts down the amount of policy code and code size significantly.

Yours is one of the smaller patches mainly because you perpetuate (or you did in the last one I looked at) the (horrible to my eyes) dual array (active/expired) mechanism.

Actually, I wasn't comparing with other out of tree schedulers (but it is good to know mine is among the smaller ones). I was comparing with the mainline scheduler, which also has the dual arrays.

Quoted 3 lines

That this idea was bad should have
been apparent to all as soon as the decision was made to excuse some tasks from being moved from the active array to the expired array. This

My patch doesn't implement any such excusing.

Quoted 5 lines

essentially meant that there would be circumstances where extreme unfairness (to the extent of starvation in some cases) -- the very things that the mechanism was originally designed to ensure (as far as I can gather). Right about then in the development of the O(1) scheduler alternative solutions should have been sought.

Fairness has always been my first priority, and I consider it a bug if it is possible for any process to get more CPU time than a CPU hog over the long term. Or over another task doing the same thing, for that matter.

Quoted 2 lines

Other hints that it was a bad idea was the need to transfer time slices between children and parents during fork() and exit().

I don't see how that has anything to do with dual arrays. If you put a new child at the back of the queue, then your various interactive shell commands that typically do a lot of dependant forking get slowed right down behind your compile job. If you give a new child its own timeslice irrespective of the parent, then you have things like 'make' (which doesn't use a lot of CPU time) spawning off lots of high priority children.

You need to do _something_ (Ingo's does). I don't see why this would be tied with a dual array. FWIW, mine doesn't do anything on exit() like most others, but it may need more tuning in this area.

Quoted 3 lines

This disregard for the dual array mechanism has prevented me from looking at the rest of your scheduler in any great detail so I can't comment on any other ideas that may be in there.

Well I wasn't really asking you to review it. As I said, everyone has their own idea of what a good design does, and review can't really distinguish between the better of two reasonable designs.

A fair evaluation of the alternatives seems like a good idea though. Nobody is actually against this, are they?

Quoted 10 lines
Quoted 2 lines

I haven't looked at Con's ones for a while,
but I believe they are also much more straightforward than mainline...

I like Con's scheduler (partly because it uses a single array) but mainly because it's nice and simple. However, his earlier schedulers were prone to starvation (admittedly, only if you went out of your way to make it happen) and I tried to convince him to use the anti starvation mechanism in my SPA schedulers but was unsuccessful. I haven't looked at his latest scheduler that sparked all this furore so can't comment on it.

I agree starvation or unfairness is unacceptable for a new scheduler.

Quoted 5 lines
Quoted 2 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

In the highly unlikely event that you can't separate them on technical grounds, Occam's razor recommends choosing the simplest solution. :-)

O(logN) vs O(1) is technical grounds.

But yeah, see my earlier comment: simplicity would be a factor too.

#281 lore raw
In reply to Nick Piggin
Quoted 4 lines · Nick Piggin
Quoted 1 line

All things are not equal; they all have different properties. I like

Exactly. So we have to explore those properties and evaluate performance (in all meanings of the word). That's only logical.

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;) And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.
I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

- Davide

#185 lore raw
In reply to William Lee Irwin III
Quoted 7 lines · William Lee Irwin III
Quoted 1 line · William Lee Irwin III
Quoted 1 line

All things are not equal; they all have different properties. I like

Quoted 2 lines · Nick Piggin

Exactly. So we have to explore those properties and evaluate performance (in all meanings of the word). That's only logical.

Quoted 6 lines

Any chance you'd be willing to put down a few thoughts on what sorts of standards you'd like to set for both correctness (i.e. the bare minimum a scheduler implementation must do to be considered valid beyond not oopsing) and performance metrics (i.e. things that produce numbers for each scheduler you can compare to say "this scheduler is better than this other scheduler at this.").

Yeah I guess that's the hard part :)

For correctness, I guess fairness is an easy one. I think that unfairness is basically a bug and that it would be very unfortunate to merge something unfair. But this is just within the context of a single runqueue... for better or worse, we allow some unfairness in multiprocessors for performance reasons of course.

Latency. Given N tasks in the system, an arbitrary task should get onto the CPU in a bounded amount of time (excluding events like freak IRQ holdoffs and such, obviously -- ie. just considering the context of the scheduler's state machine).

I wouldn't like to see a significant drop in any micro or macro benchmarks or even worse real workloads, but I could accept some if it means haaving a fair scheduler by default.

Now it isn't actually too hard to achieve the above, I think. The hard bit is trying to compare interactivity. Ideally, we'd be able to get scripted dumps of login sessions, and measure scheduling latencies of key proceses (sh/X/wm/xmms/firefox/etc). People would send a dump if they were having problems with any scheduler, and we could compare all of them against it. Wishful thinking!

#282 lore raw
In reply to Davide Libenzi
Quoted 5 lines · Davide Libenzi

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;) And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.

The additive nice_offset breaks nice levels. A multiplicative priority weighting of a different, nonnegative metric of cpu utilization from what's now used is required for nice levels to work. I've been trying to point this out politely by strongly suggesting testing whether nice levels work.

Quoted 6 lines · Davide Libenzi

I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

The trouble with thorough testing right now is that no one agrees on what the tests should be and a number of the testcases are not in great shape. An agreed-upon set of testcases for basic correctness should be devised and the implementations of those testcases need to be maintainable code and the tests set up for automated testing and changing their parameters without recompiling via command-line options.

Once there's a standard regression test suite for correctness, one needs to be devised for performance, including interactive performance. The primary difficulty I see along these lines is finding a way to automate tests of graphics and input device response performance. Others, like how deterministically priorities are respected over progressively smaller time intervals and noninteractive workload performance are nowhere near as difficult to arrange and in many cases already exist. Just reuse SDET, AIM7/AIM9, OAST, contest, interbench, et al.

-- wli

#303 lore raw
In reply to Davide Libenzi
Quoted 7 lines · Davide Libenzi
Quoted 4 lines · Nick Piggin
Quoted 1 line

All things are not equal; they all have different properties. I like

Exactly. So we have to explore those properties and evaluate performance (in all meanings of the word). That's only logical.

Quoted 11 lines

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;) And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.
I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

To be clear, I'm not saying O(logN) itself is a big problem. Type

plot [10:100] x with lines, log(x) with lines, 1 with lines

into gnuplot. I was just trying to point out that we need to evalute things. Considering how long we've had this scheduler with its known deficiencies, let's pick a new one wisely.

#304 lore raw
Quoted 3 lines · Nick Piggin

To be clear, I'm not saying O(logN) itself is a big problem. Type

plot [10:100] x with lines, log(x) with lines, 1 with lines

Haha, Nick, I know how a log() looks like :)
The Time Ring I posted as example (that nothing is other than a ring-based bucket sort), keeps O(1) if you can concede some timer clustering.

- Davide

#283 lore raw
In reply to William Lee Irwin III
Quoted 22 lines · William Lee Irwin III
Quoted 2 lines · Davide Libenzi

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;)
And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.

The additive nice_offset breaks nice levels. A multiplicative priority weighting of a different, nonnegative metric of cpu utilization from what's now used is required for nice levels to work. I've been trying to point this out politely by strongly suggesting testing whether nice levels work.

Quoted 2 lines · Davide Libenzi

I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

The trouble with thorough testing right now is that no one agrees on what the tests should be and a number of the testcases are not in great shape. An agreed-upon set of testcases for basic correctness should be devised and the implementations of those testcases need to be maintainable code and the tests set up for automated testing and changing their parameters without recompiling via command-line options.

Quoted 8 lines

Once there's a standard regression test suite for correctness, one needs to be devised for performance, including interactive performance. The primary difficulty I see along these lines is finding a way to automate tests of graphics and input device response performance. Others, like how deterministically priorities are respected over progressively smaller time intervals and noninteractive workload performance are nowhere near as difficult to arrange and in many cases already exist. Just reuse SDET, AIM7/AIM9, OAST, contest, interbench, et al.

At this point, I'd like direct everyone's attention to the simloads package:

<http://downloads.sourceforge.net/cpuse/simloads-0.1.1.tar.gz>

which contains a set of programs designed to be used in the construction of CPU scheduler tests. Of particular use is the aspin program which can be used to launch tasks with specified sleep/wake characteristics.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#284 lore raw
In reply to William Lee Irwin III
Quoted 8 lines · William Lee Irwin III

The trouble with thorough testing right now is that no one agrees on what the tests should be and a number of the testcases are not in great shape. An agreed-upon set of testcases for basic correctness should be devised and the implementations of those testcases need to be maintainable code and the tests set up for automated testing and changing their parameters without recompiling via command-line options.

Quoted 8 lines

Once there's a standard regression test suite for correctness, one needs to be devised for performance, including interactive performance. The primary difficulty I see along these lines is finding a way to automate tests of graphics and input device response performance. Others, like how deterministically priorities are respected over progressively smaller time intervals and noninteractive workload performance are nowhere near as difficult to arrange and in many cases already exist. Just reuse SDET, AIM7/AIM9, OAST, contest, interbench, et al.

Definitely. It would be really good if we could have interactivity regression tests too (see my earlier wishful email). The problem with a lot of the scripted interactivity tests I see is that they don't really capture the complexities of the interactions between, say, an interactive X session. Others just go straight for trying to exploit the design by making lots of high priority processes runnablel at once. This just provides an unrealistic decoy and you end up trying to tune for the wrong thing.

#285 lore raw
In reply to William Lee Irwin III
Quoted 15 lines · William Lee Irwin III
Quoted 6 lines · Davide Libenzi

I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

The trouble with thorough testing right now is that no one agrees on what the tests should be and a number of the testcases are not in great shape. An agreed-upon set of testcases for basic correctness should be devised and the implementations of those testcases need to be maintainable code and the tests set up for automated testing and changing their parameters without recompiling via command-line options.

Quoted 8 lines

Once there's a standard regression test suite for correctness, one needs to be devised for performance, including interactive performance. The primary difficulty I see along these lines is finding a way to automate tests of graphics and input device response performance. Others, like how deterministically priorities are respected over progressively smaller time intervals and noninteractive workload performance are nowhere near as difficult to arrange and in many cases already exist. Just reuse SDET, AIM7/AIM9, OAST, contest, interbench, et al.

What I meant was, that the rules (requirements and associated test cases) for this new Scheduler Amazing Race should be set forward, and not kept a moving target to fit&follow one or the other implementation.

- Davide

#286 lore raw
Quoted 26 lines · Davide Libenzi
Quoted 15 lines · William Lee Irwin III
Quoted 6 lines · Davide Libenzi

I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

The trouble with thorough testing right now is that no one agrees on what the tests should be and a number of the testcases are not in great shape. An agreed-upon set of testcases for basic correctness should be devised and the implementations of those testcases need to be maintainable code and the tests set up for automated testing and changing their parameters without recompiling via command-line options.

Quoted 8 lines

Once there's a standard regression test suite for correctness, one needs to be devised for performance, including interactive performance. The primary difficulty I see along these lines is finding a way to automate tests of graphics and input device response performance. Others, like how deterministically priorities are respected over progressively smaller time intervals and noninteractive workload performance are nowhere near as difficult to arrange and in many cases already exist. Just reuse SDET, AIM7/AIM9, OAST, contest, interbench, et al.

Quoted 3 lines

What I meant was, that the rules (requirements and associated test cases) for this new Scheduler Amazing Race should be set forward, and not kept a moving target to fit&follow one or the other implementation.

Exactly. Well I don't mind if it is a moving target as such, just as long as the decisions are rational (no "blah is more important because I say so").

#287 lore raw
In reply to William Lee Irwin III
Quoted 7 lines · William Lee Irwin III
Quoted 5 lines · Davide Libenzi

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;) And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.

Quoted 5 lines

The additive nice_offset breaks nice levels. A multiplicative priority weighting of a different, nonnegative metric of cpu utilization from what's now used is required for nice levels to work. I've been trying to point this out politely by strongly suggesting testing whether nice levels work.

granted, CFS's nice code is still incomplete, but you err quite significantly with this extreme statement that they are "broken".

nice levels certainly work to a fair degree even in the current code and much of the focus is elsewhere - just try it. (In fact i claim that CFS's nice levels often work _better_ than the mainline scheduler's nice level support, for the testcases that matter to users.)

The precise behavior of nice levels, as i pointed it out in previous mails, is largely 'uninteresting' and it has changed multiple times in the past 10 years.

What matters to users is mainly: whether X reniced to -10 does get enough CPU time and whether stuff reniced to +19 doesnt take away too much CPU time from the rest of the system. _How_ a Linux scheduler achieves this is an internal matter and certainly CFS does it in a hacky way at the moment.

All the rest, 'CPU bandwidth utilization' or whatever abstract metric we could come up with is just a fancy academic technicality that has no real significance to any of the testers who are trying CFS right now.

Sure we prefer final solutions that are clean and make sense (because such things are the easiest to maintain long-term), and often such final solutions are quite close to academic concepts, and i think Davide correctly observed this by saying that "the final key calculation code will end up quite different from what it looks now", but your extreme-end claim of 'breakage' for something that is just plain incomplete is not really a fair characterisation at this point.

Anyone who thinks that there exists only two kinds of code: 100% correct and 100% incorrect with no shades of grey inbetween is in reality a sort of an extremist: whom, depending on mood and affection, we could call either a 'coding purist' or a 'coding taliban' ;-)

Ingo

#288 lore raw
Quoted 24 lines · Ingo Molnar
Quoted 7 lines · William Lee Irwin III
Quoted 5 lines · Davide Libenzi

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;) And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.

Quoted 5 lines

The additive nice_offset breaks nice levels. A multiplicative priority weighting of a different, nonnegative metric of cpu utilization from what's now used is required for nice levels to work. I've been trying to point this out politely by strongly suggesting testing whether nice levels work.

granted, CFS's nice code is still incomplete, but you err quite significantly with this extreme statement that they are "broken".

nice levels certainly work to a fair degree even in the current code and much of the focus is elsewhere - just try it. (In fact i claim that CFS's nice levels often work _better_ than the mainline scheduler's nice level support, for the testcases that matter to users.)

Quoted 7 lines

The precise behavior of nice levels, as i pointed it out in previous mails, is largely 'uninteresting' and it has changed multiple times in the past 10 years.

What matters to users is mainly: whether X reniced to -10 does get enough CPU time and whether stuff reniced to +19 doesnt take away too much CPU time from the rest of the system.

I agree there.

Quoted 16 lines

_How_ a Linux scheduler
achieves this is an internal matter and certainly CFS does it in a hacky way at the moment.

All the rest, 'CPU bandwidth utilization' or whatever abstract metric we could come up with is just a fancy academic technicality that has no real significance to any of the testers who are trying CFS right now.

Sure we prefer final solutions that are clean and make sense (because such things are the easiest to maintain long-term), and often such final solutions are quite close to academic concepts, and i think Davide correctly observed this by saying that "the final key calculation code will end up quite different from what it looks now", but your extreme-end claim of 'breakage' for something that is just plain incomplete is not really a fair characterisation at this point.

Quoted 4 lines

Anyone who thinks that there exists only two kinds of code: 100% correct and 100% incorrect with no shades of grey inbetween is in reality a sort of an extremist: whom, depending on mood and affection, we could call either a 'coding purist' or a 'coding taliban' ;-)

Only if you are an extremist-naming extremist with no shades of grey. Others, like myself, also include 'coding al-qaeda' and 'coding john howard' in that scale.

#307 lore raw
In reply to Nick Piggin
Quoted 25 lines · Nick Piggin
Quoted 4 lines · Peter Williams
Quoted 2 lines · Nick Piggin

And my scheduler for example cuts down the amount of policy code and code size significantly.

Yours is one of the smaller patches mainly because you perpetuate (or you did in the last one I looked at) the (horrible to my eyes) dual array (active/expired) mechanism.

Actually, I wasn't comparing with other out of tree schedulers (but it is good to know mine is among the smaller ones). I was comparing with the mainline scheduler, which also has the dual arrays.

Quoted 2 lines

That this idea was bad should have
been apparent to all as soon as the decision was made to excuse some tasks from being moved from the active array to the expired array. This

My patch doesn't implement any such excusing.

Quoted 1 line

essentially meant that there would be circumstances where extreme unfairness (to the extent of starvation in some cases) -- the very things that the mechanism was originally designed to ensure (as far as I can gather). Right about then in the development of the O(1) scheduler alternative solutions should have been sought.

Fairness has always been my first priority, and I consider it a bug if it is possible for any process to get more CPU time than a CPU hog over the long term. Or over another task doing the same thing, for that matter.

Quoted 3 lines
Quoted 1 line

Other hints that it was a bad idea was the need to transfer time slices between children and parents during fork() and exit().

I don't see how that has anything to do with dual arrays.

It's totally to do with the dual arrays. The only real purpose of the time slice in O(1) (regardless of what its perceived purpose was) was to control the switching between the arrays.

Quoted 7 lines

If you put
a new child at the back of the queue, then your various interactive shell commands that typically do a lot of dependant forking get slowed right down behind your compile job. If you give a new child its own timeslice irrespective of the parent, then you have things like 'make' (which doesn't use a lot of CPU time) spawning off lots of high priority children.

This is an artefact of trying to control nice using time slices while using them for controlling array switching and whatever else they were being used for. Priority (static and dynamic) is the the best way to implement nice.

Quoted 6 lines

You need to do _something_ (Ingo's does). I don't see why this would be tied with a dual array. FWIW, mine doesn't do anything on exit() like most others, but it may need more tuning in this area.

Quoted 8 lines
Quoted 1 line

This disregard for the dual array mechanism has prevented me from looking at the rest of your scheduler in any great detail so I can't comment on any other ideas that may be in there.

Well I wasn't really asking you to review it. As I said, everyone has their own idea of what a good design does, and review can't really distinguish between the better of two reasonable designs.

A fair evaluation of the alternatives seems like a good idea though. Nobody is actually against this, are they?

No. It would be nice if the basic ideas that each scheduler tries to implement could be extracted and explained though. This could lead to a melding of ideas that leads to something quite good.

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

I haven't looked at Con's ones for a while,
but I believe they are also much more straightforward than mainline...

I like Con's scheduler (partly because it uses a single array) but mainly because it's nice and simple. However, his earlier schedulers were prone to starvation (admittedly, only if you went out of your way to make it happen) and I tried to convince him to use the anti starvation mechanism in my SPA schedulers but was unsuccessful. I haven't looked at his latest scheduler that sparked all this furore so can't comment on it.

Quoted 8 lines

I agree starvation or unfairness is unacceptable for a new scheduler.

Quoted 3 lines
Quoted 2 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

In the highly unlikely event that you can't separate them on technical grounds, Occam's razor recommends choosing the simplest solution. :-)

O(logN) vs O(1) is technical grounds.

In that case I'd go O(1) provided that the k factor for the O(1) wasn't greater than O(logN)'s k factor multiplied by logMaxN.

Quoted 2 lines

But yeah, see my earlier comment: simplicity would be a factor too.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#308 lore raw
Quoted 9 lines · Peter Williams
Quoted 4 lines · Nick Piggin
Quoted 2 lines

Other hints that it was a bad idea was the need to transfer time slices between children and parents during fork() and exit().

I don't see how that has anything to do with dual arrays.

It's totally to do with the dual arrays. The only real purpose of the time slice in O(1) (regardless of what its perceived purpose was) was to control the switching between the arrays.

The O(1) design is pretty convoluted in that regard. In my scheduler, the only purpose of the arrays is to renew time slices.

The fork/exit logic is added to make interactivity better. Ingo's scheduler has similar equivalent logic.

Quoted 8 lines
Quoted 7 lines

If you put
a new child at the back of the queue, then your various interactive shell commands that typically do a lot of dependant forking get slowed right down behind your compile job. If you give a new child its own timeslice irrespective of the parent, then you have things like 'make' (which doesn't use a lot of CPU time) spawning off lots of high priority children.

Quoted 4 lines

This is an artefact of trying to control nice using time slices while using them for controlling array switching and whatever else they were being used for. Priority (static and dynamic) is the the best way to implement nice.

I don't like the timeslice based nice in mainline. It's too nasty with latencies. nicksched is far better in that regard IMO.

But I don't know how you can assert a particular way is the best way to do something.

Quoted 37 lines
Quoted 9 lines

You need to do _something_ (Ingo's does). I don't see why this would be tied with a dual array. FWIW, mine doesn't do anything on exit() like most others, but it may need more tuning in this area.

Quoted 3 lines

This disregard for the dual array mechanism has prevented me from looking at the rest of your scheduler in any great detail so I can't comment on any other ideas that may be in there.

Quoted 6 lines

Well I wasn't really asking you to review it. As I said, everyone has their own idea of what a good design does, and review can't really distinguish between the better of two reasonable designs.

A fair evaluation of the alternatives seems like a good idea though. Nobody is actually against this, are they?

No. It would be nice if the basic ideas that each scheduler tries to implement could be extracted and explained though. This could lead to a melding of ideas that leads to something quite good.

Quoted 17 lines
Quoted 11 lines
Quoted 4 lines

I haven't looked at Con's ones for a while,
but I believe they are also much more straightforward than mainline...

I like Con's scheduler (partly because it uses a single array) but mainly because it's nice and simple. However, his earlier schedulers were prone to starvation (admittedly, only if you went out of your way to make it happen) and I tried to convince him to use the anti starvation mechanism in my SPA schedulers but was unsuccessful. I haven't looked at his latest scheduler that sparked all this furore so can't comment on it.

I agree starvation or unfairness is unacceptable for a new scheduler.

Quoted 2 lines
Quoted 2 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

In the highly unlikely event that you can't separate them on technical grounds, Occam's razor recommends choosing the simplest solution. :-)

O(logN) vs O(1) is technical grounds.

In that case I'd go O(1) provided that the k factor for the O(1) wasn't greater than O(logN)'s k factor multiplied by logMaxN.

Yes, or even significantly greater around typical large sizes of N.

#369 lore raw
In reply to Ingo Molnar
Quoted 97 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.

[ QuickStart: apply the patch to v2.6.21-rc6, recompile, reboot. The
new scheduler will be active by default and all tasks will default to the new SCHED_FAIR interactive scheduling class. ]

Highlights are:

- the introduction of Scheduling Classes: an extensible hierarchy of scheduler modules. These modules encapsulate scheduling policy details and are handled by the scheduler core without the core code assuming about them too much.

- sched_fair.c implements the 'CFS desktop scheduler': it is a replacement for the vanilla scheduler's SCHED_OTHER interactivity code.

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!

The CFS patch uses a completely different approach and implementation from RSDL/SD. My goal was to make CFS's interactivity quality exceed that of RSDL/SD, which is a high standard to meet :-) Testing feedback is welcome to decide this one way or another. [ and, in any case, all of SD's logic could be added via a kernel/sched_sd.c module as well, if Con is interested in such an approach. ]

CFS's design is quite radical: it does not use runqueues, it uses a time-ordered rbtree to build a 'timeline' of future task execution, and thus has no 'array switch' artifacts (by which both the vanilla scheduler and RSDL/SD are affected).

CFS uses nanosecond granularity accounting and does not rely on any jiffies or other HZ detail. Thus the CFS scheduler has no notion of 'timeslices' and has no heuristics whatsoever. There is only one central tunable:

/proc/sys/kernel/sched_granularity_ns

which can be used to tune the scheduler from 'desktop' (low latencies) to 'server' (good batching) workloads. It defaults to a setting suitable for desktop workloads. SCHED_BATCH is handled by the CFS scheduler module too.

due to its design, the CFS scheduler is not prone to any of the 'attacks' that exist today against the heuristics of the stock
scheduler: fiftyp.c, thud.c, chew.c, ring-test.c, massive_intr.c all work fine and do not impact interactivity and produce the expected behavior.

the CFS scheduler has a much stronger handling of nice levels and
SCHED_BATCH: both types of workloads should be isolated much more agressively than under the vanilla scheduler.

( another rdetail: due to nanosec accounting and timeline sorting,
sched_yield() support is very simple under CFS, and in fact under CFS sched_yield() behaves much better than under any other scheduler i have tested so far. )

- sched_rt.c implements SCHED_FIFO and SCHED_RR semantics, in a simpler way than the vanilla scheduler does. It uses 100 runqueues (for all 100 RT priority levels, instead of 140 in the vanilla scheduler) and it needs no expired array.

- reworked/sanitized SMP load-balancing: the runqueue-walking assumptions are gone from the load-balancing code now, and iterators of the scheduling modules are used. The balancing code got quite a bit simpler as a result.

the core scheduler got smaller by more than 700 lines:

 kernel/sched.c | 1454 ++++++++++++++++------------------------------------------------
 1 file changed, 372 insertions(+), 1082 deletions(-)

and even adding all the scheduling modules, the total size impact is relatively small:

 18 files changed, 1454 insertions(+), 1133 deletions(-)

most of the increase is due to extensive comments. The kernel size impact is in fact a small negative:

   text    data     bss     dec     hex filename
  23366    4001      24   27391    6aff kernel/sched.o.vanilla
  24159    2705      56   26920    6928 kernel/sched.o.CFS
Quoted 8 lines

(this is mainly due to the benefit of getting rid of the expired array and its data structure overhead.)

thanks go to Thomas Gleixner and Arjan van de Ven for review of this patchset.

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

Pushed this through the test.kernel.org and nothing new blew up. Notably the kernbench figures are within expectations even on the bigger numa systems, commonly badly affected by balancing problems in the schedular.

I see there is a second one out, I'll push that one through too.

-apw

#289 lore raw
In reply to Nick Piggin
Quoted 9 lines · Nick Piggin
Quoted 5 lines

Anyone who thinks that there exists only two kinds of code: 100% correct and 100% incorrect with no shades of grey inbetween is in reality a sort of an extremist: whom, depending on mood and affection, we could call either a 'coding purist' or a 'coding taliban' ;-)

Only if you are an extremist-naming extremist with no shades of grey. Others, like myself, also include 'coding al-qaeda' and 'coding john howard' in that scale.

heh ;) You, you ... nitpicking extremist! ;)

And beware that you just commited another act of extremism too:

Quoted 1 line

I agree there.

because you just went to the extreme position of saying that "i agree with this portion 100%", instead of saying "this seems to be 91.5% correct in my opinion, Tue, 17 Apr 2007 09:40:25 +0200".

and the nasty thing is, that in reality even shades of grey, if you print them out, are just a set of extreme black dots on an extreme white sheet of paper! ;)

[ so i guess we've got to consider the scope of extremism too: the
larger the scope, the more limiting and hence the more dangerous it is. ]

Ingo

#344 lore raw
In reply to a message not in the archive
Quoted 6 lines · William Lee Irwin III
Quoted 2 lines · Peter Williams

This doesn't make any sense to me.
For a start, exact simultaneous operation would be impossible to achieve except with highly specialized architecture such as the long departed transputer. And secondly, I can't see why it's necessary.

We're not going to make any headway here, so we might as well drop the thread.

Yes, we were starting to go around in circles weren't we?

Quoted 11 lines

There are other things to talk about anyway, for instance I'm seeing interest in plugsched come about from elsewhere and am taking an interest in getting it into shape wrt. various design goals therefore.

Probably the largest issue of note is getting scheduler drivers loadable as kernel modules. Addressing the points Ingo made that can be addressed are also lined up for this effort.

Comments on which directions you'd like this to go in these respects would be appreciated, as I regard you as the current "project owner."

I'd do scan through LKML from about 18 months ago looking for mention of runtime configurable version of plugsched. Some students at a university (in Germany, I think) posted some patches adding this feature to plugsched around about then.

I never added them to plugsched proper as I knew (from previous experience when the company I worked for posted patches with similar functionality) that Linux would like this idea less than he did the current plugsched mechanism.

Unfortunately, my own cache of the relevant e-mails got overwritten during a Fedora Core upgrade (I've since moved /var onto a separate drive to avoid a repetition) or I would dig them out and send them to you. I'd provided with copies of the company's patches to use as a guide to how to overcome the problems associated with changing schedulers on a running system (a few non trivial locking issues pop up).

Maybe if one of the students still reads LKML he will provide a pointer.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#186 lore raw
In reply to Nick Piggin
Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

Any chance you'd be willing to put down a few thoughts on what sorts of standards you'd like to set for both correctness (i.e. the bare minimum a scheduler implementation must do to be considered valid beyond not oopsing) and performance metrics (i.e. things that produce numbers for each scheduler you can compare to say "this scheduler is better than this other scheduler at this.").

Quoted 6 lines · Nick Piggin

Yeah I guess that's the hard part :)
For correctness, I guess fairness is an easy one. I think that unfairness is basically a bug and that it would be very unfortunate to merge something unfair. But this is just within the context of a single runqueue... for better or worse, we allow some unfairness in multiprocessors for performance reasons of course.

Requiring that identical tasks be allocated equal shares of CPU bandwidth is the easy part here. ringtest.c exercises another aspect of fairness that is extremely important. Generalizing ringtest.c is a good idea for fairness testing.

But another aspect of fairness is that "controlled unfairness" is also intended to exist, in no small part by virtue of nice levels, but also in the form of favoring tasks that are considered interactive somehow. Testing various forms of controlled unfairness to ensure that they are indeed controlled and otherwise have the semantics intended is IMHO the more difficult aspect of fairness testing.

Quoted 4 lines · Nick Piggin

Latency. Given N tasks in the system, an arbitrary task should get onto the CPU in a bounded amount of time (excluding events like freak IRQ holdoffs and such, obviously -- ie. just considering the context of the scheduler's state machine).

ISTR Davide Libenzi having a scheduling latency test a number of years ago. Resurrecting that and tuning it to the needs of this kind of testing sounds relevant here. The test suite Peter Willliams mentioned would also help.

Quoted 3 lines · Nick Piggin

I wouldn't like to see a significant drop in any micro or macro benchmarks or even worse real workloads, but I could accept some if it means haaving a fair scheduler by default.

Quoted 6 lines · Nick Piggin

Now it isn't actually too hard to achieve the above, I think. The hard bit is trying to compare interactivity. Ideally, we'd be able to get scripted dumps of login sessions, and measure scheduling latencies of key proceses (sh/X/wm/xmms/firefox/etc). People would send a dump if they were having problems with any scheduler, and we could compare all of them against it. Wishful thinking!

That's a pretty good idea. I'll queue up writing something of that form as well.

-- wli

#336 lore raw
In reply to Nick Piggin
Quoted 7 lines · Michael K. Edwards
Quoted 7 lines

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

Quoted 2 lines · Nick Piggin

Why? If you do that, then your load balancer just becomes less flexible because it is harder to have tasks run on one or the other.

Quoted 4 lines · Nick Piggin

You can have single-runqueue-per-domain behaviour (or close to) just by relaxing all restrictions on idle load balancing within that domain. It is harder to go the other way and place any per-cpu affinity or restirctions with multiple cpus on a single runqueue.

The big sticking point here is order-sensitivity. One can point to stringent sched_yield() ordering but that's not so important in and of itself. The more significant case is RT applications which are order- sensitive. Per-cpu runqueues rather significantly disturb the ordering requirements of applications that care about it.

In terms of a plugging framework, the per-cpu arrangement precludes or makes extremely awkward scheduling policies that don't have per-cpu runqueues, for instance, the 2.4.x policy. There is also the alternate SMP scalability strategy of a lockless scheduler with a single global queue, which is more performance-oriented.

-- wli

#311 lore raw
In reply to Peter Williams
Quoted 13 lines · Peter Williams
Quoted 2 lines

And my scheduler for example cuts down the amount of policy code and code size significantly.

Yours is one of the smaller patches mainly because you perpetuate (or you did in the last one I looked at) the (horrible to my eyes) dual array (active/expired) mechanism. That this idea was bad should have been apparent to all as soon as the decision was made to excuse some tasks from being moved from the active array to the expired array. This essentially meant that there would be circumstances where extreme unfairness (to the extent of starvation in some cases) -- the very things that the mechanism was originally designed to ensure (as far as I can gather). Right about then in the development of the O(1) scheduler alternative solutions should have been sought.

in hindsight i'd agree. But back then we were clearly not ready for fine-grained accurate statistics + trees (cpus are alot faster at more complex arithmetics today, plus people still believed that low-res can be done well enough), and taking out any of these two concepts from CFS would result in a similarly complex runqueue implementation. Also, the array switch was just thought to be of another piece of 'if the heuristics go wrong, we fall back to an array switch' logic, right in line with the other heuristics. And you have to accept it, mainline's ability to auto-renice make -j jobs (and other CPU hogs) was quite a plus for developers, so it had (and probably still has) quite some inertia.

Ingo

#290 lore raw
In reply to Ingo Molnar
Quoted 5 lines · William Lee Irwin III
Quoted 5 lines

The additive nice_offset breaks nice levels. A multiplicative priority weighting of a different, nonnegative metric of cpu utilization from what's now used is required for nice levels to work. I've been trying to point this out politely by strongly suggesting testing whether nice levels work.

Quoted 2 lines · Ingo Molnar

granted, CFS's nice code is still incomplete, but you err quite significantly with this extreme statement that they are "broken".

I used the word relatively loosely. Nothing extreme is going on. Maybe the phrasing exaggerated the force of the opinion. I'm sorry about having misspoke so.

Quoted 4 lines · Ingo Molnar

nice levels certainly work to a fair degree even in the current code and much of the focus is elsewhere - just try it. (In fact i claim that CFS's nice levels often work _better_ than the mainline scheduler's nice level support, for the testcases that matter to users.)

Al Boldi's testcase appears to reveal some issues. I'm plotting a testcase of my own if I can ever get past responding to email.

Quoted 3 lines · Ingo Molnar

The precise behavior of nice levels, as i pointed it out in previous mails, is largely 'uninteresting' and it has changed multiple times in the past 10 years.

I expect that whether a scheduler can handle such prioritization has a rather strong predictive quality regarding whether it can handle, say, CKRM controls. I remain convinced that there should be some target behavior and that some attempt should be made to achieve it. I don't think any particular behavior is best, just that the behavior should be well-defined.

Quoted 5 lines · Ingo Molnar

What matters to users is mainly: whether X reniced to -10 does get enough CPU time and whether stuff reniced to +19 doesnt take away too much CPU time from the rest of the system. _How_ a Linux scheduler achieves this is an internal matter and certainly CFS does it in a hacky way at the moment.

It's not so far out. Basically just changing the key calculation in a relatively simple manner should get things into relatively good shape. It can, of course, be done other ways (I did it a rather different way in vdls, though that method is not likely to be considered desirable).

I can't really write a testcase for such loose semantics, so the above description is useless to me. These squishy sorts of definitions of semantics are also uninformative to users, who, I would argue, do have some interest in what nice levels mean. There have been at least a small number of concerns about the strength of nice levels, and it would reveal issues surrounding that area earlier if there were an objective one could test to see if it were achieved.

It's furthermore a user-visible change in system call semantics we should be more careful about changing out from beneath users.

So I see a lot of good reasons to pin down nice numbers. Incompleteness is not a particularly mortal sin, but the proliferation of competing schedulers is creating a need for standards, and that's what I'm really on about.

Quoted 3 lines · Ingo Molnar

All the rest, 'CPU bandwidth utilization' or whatever abstract metric we could come up with is just a fancy academic technicality that has no real significance to any of the testers who are trying CFS right now.

I could say "percent cpu" if it sounds less like formal jargon, which "CPU bandwidth utilization" isn't really.

Quoted 7 lines · Ingo Molnar

Sure we prefer final solutions that are clean and make sense (because such things are the easiest to maintain long-term), and often such final solutions are quite close to academic concepts, and i think Davide correctly observed this by saying that "the final key calculation code will end up quite different from what it looks now", but your extreme-end claim of 'breakage' for something that is just plain incomplete is not really a fair characterisation at this point.

It wasn't meant to be quite as strong a statement as it came out. Sorry about that.

Quoted 4 lines · Ingo Molnar

Anyone who thinks that there exists only two kinds of code: 100% correct and 100% incorrect with no shades of grey inbetween is in reality a sort of an extremist: whom, depending on mood and affection, we could call either a 'coding purist' or a 'coding taliban' ;-)

I've made no such claims. Also rest assured that the tone of the critique is not hostile, and wasn't meant to sound that way.

Also, given the general comments it appears clear that some statistical metric of deviation from the intended behavior furthermore qualified by timescale is necessary, so this appears to be headed toward a sort of performance metric as opposed to a pass/fail test anyway. However, to even measure this at all, some statement of intention is required. I'd prefer that there be a Linux-standard semantics for nice so results are more directly comparable and so that users also get similar nice behavior from the scheduler as it varies over time and possibly implementations if users should care to switch them out with some scheduler patch or other.

-- wli

#291 lore raw
Quoted 2 lines · William Lee Irwin III

[...] Also rest assured that the tone of the critique is not hostile, and wasn't meant to sound that way.

ok :) (And i guess i was too touchy - sorry about coming out swinging.)

Quoted 10 lines

Also, given the general comments it appears clear that some statistical metric of deviation from the intended behavior furthermore qualified by timescale is necessary, so this appears to be headed toward a sort of performance metric as opposed to a pass/fail test anyway. However, to even measure this at all, some statement of intention is required. I'd prefer that there be a Linux-standard semantics for nice so results are more directly comparable and so that users also get similar nice behavior from the scheduler as it varies over time and possibly implementations if users should care to switch them out with some scheduler patch or other.

yeah. If you could come up with a sane definition that also translates into low overhead on the algorithm side that would be great! The only good generic definition i could come up with (nice levels are isolated buckets with a constant maximum relative percentage of CPU time available to every active bucket) resulted in having a per-nice-level array of rbtree roots, which did not look worth the hassle at first sight :-)

until now the main approach for nice levels in Linux was always:
"implement your main scheduling logic for nice 0 and then look for some low-overhead method that can be glued to it that does something that behaves like nice levels". Feel free to turn that around into a more natural approach, but the algorithm should remain fairly simple i think.

Ingo

#370 lore raw
In reply to Andy Whitcroft
Quoted 10 lines · Andy Whitcroft
Quoted 3 lines

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

Pushed this through the test.kernel.org and nothing new blew up. Notably the kernbench figures are within expectations even on the bigger numa systems, commonly badly affected by balancing problems in the schedular.

I see there is a second one out, I'll push that one through too.

Well I just sent some feedback on cfs-v2, but realised it went off-list, so I'll resend here because others may find it interesting too. Sorry about jamming it in here, but it is relevant to performance...

Anyway, roughly in the context of good cfs-v2 interactivity, I wrote:

Well I'm not too surprised. I am disappointed that it uses such small timeslices (or whatever they are called) as the default.

Using small timeslices is actually a pretty easy way to ensure everything stays smooth even under load, but is bad for efficiency. Sure you can say you'll have desktop and server tunings, but... With nicksched I'm testing a default timeslice of *300ms* even on the desktop, wheras Ingo's seems to be effectively 3ms :P So if you compare default tunings, it isn't exactly fair!

Kbuild times on a 2x Xeon:

2.6.21-rc7
508.87user 32.47system 2:17.82elapsed 392%CPU
509.05user 32.25system 2:17.84elapsed 392%CPU
508.75user 32.26system 2:17.83elapsed 392%CPU
508.63user 32.17system 2:17.88elapsed 392%CPU
509.01user 32.26system 2:17.90elapsed 392%CPU
509.08user 32.20system 2:17.95elapsed 392%CPU

2.6.21-rc7-cfs-v2
534.80user 30.92system 2:23.64elapsed 393%CPU
534.75user 31.01system 2:23.70elapsed 393%CPU
534.66user 31.07system 2:23.76elapsed 393%CPU
534.56user 30.91system 2:23.76elapsed 393%CPU
534.66user 31.07system 2:23.67elapsed 393%CPU
535.43user 30.62system 2:23.72elapsed 393%CPU

2.6.21-rc7-nicksched
505.60user 32.31system 2:17.91elapsed 390%CPU
506.55user 32.42system 2:17.66elapsed 391%CPU
506.41user 32.30system 2:17.85elapsed 390%CPU
506.48user 32.36system 2:17.77elapsed 391%CPU
506.10user 32.40system 2:17.81elapsed 390%CPU
506.69user 32.16system 2:17.78elapsed 391%CPU

#335 lore raw
In reply to Peter Williams
Quoted 7 lines · Peter Williams

There's a lot of ugly code in the load balancer that is only there to overcome the side effects of SMT and dual core. A lot of it was put there by Intel employees trying to make load balancing more friendly to their systems. What I'm suggesting is that an N CPUs per runqueue is a better way of achieving that end. I may (of course) be wrong but I think that the idea deserves more consideration than you're willing to give it.

i actually implemented that some time ago and i'm afraid it was ugly as hell and pretty fragile. Load-balancing gets simpler, but task picking gets alot uglier.

Ingo

#166 lore raw
In reply to Nick Piggin
Quoted 9 lines · Nick Piggin
Quoted 6 lines
Quoted 2 lines

Maybe the progress is that more key people are becoming open to the idea of changing the scheduler.

Could be. All was quiet for quite a while, but when RSDL showed up, it aroused enough interest to show that scheduling woes is on folks radar.

Well I know people have had woes with the scheduler for ever (I guess that isn't going to change :P). [...]

yes, that part isnt going to change, because the CPU is a _scarce resource_ that is perhaps the most frequently overcommitted physical computer resource in existence, and because the kernel does not (yet) track eye movements of humans to figure out which tasks are more important them. So critical human constraints are unknown to the scheduler and thus complaints will always come.

The upstream scheduler thought it had enough information: the sleep average. So now the attempt is to go back and _simplify_ the scheduler and remove that information, and concentrate on getting fairness precisely right. The magic thing about 'fairness' is that it's a pretty good default policy if we decide that we simply have not enough information to do an intelligent choice.

( Lets be cautious though: the jury is still out whether people actually
like this more than the current approach. While CFS feedback looks promising after a whopping 3 days of it being released [ ;-) ], the test coverage of all 'fairness centric' schedulers, even considering years of availability is less than 1% i'm afraid, and that < 1% was mostly self-selecting. )

Ingo

#292 lore raw
In reply to Ingo Molnar
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines

Also, given the general comments it appears clear that some statistical metric of deviation from the intended behavior furthermore qualified by timescale is necessary, so this appears to be headed toward a sort of performance metric as opposed to a pass/fail test

[...]

Quoted 7 lines · Ingo Molnar

yeah. If you could come up with a sane definition that also translates into low overhead on the algorithm side that would be great! The only good generic definition i could come up with (nice levels are isolated buckets with a constant maximum relative percentage of CPU time available to every active bucket) resulted in having a per-nice-level array of rbtree roots, which did not look worth the hassle at first sight :-)

Interesting! That's what vdls did, except its fundamental data structure was more like a circular buffer data structure (resembling Davide Libenzi's timer ring in concept, but with all the details different). I'm not entirely sure how that would've turned out performancewise if I'd done any tuning at all. I was mostly interested in doing something like what I heard Bob Mullens did in 1976 for basic pedagogical value about schedulers to prepare for writing patches for gang scheduling as opposed to creating a viable replacement for the mainline scheduler.

I'm relatively certain a different key calculation will suffice, but it may disturb other desired semantics since they really need to be nonnegative for multiplying by a scaling factor corresponding to its nice number to work properly. Well, as the cfs code now stands, it would correspond to negative keys. Dividing positive keys by the nice scaling factor is my first thought of how to extend the method to the current key semantics. Or such are my thoughts on the subject.

I expect that all that's needed is to fiddle with those numbers a bit. There's quite some capacity for expression there given the precision.

Quoted 5 lines · Ingo Molnar

until now the main approach for nice levels in Linux was always:
"implement your main scheduling logic for nice 0 and then look for some low-overhead method that can be glued to it that does something that behaves like nice levels". Feel free to turn that around into a more natural approach, but the algorithm should remain fairly simple i think.

Part of my insistence was because it seemed to be relatively close to a one-liner, though I'm not entirely sure what particular computation to use to handle the signedness of the keys. I guess I could pick some particular nice semantics myself and then sweep the extant schedulers to use them after getting a testcase hammered out.

-- wli

#371 lore raw
In reply to Nick Piggin
Quoted 7 lines · Nick Piggin

2.6.21-rc7-cfs-v2
534.80user 30.92system 2:23.64elapsed 393%CPU 534.75user 31.01system 2:23.70elapsed 393%CPU 534.66user 31.07system 2:23.76elapsed 393%CPU 534.56user 30.91system 2:23.76elapsed 393%CPU 534.66user 31.07system 2:23.67elapsed 393%CPU 535.43user 30.62system 2:23.72elapsed 393%CPU

Thanks for testing this! Could you please try this also with:

echo 100000000 > /proc/sys/kernel/sched_granularity

on the same system, so that we can get a complete set of numbers? Just to make sure that lowering the preemption frequency indeed has the expected result of moving kernbench numbers back to mainline levels. (if not then that would indicate some CFS buglet)

could you maybe even try a more extreme setting of:

echo 500000000 > /proc/sys/kernel/sched_granularity

for kicks? This would allow us to see how much kernbench we lose due to preemption granularity. Thanks!

Ingo

#293 lore raw
In reply to William Lee Irwin III
Quoted 9 lines · William Lee Irwin III
Quoted 6 lines · Ingo Molnar

until now the main approach for nice levels in Linux was always:
"implement your main scheduling logic for nice 0 and then look for some low-overhead method that can be glued to it that does something that behaves like nice levels". Feel free to turn that around into a more natural approach, but the algorithm should remain fairly simple i think.

Quoted 5 lines

Part of my insistence was because it seemed to be relatively close to a one-liner, though I'm not entirely sure what particular computation to use to handle the signedness of the keys. I guess I could pick some particular nice semantics myself and then sweep the extant schedulers to use them after getting a testcase hammered out.

i'd love to have a oneliner solution :-)

wrt. signedness: note that in v2 i have made rq_running signed, and most calculations (especially those related to nice) are signed values. (On 64-bit systems this all isnt a big issue - most of the arithmetics gymnastics in CFS are done to keep deltas within 32 bits, so that divisions and multiplications are sane.)

Ingo

#345 lore raw
In reply to Peter Williams
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

Comments on which directions you'd like this to go in these respects would be appreciated, as I regard you as the current "project owner."

Quoted 4 lines · Peter Williams

I'd do scan through LKML from about 18 months ago looking for mention of runtime configurable version of plugsched. Some students at a university (in Germany, I think) posted some patches adding this feature to plugsched around about then.

Excellent. I'll go hunting for that.

Quoted 4 lines · Peter Williams

I never added them to plugsched proper as I knew (from previous experience when the company I worked for posted patches with similar functionality) that Linux would like this idea less than he did the current plugsched mechanism.

Odd how the requirements ended up including that. Fickleness abounds. If only we knew up-front what the end would be.

Quoted 7 lines · Peter Williams

Unfortunately, my own cache of the relevant e-mails got overwritten during a Fedora Core upgrade (I've since moved /var onto a separate drive to avoid a repetition) or I would dig them out and send them to you. I'd provided with copies of the company's patches to use as a guide to how to overcome the problems associated with changing schedulers on a running system (a few non trivial locking issues pop up). Maybe if one of the students still reads LKML he will provide a pointer.

I was tempted to restart from scratch given Ingo's comments, but I reconsidered and I'll be working with your code (and the German students' as well). If everything has to change, so be it, but it'll still be a derived work. It would be ignoring precedent and failure to properly attribute if I did otherwise.

-- wli

#372 lore raw
In reply to Ingo Molnar
Quoted 20 lines · Ingo Molnar
Quoted 7 lines · Nick Piggin

2.6.21-rc7-cfs-v2
534.80user 30.92system 2:23.64elapsed 393%CPU 534.75user 31.01system 2:23.70elapsed 393%CPU 534.66user 31.07system 2:23.76elapsed 393%CPU 534.56user 30.91system 2:23.76elapsed 393%CPU 534.66user 31.07system 2:23.67elapsed 393%CPU 535.43user 30.62system 2:23.72elapsed 393%CPU

Thanks for testing this! Could you please try this also with:

   echo 100000000 > /proc/sys/kernel/sched_granularity

on the same system, so that we can get a complete set of numbers? Just to make sure that lowering the preemption frequency indeed has the expected result of moving kernbench numbers back to mainline levels. (if not then that would indicate some CFS buglet)

Quoted 6 lines

could you maybe even try a more extreme setting of:

   echo 500000000 > /proc/sys/kernel/sched_granularity

for kicks? This would allow us to see how much kernbench we lose due to preemption granularity. Thanks!

Yeah but I just powered down the test-box, so I'll have to get onto that tomorrow.

#294 lore raw
In reply to William Lee Irwin III
Quoted 8 lines · William Lee Irwin III

Interesting! That's what vdls did, except its fundamental data structure was more like a circular buffer data structure (resembling Davide Libenzi's timer ring in concept, but with all the details different). I'm not entirely sure how that would've turned out performancewise if I'd done any tuning at all. I was mostly interested in doing something like what I heard Bob Mullens did in 1976 for basic pedagogical value about schedulers to prepare for writing patches for gang scheduling as opposed to creating a viable replacement for the mainline scheduler.

Con helped me dredge up the vdls bits, so here is the last version I before I got tired of toying with the idea. It's not all that clean, with a fair amount of debug code floating around and a number of idiocies (it seems there was a plot to use a heap somewhere I forgot about entirely, never mind other cruft), but I thought I should at least say something more provable than "there was a patch I never posted."

Enjoy!

-- wli

fs/proc/array.c +4 -4
diff -prauN linux-2.6.0-test11/fs/proc/array.c sched-2.6.0-test11-5/fs/proc/array.c
@@ -162,7 +162,7 @@ static inline char * task_state(struct t
 		"Uid:\t%d\t%d\t%d\t%d\n"
 		"Gid:\t%d\t%d\t%d\t%d\n",
 		get_task_state(p),
-		(p->sleep_avg/1024)*100/(1000000000/1024),
+		0UL, /* was ->sleep_avg */
 	       	p->tgid,
 		p->pid, p->pid ? p->real_parent->pid : 0,
 		p->pid && p->ptrace ? p->parent->pid : 0,
@@ -345,7 +345,7 @@ int proc_pid_stat(struct task_struct *ta
 	read_unlock(&tasklist_lock);
 	res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
 %lu %lu %lu %lu %lu %ld %ld %ld %ld %d %ld %llu %lu %ld %lu %lu %lu %lu %lu \
-%lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu\n",
+%lu %lu %lu %lu %lu %lu %lu %lu %d %d %d %d\n",
 		task->pid,
 		task->comm,
 		state,
@@ -390,8 +390,8 @@ int proc_pid_stat(struct task_struct *ta
 		task->cnswap,
 		task->exit_signal,
 		task_cpu(task),
-		task->rt_priority,
-		task->policy);
+		task_prio(task),
+		task_sched_policy(task));
 	if(mm)
 		mmput(mm);
 	return res;
include/asm-i386/thread_info.h +2 -0
diff -prauN linux-2.6.0-test11/include/asm-i386/thread_info.h sched-2.6.0-test11-5/include/asm-i386/thread_info.h
@@ -114,6 +114,8 @@ static inline struct thread_info *curren
 #define TIF_SINGLESTEP		4	/* restore singlestep on return to user mode */
 #define TIF_IRET		5	/* return with iret */
 #define TIF_POLLING_NRFLAG	16	/* true if poll_idle() is polling TIF_NEED_RESCHED */
+#define TIF_QUEUED		17
+#define TIF_PREEMPT		18
 
 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
 #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
include/linux/binomial.h +16 -0
diff -prauN linux-2.6.0-test11/include/linux/binomial.h sched-2.6.0-test11-5/include/linux/binomial.h
@@ -0,0 +1,16 @@
+/*
+ * Simple binomial heaps.
+ */
+
+struct binomial {
+	unsigned priority, degree;
+	struct binomial *parent, *child, *sibling;
+};
+
+
+struct binomial *binomial_minimum(struct binomial **);
+void binomial_union(struct binomial **, struct binomial **, struct binomial **);
+void binomial_insert(struct binomial **, struct binomial *);
+struct binomial *binomial_extract_min(struct binomial **);
+void binomial_decrease(struct binomial **, struct binomial *, unsigned);
+void binomial_delete(struct binomial **, struct binomial *);
include/linux/init_task.h +7 -5
diff -prauN linux-2.6.0-test11/include/linux/init_task.h sched-2.6.0-test11-5/include/linux/init_task.h
@@ -56,6 +56,12 @@
 	.siglock	= SPIN_LOCK_UNLOCKED, 		\
 }
 
+#define INIT_SCHED_INFO(info)					\
+{								\
+	.run_list	= LIST_HEAD_INIT((info).run_list),	\
+	.policy		= 1 /* SCHED_POLICY_TS */,		\
+}
+
 /*
  *  INIT_TASK is used to set up the first task table, touch at
  * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -67,14 +73,10 @@
 	.usage		= ATOMIC_INIT(2),				\
 	.flags		= 0,						\
 	.lock_depth	= -1,						\
-	.prio		= MAX_PRIO-20,					\
-	.static_prio	= MAX_PRIO-20,					\
-	.policy		= SCHED_NORMAL,					\
+	.sched_info	= INIT_SCHED_INFO(tsk.sched_info),		\
 	.cpus_allowed	= CPU_MASK_ALL,					\
 	.mm		= NULL,						\
 	.active_mm	= &init_mm,					\
-	.run_list	= LIST_HEAD_INIT(tsk.run_list),			\
-	.time_slice	= HZ,						\
 	.tasks		= LIST_HEAD_INIT(tsk.tasks),			\
 	.ptrace_children= LIST_HEAD_INIT(tsk.ptrace_children),		\
 	.ptrace_list	= LIST_HEAD_INIT(tsk.ptrace_list),		\
include/linux/sched.h +64 -21

129 lines not on this page · raw message

kernel/Makefile +1 -1
diff -prauN linux-2.6.0-test11/kernel/Makefile sched-2.6.0-test11-5/kernel/Makefile
@@ -6,7 +6,7 @@ obj-y     = sched.o fork.o exec_domain.o
 	    exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o capability.o ptrace.o timer.o user.o \
 	    signal.o sys.o kmod.o workqueue.o pid.o \
-	    rcupdate.o intermodule.o extable.o params.o posix-timers.o
+	    rcupdate.o intermodule.o extable.o params.o posix-timers.o sched/
 
 obj-$(CONFIG_FUTEX) += futex.o
 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
kernel/exit.c +1 -1
diff -prauN linux-2.6.0-test11/kernel/exit.c sched-2.6.0-test11-5/kernel/exit.c
@@ -225,7 +225,7 @@ void reparent_to_init(void)
 	/* Set the exit signal to SIGCHLD so we signal init on exit */
 	current->exit_signal = SIGCHLD;
 
-	if ((current->policy == SCHED_NORMAL) && (task_nice(current) < 0))
+	if (task_nice(current) < 0)
 		set_user_nice(current, 0);
 	/* cpus_allowed? */
 	/* rt_priority? */
kernel/fork.c +14 -34

89 lines not on this page · raw message

kernel/sched/Makefile +1 -0
diff -prauN linux-2.6.0-test11/kernel/sched/Makefile sched-2.6.0-test11-5/kernel/sched/Makefile
@@ -0,0 +1 @@
+obj-y = util.o ts.o idle.o rt.o batch.o
kernel/sched/batch.c +190 -0

190 lines not on this page · raw message

kernel/sched/idle.c +99 -0

99 lines not on this page · raw message

kernel/sched/queue.h +104 -0

104 lines not on this page · raw message

kernel/sched/rt.c +208 -0

208 lines not on this page · raw message

kernel/sched/ts.c +841 -0

841 lines not on this page · raw message

kernel/sched/util.c +37 -0
diff -prauN linux-2.6.0-test11/kernel/sched/util.c sched-2.6.0-test11-5/kernel/sched/util.c
@@ -0,0 +1,37 @@
+#include <linux/sched.h>
+#include <linux/list.h>
+#include <linux/percpu.h>
+#include <asm/page.h>
+#include "queue.h"
+
+int find_first_circular_bit(unsigned long *addr, int start, int end)
+{
+	int bit = find_next_bit(addr, end, start);
+	if (bit < end)
+		return bit;
+	bit = find_first_bit(addr, start);
+	if (bit < start)
+		return bit;
+	return end;
+}
+
+void queue_nop(struct queue *queue, task_t *task)
+{
+}
+
+void nop_renice(struct queue *queue, task_t *task, int nice)
+{
+}
+
+void nop_fini(struct policy *policy, int cpu)
+{
+}
+
+unsigned long nop_timeslice(struct queue *queue, task_t *task)
+{
+	return 0;
+}
+
+void nop_set_timeslice(struct queue *queue, task_t *task, unsigned long n)
+{
+}
kernel/sched.c +318 -673

1,209 lines not on this page · raw message

lib/Makefile +1 -1
diff -prauN linux-2.6.0-test11/lib/Makefile sched-2.6.0-test11-5/lib/Makefile

Lines of this file are not shown. View the raw message.

lib/binomial.c +138 -0

138 lines not on this page · raw message

mm/oom_kill.c +0 -1
diff -prauN linux-2.6.0-test11/mm/oom_kill.c sched-2.6.0-test11-5/mm/oom_kill.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#137 lore raw
In reply to Chris Friesen
Quoted 9 lines · Chris Friesen
Quoted 5 lines · William Lee Irwin III

The sorts of like explicit decisions I'd like to be made for these are:
(1) In a mixture of tasks with varying nice numbers, a given nice number corresponds to some share of CPU bandwidth. Implementations should not have the freedom to change this arbitrarily according to some intention.

The first question that comes to my mind is whether nice levels should be linear or not. I would lean towards nonlinear as it allows a wider range (although of course at the expense of precision). Maybe something like "each nice level gives X times the cpu of the previous"? I think a value of X somewhere between 1.15 and 1.25 might be reasonable.

Nonlinear is a must IMO. I would suggest X = exp(ln(10)/10) ~= 1.2589

That value has the property that a nice=10 task gets 1/10th the cpu of a nice=0 task, and a nice=20 task gets 1/100 of nice=0. I think that would be fairly easy to explain to admins and users so that they can know what to expect from nicing tasks.

Quoted 1 line

What about also having something that looks at latency, and how latency changes with niceness?

I think this would be a lot harder to pin down, since it's a function of all the other tasks running and their nice levels. Do you have any of the RT-derived analysis models in mind?

Quoted 1 line

What about specifying the timeframe over which the cpu bandwidth is measured? I currently have a system where the application designers would like it to be totally fair over a period of 1 second. As you can imagine, mainline doesn't do very well in this case.

It might be easier to specify the maximum deviation from the ideal bandwidth over a certain period. I.e. something like "over a period of one second, each task receives within 10% of the expected bandwidth".

- Jim Bruce

#309 lore raw
In reply to Nick Piggin
Quoted 20 lines · Nick Piggin
Quoted 4 lines · Peter Williams
Quoted 2 lines · Nick Piggin
Quoted 1 line

Other hints that it was a bad idea was the need to transfer time slices between children and parents during fork() and exit().

I don't see how that has anything to do with dual arrays.

It's totally to do with the dual arrays. The only real purpose of the time slice in O(1) (regardless of what its perceived purpose was) was to control the switching between the arrays.

The O(1) design is pretty convoluted in that regard. In my scheduler, the only purpose of the arrays is to renew time slices.

The fork/exit logic is added to make interactivity better. Ingo's scheduler has similar equivalent logic.

Quoted 7 lines
Quoted 7 lines

If you put
a new child at the back of the queue, then your various interactive shell commands that typically do a lot of dependant forking get slowed right down behind your compile job. If you give a new child its own timeslice irrespective of the parent, then you have things like 'make' (which doesn't use a lot of CPU time) spawning off lots of high priority children.

Quoted 7 lines
Quoted 1 line

This is an artefact of trying to control nice using time slices while using them for controlling array switching and whatever else they were being used for. Priority (static and dynamic) is the the best way to implement nice.

I don't like the timeslice based nice in mainline. It's too nasty with latencies. nicksched is far better in that regard IMO.

But I don't know how you can assert a particular way is the best way to do something.

I should have added "I may be wrong but I think that ...".

My opinion is based on a lot of experience with different types of scheduler design and the observation from gathering scheduling statistics while playing with these schedulers that the size of the time slices we're talking about is much larger than the CPU chunks most tasks use in any one go so time slice size has no real effect on most tasks and the faster CPUs become the more this becomes true.

Quoted 23 lines
Quoted 23 lines
Quoted 7 lines

You need to do _something_ (Ingo's does). I don't see why this would be tied with a dual array. FWIW, mine doesn't do anything on exit() like most others, but it may need more tuning in this area.

Quoted 7 lines
Quoted 1 line

This disregard for the dual array mechanism has prevented me from looking at the rest of your scheduler in any great detail so I can't comment on any other ideas that may be in there.

Well I wasn't really asking you to review it. As I said, everyone has their own idea of what a good design does, and review can't really distinguish between the better of two reasonable designs.

A fair evaluation of the alternatives seems like a good idea though. Nobody is actually against this, are they?

No. It would be nice if the basic ideas that each scheduler tries to implement could be extracted and explained though. This could lead to a melding of ideas that leads to something quite good.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

I haven't looked at Con's ones for a while,
but I believe they are also much more straightforward than mainline...

I like Con's scheduler (partly because it uses a single array) but mainly because it's nice and simple. However, his earlier schedulers were prone to starvation (admittedly, only if you went out of your way to make it happen) and I tried to convince him to use the anti starvation mechanism in my SPA schedulers but was unsuccessful. I haven't looked at his latest scheduler that sparked all this furore so can't comment on it.

I agree starvation or unfairness is unacceptable for a new scheduler.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

In the highly unlikely event that you can't separate them on technical grounds, Occam's razor recommends choosing the simplest solution. :-)

O(logN) vs O(1) is technical grounds.

In that case I'd go O(1) provided that the k factor for the O(1) wasn't greater than O(logN)'s k factor multiplied by logMaxN.

Yes, or even significantly greater around typical large sizes of N.

Yes. In fact its' probably better to use the maximum number of threads allowed on the system for N. We know that value don't we?

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#167 lore raw
In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar
Quoted 3 lines · Nick Piggin
Quoted 2 lines
Quoted 1 line

Maybe the progress is that more key people are becoming open to the idea of changing the scheduler.

Could be. All was quiet for quite a while, but when RSDL showed up, it aroused enough interest to show that scheduling woes is on folks radar.

Well I know people have had woes with the scheduler for ever (I guess that isn't going to change :P). [...]

yes, that part isnt going to change, because the CPU is a _scarce resource_ that is perhaps the most frequently overcommitted physical computer resource in existence, and because the kernel does not (yet) track eye movements of humans to figure out which tasks are more important them. So critical human constraints are unknown to the scheduler and thus complaints will always come.

Quoted 8 lines

The upstream scheduler thought it had enough information: the sleep average. So now the attempt is to go back and _simplify_ the scheduler and remove that information, and concentrate on getting fairness precisely right. The magic thing about 'fairness' is that it's a pretty good default policy if we decide that we simply have not enough information to do an intelligent choice.

( Lets be cautious though: the jury is still out whether people actually
like this more than the current approach. While CFS feedback looks promising after a whopping 3 days of it being released [ ;-) ], the test coverage of all 'fairness centric' schedulers, even considering years of availability is less than 1% i'm afraid, and that < 1% was mostly self-selecting. )

At this point I'd like to make the observation that spa_ebs is a very fair scheduler if you consider "nice" to be an indication of the relative entitlement of tasks to CPU bandwidth.

It works by mapping nice to shares using a function very similar to the one for calculating p->load weight except it's not offset by the RT priorities as RT is handled separately. In theory, a runnable task's entitlement to CPU bandwidth at any time is the ratio of its shares to the total shares held by runnable tasks on the same CPU (in reality, a smoothed average of this sum is used to make scheduling smoother). The dynamic priorities of the runnable tasks are then fiddled to try to keep each tasks CPU bandwidth usage in proportion to its entitlement.

That's the theory anyway.

The actual implementation looks a bit different due to efficiency considerations. The modifications to the above theory boil down to keeping a running measure of the (recent) highest CPU bandwidth use per share for tasks running on the CPU -- I call this the yardstick for this CPU. When it's time to put a task on the run queue it's dynamic priority is determined by comparing its CPU bandwidth per share value with the yardstick for its CPU. If it's greater than the yardstick this value becomes the new yardstick and the task gets given the lowest possible dynamic priority (for its scheduling class). If the value is zero it gets the highest possible priority (for its scheduling class) which would be MAX_RT_PRIO for a SCHED_OTHER task. Otherwise it gets given a priority between these two extremes proportional to ratio of its CPU bandwidth per share value and the yardstick. Quite simple really.

The other way in which the code deviates from the original as that (for a few years now) I no longer calculated CPU bandwidth usage directly. I've found that the overhead is less if I keep a running average of the size of a tasks CPU bursts and the length of its scheduling cycle (i.e. from on CPU one time to on CPU next time) and using the ratio of these values as a measure of bandwidth usage.

Anyway it works and gives very predictable allocations of CPU bandwidth based on nice.

Another good feature is that (in this pure form) it's starvation free. However, if you fiddle with it and do things like giving bonus priority boosts to interactive tasks it becomes susceptible to starvation. This can be fixed by using an anti starvation mechanism such as SPA's promotion scheme and that's what spa_ebs does.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#346 lore raw
In reply to William Lee Irwin III
Quoted 18 lines · William Lee Irwin III
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

Comments on which directions you'd like this to go in these respects would be appreciated, as I regard you as the current "project owner."

Quoted 1 line · Peter Williams

I'd do scan through LKML from about 18 months ago looking for mention of runtime configurable version of plugsched. Some students at a university (in Germany, I think) posted some patches adding this feature to plugsched around about then.

Excellent. I'll go hunting for that.

Quoted 1 line · Peter Williams

I never added them to plugsched proper as I knew (from previous experience when the company I worked for posted patches with similar functionality) that Linux would like this idea less than he did the current plugsched mechanism.

Odd how the requirements ended up including that. Fickleness abounds. If only we knew up-front what the end would be.

On Tue, Apr 17, 2007 at 06:00:06PM +1000, Peter Williams wrote:

Quoted 8 lines
Quoted 2 lines

Unfortunately, my own cache of the relevant e-mails got overwritten during a Fedora Core upgrade (I've since moved /var onto a separate drive to avoid a repetition) or I would dig them out and send them to you. I'd provided with copies of the company's patches to use as a guide to how to overcome the problems associated with changing schedulers on a running system (a few non trivial locking issues pop up). Maybe if one of the students still reads LKML he will provide a pointer.

I was tempted to restart from scratch given Ingo's comments, but I reconsidered and I'll be working with your code (and the German students' as well). If everything has to change, so be it, but it'll still be a derived work. It would be ignoring precedent and failure to properly attribute if I did otherwise.

I can give you a patch (or set of patches) against the latest git vanilla kernel version if that would help. There have been changes to the vanilla scheduler code since 2.6.20 so the latest patch on sourceforge won't apply cleanly. I've found that implementing this as a series of patches rather than one big patch makes it easier fro me to cope with changes to the underlying code.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#352 lore raw
In reply to Peter Williams
Quoted 4 lines · Peter Williams
Quoted 1 line · Chris Friesen

Scuse me if I jump in here, but doesn't the load balancer need some way to figure out a) when to run, and b) which tasks to pull and where to push them?

Yes but both of these are independent of the scheduler discipline in force.

It is not clear to me that this is always the case, especially once you mix in things like resource groups.

Quoted 2 lines

If
the load balancer manages to keep the weighted (according to static priority) load and distribution of priorities within the loads on the CPUs roughly equal and the scheduler does a good job of ensuring fairness, interactive responsiveness etc. for the tasks within a CPU then the result will be good system performance within the constraints set by the sys admins use of real time priorities and nice.

Suppose I have a really high priority task running. Another very high priority task wakes up and would normally preempt the first one. However, there happens to be another cpu available. It seems like it would be a win if we moved one of those tasks to the available cpu immediately so they can both run simultaneously. This would seem to require some communication between the scheduler and the load balancer.

Certainly the above design could introduce a lot of context switching. But if my goal is a scheduler that minimizes latency (even at the cost of throughput) then that's an acceptable price to pay.

Chris

#320 lore raw
In reply to Nick Piggin
Quoted 16 lines · Nick Piggin
Quoted 8 lines · Matt Mackall
Quoted 2 lines · Nick Piggin

I'd prefer if we kept a single CPU scheduler in mainline, because I think that simplifies analysis and focuses testing.

I think you'll find something like 80-90% of the testing will be done on the default choice, even if other choices exist. So you really won't have much of a problem here.

Quoted 6 lines

But when the only choice for other schedulers is to go out-of-tree, then only 1% of the people will try it out and those people are guaranteed to be the ones who saw scheduling problems in mainline. So the alternative won't end up getting any testing on many of the workloads that work fine in mainstream so their feedback won't tell you very much at all.

Quoted 3 lines

Yeah I concede that perhaps it is the only way to get things going any further. But how do we decide if and when the current scheduler should be demoted from default, and which should replace it?

Step one is ship both in -mm. If that doesn't give us enough confidence, ship both in mainline. If that doesn't give us enough confidence, wait until vendors ship both. Eventually a clear picture should emerge. If it doesn't, either the change is not significant or no one cares.

But it really is important to be able to do controlled experiments on this stuff with little effort. That's the recipe for getting lots of valid feedback.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#138 lore raw
In reply to James Bruce
Quoted 5 lines · James Bruce

Nonlinear is a must IMO. I would suggest X = exp(ln(10)/10) ~= 1.2589 That value has the property that a nice=10 task gets 1/10th the cpu of a nice=0 task, and a nice=20 task gets 1/100 of nice=0. I think that would be fairly easy to explain to admins and users so that they can know what to expect from nicing tasks.

[...additional good commentary trimmed...]

Lots of good ideas here. I'll follow them.

-- wli

#188 lore raw
In reply to Nick Piggin
Quoted 15 lines · Nick Piggin
Quoted 7 lines · William Lee Irwin III
Quoted 1 line · William Lee Irwin III
Quoted 1 line

All things are not equal; they all have different properties. I like

Quoted 2 lines · Nick Piggin

Exactly. So we have to explore those properties and evaluate performance (in all meanings of the word). That's only logical.

Quoted 6 lines

Any chance you'd be willing to put down a few thoughts on what sorts of standards you'd like to set for both correctness (i.e. the bare minimum a scheduler implementation must do to be considered valid beyond not oopsing) and performance metrics (i.e. things that produce numbers for each scheduler you can compare to say "this scheduler is better than this other scheduler at this.").

Quoted 7 lines

Yeah I guess that's the hard part :)

For correctness, I guess fairness is an easy one. I think that unfairness is basically a bug and that it would be very unfortunate to merge something unfair. But this is just within the context of a single runqueue... for better or worse, we allow some unfairness in multiprocessors for performance reasons of course.

I'm a big fan of fairness, but I think it's a bit early to declare it a mandatory feature. Bounded unfairness is probably something we can agree on, ie "if we decide to be unfair, no process suffers more than a factor of x".

Quoted 4 lines

Latency. Given N tasks in the system, an arbitrary task should get onto the CPU in a bounded amount of time (excluding events like freak IRQ holdoffs and such, obviously -- ie. just considering the context of the scheduler's state machine).

This is a slightly stronger statement than starvation-free (which is obviously mandatory). I think you're looking for something like "worst-case scheduling latency is proportional to the number of runnable tasks". Which I think is quite a reasonable requirement.

I'm pretty sure the stock scheduler falls short of both of these guarantees though.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#295 lore raw
In reply to Ingo Molnar
Quoted 19 lines · Ingo Molnar
Quoted 2 lines · William Lee Irwin III

[...] Also rest assured that the tone of the critique is not hostile, and wasn't meant to sound that way.

ok :) (And i guess i was too touchy - sorry about coming out swinging.)

Quoted 10 lines

Also, given the general comments it appears clear that some statistical metric of deviation from the intended behavior furthermore qualified by timescale is necessary, so this appears to be headed toward a sort of performance metric as opposed to a pass/fail test anyway. However, to even measure this at all, some statement of intention is required. I'd prefer that there be a Linux-standard semantics for nice so results are more directly comparable and so that users also get similar nice behavior from the scheduler as it varies over time and possibly implementations if users should care to switch them out with some scheduler patch or other.

Quoted 2 lines

yeah. If you could come up with a sane definition that also translates into low overhead on the algorithm side that would be great!

How's this:

If you're running two identical CPU hog tasks A and B differing only by nice level (Anice, Bnice), the ratio cputime(A)/cputime(B) should be a constant f(Anice - Bnice).

Other definitions make things hard to analyze and probably not well-bounded when confronted with > 2 tasks.

I -think- this implies keeping a separate scaled CPU usage counter, where the scaling factor is a trivial exponential function of nice level where f(0) == 1. Then you schedule based on this scaled usage counter rather than unscaled.

I also suspect we want to keep the exponential base small so that the maximal difference is 10x-100x.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#187 lore raw
In reply to William Lee Irwin III
Quoted 10 lines · William Lee Irwin III
Quoted 4 lines · Nick Piggin

Latency. Given N tasks in the system, an arbitrary task should get onto the CPU in a bounded amount of time (excluding events like freak IRQ holdoffs and such, obviously -- ie. just considering the context of the scheduler's state machine).

ISTR Davide Libenzi having a scheduling latency test a number of years ago. Resurrecting that and tuning it to the needs of this kind of testing sounds relevant here. The test suite Peter Willliams mentioned would also help.

That helped me a lot at that time. At every context switch was sampling critical scheduler parameters for both entering and exiting task (and associated timestamps). Then the data was collected through a /dev/idontremember from userspace for analysis. It'd very useful to have it those days, to study what really happens under the hook (scheduler internal parameters variations and such) when those wierd loads make the scheduler unstable.

- Davide

#296 lore raw
In reply to Matt Mackall
Quoted 2 lines · Ingo Molnar
Quoted 2 lines

yeah. If you could come up with a sane definition that also translates into low overhead on the algorithm side that would be great!

Quoted 4 lines · Matt Mackall

How's this:
If you're running two identical CPU hog tasks A and B differing only by nice level (Anice, Bnice), the ratio cputime(A)/cputime(B) should be a constant f(Anice - Bnice).

Quoted 8 lines

Other definitions make things hard to analyze and probably not well-bounded when confronted with > 2 tasks.
I -think- this implies keeping a separate scaled CPU usage counter, where the scaling factor is a trivial exponential function of nice level where f(0) == 1. Then you schedule based on this scaled usage counter rather than unscaled.
I also suspect we want to keep the exponential base small so that the maximal difference is 10x-100x.

I'm already working with this as my assumed nice semantics (actually something with a specific exponential base, suggested in other emails) until others start saying they want something different and agree.

-- wli

#297 lore raw
Quoted 18 lines · William Lee Irwin III
Quoted 2 lines · Ingo Molnar
Quoted 2 lines

yeah. If you could come up with a sane definition that also translates into low overhead on the algorithm side that would be great!

Quoted 4 lines · Matt Mackall

How's this:
If you're running two identical CPU hog tasks A and B differing only by nice level (Anice, Bnice), the ratio cputime(A)/cputime(B) should be a constant f(Anice - Bnice).

Quoted 8 lines

Other definitions make things hard to analyze and probably not well-bounded when confronted with > 2 tasks.
I -think- this implies keeping a separate scaled CPU usage counter, where the scaling factor is a trivial exponential function of nice level where f(0) == 1. Then you schedule based on this scaled usage counter rather than unscaled.
I also suspect we want to keep the exponential base small so that the maximal difference is 10x-100x.

Quoted 3 lines

I'm already working with this as my assumed nice semantics (actually something with a specific exponential base, suggested in other emails) until others start saying they want something different and agree.

Good. This has a couple nice mathematical properties, including "bounded unfairness" which I mentioned earlier. What base are you looking at?

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#298 lore raw
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines

I'm already working with this as my assumed nice semantics (actually something with a specific exponential base, suggested in other emails) until others start saying they want something different and agree.

Quoted 3 lines · Matt Mackall

Good. This has a couple nice mathematical properties, including "bounded unfairness" which I mentioned earlier. What base are you looking at?

I'm working with the following suggestion:

Quoted 5 lines · James Bruce

Nonlinear is a must IMO. I would suggest X = exp(ln(10)/10) ~= 1.2589 That value has the property that a nice=10 task gets 1/10th the cpu of a nice=0 task, and a nice=20 task gets 1/100 of nice=0. I think that would be fairly easy to explain to admins and users so that they can know what to expect from nicing tasks.

I'm not likely to write the testcase until this upcoming weekend, though.

-- wli

#168 lore raw
In reply to Peter Williams
Quoted 9 lines · Peter Williams

The other way in which the code deviates from the original as that (for a few years now) I no longer calculated CPU bandwidth usage directly. I've found that the overhead is less if I keep a running average of the size of a tasks CPU bursts and the length of its scheduling cycle (i.e. from on CPU one time to on CPU next time) and using the ratio of these values as a measure of bandwidth usage.

Anyway it works and gives very predictable allocations of CPU bandwidth based on nice.

Works, that is, right up until you add nonlinear interactions with CPU speed scaling. From my perspective as an embedded platform integrator, clock/voltage scaling is the elephant in the scheduler's living room. Patch in DPM (now OpPoint?) to scale the clock based on what task is being scheduled, and suddenly the dynamic priority calculations go wild. Nip this in the bud by putting an RT priority on the relevant threads (which you have to do anyway if you need remotely audio-grade latency), and the lock affinity heuristics break, so you have to hand-tune all the thread priorities. Blecch.

Not to mention the likelihood that the task whose clock speed you're trying to crank up (say, a WiFi soft MAC) needs to be _lower_ priority than the application. (You want to crank the CPU for this task because it runs with the RF hot, which may cost you as much power as the rest of the platform.) You'd better hope you can remove it from the dynamic priority heuristics with SCHED_BATCH. Otherwise everything _else_ has to be RT priority (or it'll be starved by the soft MAC) and you've basically tossed SCHED_NORMAL in the bin. Double blecch!

Is it too much to ask for someone with actual engineering training (not me, unfortunately) to sit down and build a negative-feedback control system that handles soft-real-time _and_ dynamic-priority _and_ batch loads, CPU _and_ I/O scheduling, preemption _and_ clock scaling? And actually separates the accounting and control mechanisms from the heuristics, so the latter can be tuned (within a well documented stable range) to reflect the expected system usage patterns?

It's not like there isn't a vast literature in this area over the past decade, including some dealing specifically with clock scaling consistent with low-latency applications. It's a pity that people doing academic work in this area rarely wade into LKML, even when they're hacking on a Linux fork. But then, there's not much economic incentive for them to do so, and they can usually get their fill of citation politics and dominance games without leaving their home department. :-P

Seriously, though. If you're really going to put the mainline scheduler through this kind of churn, please please pretty please knit in per-task clock scaling (possibly even rejigged during the slice; see e. g. Yuan and Nahrstedt's GRACE-OS papers) and some sort of linger mechanism to keep from taking context switch hits when you're confident that an I/O will complete quickly.

Cheers,
- Michael

#169 lore raw
Quoted 9 lines · Michael K. Edwards

Works, that is, right up until you add nonlinear interactions with CPU speed scaling. From my perspective as an embedded platform integrator, clock/voltage scaling is the elephant in the scheduler's living room. Patch in DPM (now OpPoint?) to scale the clock based on what task is being scheduled, and suddenly the dynamic priority calculations go wild. Nip this in the bud by putting an RT priority on the relevant threads (which you have to do anyway if you need remotely audio-grade latency), and the lock affinity heuristics break, so you have to hand-tune all the thread priorities. Blecch.

[...not terribly enlightening stuff trimmed...]

The ongoing scheduler work is on a much more basic level than these affairs I'm guessing you googled. When the basics work as intended it will be possible to move on to more advanced issues.

-- wli

#299 lore raw
In reply to William Lee Irwin III
Quoted 13 lines · William Lee Irwin III
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines

I'm already working with this as my assumed nice semantics (actually something with a specific exponential base, suggested in other emails) until others start saying they want something different and agree.

Quoted 3 lines · Matt Mackall

Good. This has a couple nice mathematical properties, including "bounded unfairness" which I mentioned earlier. What base are you looking at?

I'm working with the following suggestion:

Quoted 8 lines
Quoted 5 lines · James Bruce

Nonlinear is a must IMO. I would suggest X = exp(ln(10)/10) ~= 1.2589 That value has the property that a nice=10 task gets 1/10th the cpu of a nice=0 task, and a nice=20 task gets 1/100 of nice=0. I think that would be fairly easy to explain to admins and users so that they can know what to expect from nicing tasks.

I'm not likely to write the testcase until this upcoming weekend, though.

So that means there's a 10000:1 ratio between nice 20 and nice -19. In that sort of dynamic range, you're likely to have non-trivial numerical accuracy issues in integer/fixed-point math.

(Especially if your clock is jiffies-scale, which a significant number of machines will continue to be.)

I really think if we want to have vastly different ratios, we probably want to be looking at BATCH and RT scheduling classes instead.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#189 lore raw
In reply to Matt Mackall
Quoted 31 lines · Matt Mackall
Quoted 12 lines · Nick Piggin
Quoted 11 lines · William Lee Irwin III
Quoted 1 line · William Lee Irwin III
Quoted 1 line

All things are not equal; they all have different properties. I like

Quoted 2 lines · Nick Piggin

Exactly. So we have to explore those properties and evaluate performance (in all meanings of the word). That's only logical.

Any chance you'd be willing to put down a few thoughts on what sorts of standards you'd like to set for both correctness (i.e. the bare minimum a scheduler implementation must do to be considered valid beyond not oopsing) and performance metrics (i.e. things that produce numbers for each scheduler you can compare to say "this scheduler is better than this other scheduler at this.").

Quoted 7 lines

Yeah I guess that's the hard part :)

For correctness, I guess fairness is an easy one. I think that unfairness is basically a bug and that it would be very unfortunate to merge something unfair. But this is just within the context of a single runqueue... for better or worse, we allow some unfairness in multiprocessors for performance reasons of course.

I'm a big fan of fairness, but I think it's a bit early to declare it a mandatory feature. Bounded unfairness is probably something we can agree on, ie "if we decide to be unfair, no process suffers more than a factor of x".

Quoted 4 lines

Latency. Given N tasks in the system, an arbitrary task should get onto the CPU in a bounded amount of time (excluding events like freak IRQ holdoffs and such, obviously -- ie. just considering the context of the scheduler's state machine).

Quoted 4 lines

This is a slightly stronger statement than starvation-free (which is obviously mandatory). I think you're looking for something like "worst-case scheduling latency is proportional to the number of runnable tasks".

add "taking into consideration nice and/or real time priorities of runnable tasks". I.e. if a task is nice 19 it can expect to wait longer to get onto the CPU than if it was nice 0.

Quoted 5 lines

Which I think is quite a reasonable requirement.

I'm pretty sure the stock scheduler falls short of both of these guarantees though.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce