scheduler updates
Linus, please pull the latest scheduler git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-sched.git
It includes 8 commits, 3 of which are important: the most important change is a bugfix to the new task startup penalty code. This could explain the task-startup unpredictability problem reported by Al Boldi.
Then there's also a change/tweak that increases the default granularity:
it's still well below human perception so should not be noticeable, but servers win a bit from less preemption of CPU-bound tasks. (this is also the first step towards eliminating HZ from the granularity default calculation.)
Plus a bonus balance inconsistency has been fixed: the previous logic was slightly inflatory of sleeper wait-runtime, without a counter-balance on runners. (I found no noticeable or measurable impact, other than a ~5% improvement in hackbench performance [due to less preemption scheduling] and a slightly nicer looking /proc/sched_debug output when there are lots of sleepers.)
Five other, low-impact changes: a group-scheduling fixlet from Bruce Ashfield, two nice simplifications from Peter Zijlstra to the bonus-balance code (which eliminate a 64-bit multiplication and shrink the code), a QOI improvement from Dmitry Adamushko to RR RT task preemption [not strictly required for .23 but this has been in my tree for some time already with no ill effects and the code is obviously correct] and a dead code elimination fix from Sven-Thorsten Dietrich.
Test-built and test-booted on x86-32 and x86-64, and it passed a few dozen "make randconfig" builds as well.
Ingo
------------------>
Bruce Ashfield (1):
sched: CONFIG_SCHED_GROUP_FAIR=y fixlet
Dmitry Adamushko (1):
sched: optimize task_tick_rt() a bit
Ingo Molnar (3):
sched: increase default granularity a bit
sched: tidy up and simplify the bonus balance
sched: fix startup penalty calculation
Peter Zijlstra (2):
sched: simplify bonus calculation #1
sched: simplify bonus calculation #2
Sven-Thorsten Dietrich (1):
sched: simplify can_migrate_task()
sched.c | 6 ------ sched_fair.c | 26 +++++++++++++++----------- sched_rt.c | 11 ++++++++--- 3 files changed, 23 insertions(+), 20 deletions(-)
Quoted 6 lines · Ingo Molnar
Then there's also a change/tweak that increases the default granularity:
it's still well below human perception so should not be noticeable, but servers win a bit from less preemption of CPU-bound tasks. (this is also the first step towards eliminating HZ from the granularity default calculation.)
Your explanation makes NO sense.
It doesn't eliminate HZ at all. It's still there, and it's still totally bogus.
Please just *remove* that thing. It has no possible value! You claim that the preemption granularity is in "ns", and that it defaults to "3 msec", but it does no such thing at all, even with your patch. It does:
unsigned int sysctl_sched_granularity __read_mostly = 3000000000ULL/HZ;
which is just total and utter CRAP!
Why the hell can't you just make the code sane and do what the comment *says* it does, and just admit that HZ has nothing what-so-ever to do with that thing, and then you do
unsigned int sysctl_sched_granularity __read_mostly = 3000000ULL;
and be done with it. Instead of this *insane* expectation that HZ is always 1000, and any other value means that you want bigger granularity, which is not true and makes no sense.
So dammit, stop writing these totally bogus "explanations". If you have a reason why the granularity needs to be HZ-dependent, *document* that reason, and make the code actually match the comment, instead of continually documenting things that SIMPLY ARE NOT TRUE.
Ingo, I'm not going to pull this kind of antics and crap.
Linus
Quoted 8 lines · Linus Torvalds
Quoted 6 lines · Ingo Molnar
Then there's also a change/tweak that increases the default
granularity: it's still well below human perception so should not be noticeable, but servers win a bit from less preemption of CPU-bound tasks. (this is also the first step towards eliminating HZ from the granularity default calculation.)
Quoted 4 lines
Your explanation makes NO sense.
It doesn't eliminate HZ at all. It's still there, and it's still totally bogus.
fair enough, and i fixed that.
( i called the previous patch the "first step" because i was too chicken
to pick a single granularity default :-/ )
for the current queue i went for settings close to that of HZ=250 - that's the most common HZ variant that was tested previously. That means 10 msec on a 1-way box, 20 msec on a 2-way box, 30 msec on a 4-way box, etc. (up to a 100 msecs ceiling.)
Quoted 8 lines
Please just *remove* that thing. It has no possible value! You claim that the preemption granularity is in "ns", and that it defaults to "3 msec", but it does no such thing at all, even with your patch. It does:
unsigned int sysctl_sched_granularity __read_mostly = 3000000000ULL/HZ;which is just total and utter CRAP!
ok, i've removed that and all the other HZ hacks too. I've uploaded a new queue with that fixed (and all other patches unchanged):
git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-sched.git
booted it on a number of boxes (32-bit and 64-bit). The question will be desktop behavior. I typically run my test-desktops with HZ=100 to make sure that desktop workloads are fine with large granularity values and coarse timers too, so i'm reasonably positive about this default.
We'll see - people can still readily tweak these values under CONFIG_SCHED_DEBUG=y and give us feedback, and if there's enough demand for very-finegrained scheduling (throughput be damned), we could introduce yet another config option or enable the runtime tunable unconditionally. (Or maybe the best option is Peter Zijlstra's adaptive granularity idea, that gives the best of both worlds.)
Ingo
------------------>
Bruce Ashfield (1):
sched: CONFIG_SCHED_GROUP_FAIR=y fixlet
Dmitry Adamushko (1):
sched: optimize task_tick_rt() a bit
Ingo Molnar (3):
sched: remove HZ dependency from the granularity default
sched: tidy up and simplify the bonus balance
sched: fix startup penalty calculation
Peter Zijlstra (2):
sched: simplify bonus calculation #1
sched: simplify bonus calculation #2
Sven-Thorsten Dietrich (1):
sched: simplify can_migrate_task()
sched.c | 8 +------- sched_fair.c | 35 +++++++++++++++++++---------------- sched_rt.c | 11 ++++++++--- 3 files changed, 28 insertions(+), 26 deletions(-)
Quoted 6 lines · Ingo Molnar
We'll see - people can still readily tweak these values under
CONFIG_SCHED_DEBUG=yand give us feedback, and if there's enough demand for very-finegrained scheduling (throughput be damned), we could introduce yet another config option or enable the runtime tunable unconditionally. (Or maybe the best option is Peter Zijlstra's adaptive granularity idea, that gives the best of both worlds.)
hm, glxgears smoothness regresses with the de-HZ-ification change: with an increasing background load the turning of the wheels quickly becomes visually ugly - with small ruckles instead of smooth rotation.
The reason for that is that the 20 msec granularity on my testbox (which is a dual-core box, so the default 10msec turns into 20msec) turns into 40, 60, 80, 100 msec 'observed latency' for glxgears as load increases to 2x, 3x, 4x etc - and a 100 msec pause in rotation is easily perceivable to the human eye (and brain). Before that the delay curve with increasing load was 4msec/8msec/12msec etc.
Due to the removal of the HZ dependency we now have upset the granularity picture anyway, so i believe we should do the adaptive granularity thing right now. That will aim for a 40msec task-observable latency, in a load-independent manner. (!) (This is an approach we couldnt even dream of with the previous, fixed-timeslice scheduler.)
The code is simple (and it is all in the slowpath), it in essence boils down to this new code:
+static long
+sched_granularity(struct cfs_rq *cfs_rq)
+{
+ unsigned int gran = sysctl_sched_latency;
+ unsigned int nr = cfs_rq->nr_running;
+
+ if (nr > 1) {
+ gran = gran/nr - gran/nr/nr;
+ gran = max(gran, sysctl_sched_granularity);
+ }
+
+ return gran;
+}
IMO it is a good compromise between long slicing and short slicing:
there are two values, one is the "CPU-bound task latency the scheduler aims for", the second one is a minimum granularity (to not do too many context-switches).
Peter and me tested this all day with various workloads and extreme-load behavior has improved all over the place - while the server benchmarks (which want less preemption) are still fine too. The glxgear ruckles are all gone.
If you do not disagree with this (it's pretty late in the game with more than 1 month spent from the kernel cycle already), please pull the latest scheduler tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-sched.git
Find the shortlog further below. There are 3 commits in it: adaptive granularity, a subsequent cleanup, and a lockdep sysctl bug Peter noticed while hacking on this. (the bug was introduced with the initial CFS commits but nobody noticed because the lockdep sysctls are rarely used.)
The linecount increase is mostly due to the comments added to explain the "gran = lat/nr - lat/nr/nr" magic formula and due to the extra parameter.
Tested on 32-bit and 64-bit x86, and with a few make randconfig build tests too.
Ingo
------------------>
Ingo Molnar (1):
sched: cleanup, sched_granularity -> sched_min_granularity
Peter Zijlstra (2):
sched: fix CONFIG_SCHED_DEBUG dependency of lockdep sysctls
sched: adaptive scheduler granularity
include/linux/sched.h | 3 + kernel/sched.c | 16 ++++++---- kernel/sched_fair.c | 77 ++++++++++++++++++++++++++++++++++++++++++-------- kernel/sysctl.c | 33 ++++++++++++++------- 4 files changed, 99 insertions(+), 30 deletions(-)
Quoted 7 lines · Ingo Molnar
git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-sched.gitFind the shortlog further below. There are 3 commits in it: adaptive granularity, a subsequent cleanup, and a lockdep sysctl bug Peter noticed while hacking on this. (the bug was introduced with the initial CFS commits but nobody noticed because the lockdep sysctls are rarely used.)
hm, a small (and mostly harmless) buglet sneaked into it: the wakeup granularity and the runtime limit is now dependent on sched_latency - while it should be dependent on min_granularity and latency. To pick up that fix please pull from:
git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-sched.git
(ontop of your very latest git tree)
the effect of this bug was too high wakeup latency that could cause audio skipping on small-audio-buffer setups. (didnt happen on mine, they have large enough buffers.)
Ingo
------------------>
Ingo Molnar (1):
sched: s/sched_latency/sched_min_granularity
sched.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 2 lines · Ingo Molnar
Peter and me tested this all day with various workloads and extreme-load behavior has improved all over the place
Adaptive granularity makes a large difference for me on my somewhat ancient laptop (1200 MHz). When browsing the interweb using firefox (or trying to) while doing a (non-niced) kbuild -j5 the difference in interactivity is significant.
[ kbuild -j5 was quite unbearable on 2.6.22 - so CFS is a clear win in any case ]
The reduced latency is clearly noticable in a much smoother scroll behaviour. Whereas both still present a usable browsing experience the clear reduction in latency spikes makes it much more pleasant.
Hi,
Quoted 9 lines · Linus Torvalds
Why the hell can't you just make the code sane and do what the comment *says* it does, and just admit that HZ has nothing what-so-ever to do with that thing, and then you do
unsigned int sysctl_sched_granularity __read_mostly = 3000000ULL;and be done with it. Instead of this *insane* expectation that HZ is always 1000, and any other value means that you want bigger granularity, which is not true and makes no sense.
I'd actually like to base this on the cpu frequency or the number of cycles to be precise, e.g. with 10^7 cycles this would be 100ms for 100MHz and 10ms for 1GHz.
bye, Roman