Skip to contentSkip to conversation

O(1) scheduler starvation

PATCH Felipe Alfaro Solana 5 participants 13 messages Jun 18, 2003 Scheduler

lore
Share & tools
lore
#0 lore raw

Hi!

I've been poking around and found the following link on O(1) scheduler starvation problems:

http://www.hpl.hp.com/research/linux/kernel/o1-starve.php

The web page contains a small test program which supposedly is able to make two processes starvate. However, I've been unable to reproduce what is described in the above link. In fact, the CPU usage ratio ranges between 60-40% or 70-30% in the worst cases.

I'm running 2.5.72-mm1 with Mike Galbraith's scheduler patches and a small patch I made myself to improve interactivity (mainly, to stop XMMS from skipping by adjusting some scheduler parameters).

What's going on here? Is the previous article outdated, or have the starvation problems been definitively fixed?

Thanks!

include/linux/sched.h +3 -1
diff -prauN linux-2.5.70-bk8/include/linux/sched.h galbraith-2.5.70-bk8-1/include/linux/sched.h
@@ -336,7 +336,9 @@
 	prio_array_t *array;
 
 	unsigned long sleep_avg;
-	unsigned long last_run;
+	unsigned long long last_run;
+	unsigned int run_nsecs;
+	unsigned int sleep_nsecs;
 
 	unsigned long policy;
 	unsigned long cpus_allowed;
kernel/sched.c +78 -47

206 lines not on this page · raw message

arch/i386/kernel/timers/timer_tsc.c +3 -2
diff -prauN linux-2.5.70-bk8/arch/i386/kernel/timers/timer_tsc.c galbraith-2.5.70-bk8-1/arch/i386/kernel/timers/timer_tsc.c
@@ -102,12 +102,13 @@
 static unsigned long long monotonic_clock_tsc(void)
 {
 	unsigned long long last_offset, this_offset, base;
+	unsigned long flags;
 	
 	/* atomically read monotonic base & last_offset */
-	read_lock_irq(&monotonic_lock);
+	read_lock_irqsave(&monotonic_lock, flags);
 	last_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low;
 	base = monotonic_base;
-	read_unlock_irq(&monotonic_lock);
+	read_unlock_irqrestore(&monotonic_lock, flags);
 
 	/* Read the Time Stamp Counter */
 	rdtscll(this_offset);
kernel/sched.c +4 -4
@@ -66,14 +66,14 @@
  * they expire.
  */
 #define MIN_TIMESLICE		( 10 * HZ / 1000)
-#define MAX_TIMESLICE		(200 * HZ / 1000)
+#define MAX_TIMESLICE		( 20 * HZ / 1000)
 #define CHILD_PENALTY		50
 #define PARENT_PENALTY		100
 #define EXIT_WEIGHT		3
-#define PRIO_BONUS_RATIO	25
+#define PRIO_BONUS_RATIO	20
 #define INTERACTIVE_DELTA	2
-#define MAX_SLEEP_AVG		(10*HZ)
-#define STARVATION_LIMIT	(10*HZ)
+#define MAX_SLEEP_AVG		(2*HZ)
+#define STARVATION_LIMIT	(2*HZ)
 #define NODE_THRESHOLD		125
 #define SCHED_NANOSECOND	1
 #define SCHED_SECOND		(1000000000 * SCHED_NANOSECOND)
#1 lore raw
Quoted 11 lines · Felipe Alfaro Solana

Hi!

I've been poking around and found the following link on O(1) scheduler starvation problems:

http://www.hpl.hp.com/research/linux/kernel/o1-starve.php

The web page contains a small test program which supposedly is able to make two processes starvate. However, I've been unable to reproduce what is described in the above link. In fact, the CPU usage ratio ranges between 60-40% or 70-30% in the worst cases.

(you're talking about with my monotinic_clock() diff in your kernel right?)

If you examine the priorities vs cpu usage, therein lies a big fat bug.

I think the fundamental problem is that you can only execute in series, but can sleep in parallel, which makes for more sleep time existing than all execution time combined. If you're running test-starve with my monotonic_clock() diff, you should notice that one task is at maximum priority and eating ~75% cpu, while the other is at minumum and getting the rest minus what top gets. In a sane universe, that should be impossible. In my current tree, this _is_ now impossible, but I haven't worked out some nasty kinks.

I've got thud licked (without the restricting sleep to time_slice), test-starve works right as well, and interactivity is up. Tasks waking each other in a loop is a bitch and a half though, and need to be beaten about the head and shoulders. Going to a synchronous wakeup for pipes (talking stock kernel now) cures irman process_load's ability to starve... IFF you're running it from a vt. If you're in an xterm, it'll still climb up from the bottom (only place where it can't starve anybody) and starve via pass-the-baton wakeup DoS. That will/does take the joy out of using xmms. If xmms didn't use multiple threads, it'd be much worse... right now, you'll lose eye-candy [cpu hungry visualization stuff] before you lose sound [at next song].

Quoted 3 lines

I'm running 2.5.72-mm1 with Mike Galbraith's scheduler patches and a small patch I made myself to improve interactivity (mainly, to stop XMMS from skipping by adjusting some scheduler parameters).

Please show me your xmms hack, and show me how you make xmms skip without doing something that puts tons of stress on the cache. I built xmms here, and the only time the audio thread gets starved is when starting a new song. That's because of CHILD_PENALTY when starting a new copy of xmms while something of prio < 20 is hogging cpu (process_load <grrrr>). Once playing, it's rock solid here.

Quoted 2 lines

What's going on here? Is the previous article outdated, or have the starvation problems been definitively fixed?

Nope, definitely not.

(if you like bean-counter diff, run contest/irman's process load:)

-Mike

#2 lore raw
Quoted 15 lines · Mike Galbraith
Quoted 11 lines · Felipe Alfaro Solana

Hi!

I've been poking around and found the following link on O(1) scheduler starvation problems:

http://www.hpl.hp.com/research/linux/kernel/o1-starve.php

The web page contains a small test program which supposedly is able to make two processes starvate. However, I've been unable to reproduce what is described in the above link. In fact, the CPU usage ratio ranges between 60-40% or 70-30% in the worst cases.

Quoted 5 lines

(you're talking about with my monotinic_clock() diff in your kernel right?)

If you examine the priorities vs cpu usage, therein lies a big fat bug.

I think the fundamental problem is that you can only execute in series, but can sleep in parallel, which makes for more sleep time existing than all execution time combined.

Would dividing the sleep time by the number of sleepers fix this? Or is division a too heavy operation here?

Helge Hafting

#3 lore raw
Quoted 15 lines · Helge Hafting
Quoted 14 lines · Mike Galbraith
Quoted 11 lines · Felipe Alfaro Solana

Hi!

I've been poking around and found the following link on O(1) scheduler starvation problems:

http://www.hpl.hp.com/research/linux/kernel/o1-starve.php

The web page contains a small test program which supposedly is able to make two processes starvate. However, I've been unable to reproduce what is described in the above link. In fact, the CPU usage ratio ranges between 60-40% or 70-30% in the worst cases.

Quoted 6 lines
Quoted 3 lines

(you're talking about with my monotinic_clock() diff in your kernel right?)
If you examine the priorities vs cpu usage, therein lies a big fat bug.
I think the fundamental problem is that you can only execute in series, but can sleep in parallel, which makes for more sleep time existing than all execution time combined.

Would dividing the sleep time by the number of sleepers fix this? Or is division a too heavy operation here?

That won't work. You'd have to plunk it all into a pot, and divvy it up by %cpu usage or something. I solved it the simple way. I keep a smoothed run_avg (%cpu * 100), and use that as a sleep_avg limit... ie if you're run_avg is 9000 (you're eating 10% cpu), no sleep will push you into insanity land. I still have the problem that tasks will seek their appropriate priority level and _stick_ there, so I probably need to add some decay. (which will no doubt open the next can-O-worms)

-Mike

#4 lore raw
In reply to Mike Galbraith
Quoted 6 lines · Mike Galbraith
Quoted 5 lines · Felipe Alfaro Solana

Hi!

I've been poking around and found the following link on O(1) scheduler starvation problems:

Quoted 8 lines
Quoted 6 lines

http://www.hpl.hp.com/research/linux/kernel/o1-starve.php

The web page contains a small test program which supposedly is able to make two processes starvate. However, I've been unable to reproduce what is described in the above link. In fact, the CPU usage ratio ranges between 60-40% or 70-30% in the worst cases.

(you're talking about with my monotinic_clock() diff in your kernel right?)

Don't know exactly its name. wli posted to LKLM a few days ago. In a few words, the patch creates

+inline void __scheduler_tick(runqueue_t *rq, task_t *p)

and

+#define SCHED_NANOSECOND       1
+#define SCHED_SECOND           (1000000000 * SCHED_NANOSECOND)
+#define SCHED_TICK             (SCHED_SECOND / HZ)
+#define TICKS_PER_SECOND       (SCHED_SECOND / SCHED_TICK)

Don't know if this is the patch you're talking about. It's not thud, anyways.

Quoted 10 lines

If you examine the priorities vs cpu usage, therein lies a big fat bug.

I think the fundamental problem is that you can only execute in series, but can sleep in parallel, which makes for more sleep time existing than all execution time combined. If you're running test-starve with my monotonic_clock() diff, you should notice that one task is at maximum priority and eating ~75% cpu, while the other is at minumum and getting the rest minus what top gets. In a sane universe, that should be impossible. In my current tree, this _is_ now impossible, but I haven't worked out some nasty kinks.

Exactly. This is more or less what was happening, roughly a 70-30 balance of CPU usage.

Quoted 10 lines
Quoted 3 lines

I'm running 2.5.72-mm1 with Mike Galbraith's scheduler patches and a small patch I made myself to improve interactivity (mainly, to stop XMMS from skipping by adjusting some scheduler parameters).

Please show me your xmms hack, and show me how you make xmms skip without doing something that puts tons of stress on the cache. I built xmms here, and the only time the audio thread gets starved is when starting a new song. That's because of CHILD_PENALTY when starting a new copy of xmms while something of prio < 20 is hogging cpu (process_load <grrrr>). Once playing, it's rock solid here.

No, I wasn't talking about an XMMS hack. I was talking about changing scheduler defaults, as shown in the following patch:

kernel/sched.c 2003-06-17 20:58:54.840902000 +0200 renamed from kernel/sched.c 2003-06-17 21:04:21.240902000 +0200 +4 -4
@@ -66,14 +66,14 @@
  * they expire.
  */
 #define MIN_TIMESLICE          ( 10 * HZ / 1000)
-#define MAX_TIMESLICE          (200 * HZ / 1000)
+#define MAX_TIMESLICE          ( 20 * HZ / 1000)
 #define CHILD_PENALTY          50
 #define PARENT_PENALTY         100
 #define EXIT_WEIGHT            3
-#define PRIO_BONUS_RATIO       25
+#define PRIO_BONUS_RATIO       20
 #define INTERACTIVE_DELTA      2
-#define MAX_SLEEP_AVG          (10*HZ)
-#define STARVATION_LIMIT       (10*HZ)
+#define MAX_SLEEP_AVG          (2*HZ)
+#define STARVATION_LIMIT       (2*HZ)
 #define NODE_THRESHOLD         125
 #define SCHED_NANOSECOND       1
 #define SCHED_SECOND           (1000000000 * SCHED_NANOSECOND)

To make XMMS skip, just force the X server to do a lot of repainting, for example, by dragging a big window slowly enough over another one which requires a lot of painting (Evolution, for example, is a good candidate as it requires a lot of CPU to repaint uncovered areas). It's easy to reproduce just after launching XMMS. However, after a while, it gets difficult to make XMMS to skip sound (it seems the scheduler adjusts priorities well enough). This is on a PIII 700Mhz laptop with no niced processes at all.

With your patch and my scheduler changes, I've been unable to make XMMS skip audio, even when the X server is reniced to -20, or another CPU hog is running.

#5 lore raw
Quoted 28 lines · Felipe Alfaro Solana
Quoted 6 lines · Mike Galbraith
Quoted 5 lines · Felipe Alfaro Solana

Hi!

I've been poking around and found the following link on O(1) scheduler starvation problems:

Quoted 8 lines
Quoted 6 lines

http://www.hpl.hp.com/research/linux/kernel/o1-starve.php

The web page contains a small test program which supposedly is able to make two processes starvate. However, I've been unable to reproduce what is described in the above link. In fact, the CPU usage ratio ranges between 60-40% or 70-30% in the worst cases.

(you're talking about with my monotinic_clock() diff in your kernel right?)

Don't know exactly its name. wli posted to LKLM a few days ago. In a few words, the patch creates

+inline void __scheduler_tick(runqueue_t *rq, task_t *p)

and

(quoted diff) +4 -0
+#define SCHED_NANOSECOND       1
+#define SCHED_SECOND           (1000000000 * SCHED_NANOSECOND)
+#define SCHED_TICK             (SCHED_SECOND / HZ)
+#define TICKS_PER_SECOND       (SCHED_SECOND / SCHED_TICK)
Quoted 2 lines

Don't know if this is the patch you're talking about. It's not thud, anyways.

Yeah, that's the diff. (thud is a starvation testcase posted a while back)

Quoted 27 lines
Quoted 3 lines

If you examine the priorities vs cpu usage, therein lies a big fat bug.

I think the fundamental problem is that you can only execute in series,

but

Quoted 4 lines

can sleep in parallel, which makes for more sleep time existing than all execution time combined. If you're running test-starve with my monotonic_clock() diff, you should notice that one task is at maximum priority and eating ~75% cpu, while the other is at minumum and getting

the

Quoted 3 lines

rest minus what top gets. In a sane universe, that should be impossible. In my current tree, this _is_ now impossible, but I haven't worked out some nasty kinks.

Exactly. This is more or less what was happening, roughly a 70-30 balance of CPU usage.

Quoted 10 lines
Quoted 3 lines

I'm running 2.5.72-mm1 with Mike Galbraith's scheduler patches and a small patch I made myself to improve interactivity (mainly, to stop XMMS from skipping by adjusting some scheduler parameters).

Please show me your xmms hack, and show me how you make xmms skip without doing something that puts tons of stress on the cache. I built xmms here, and the only time the audio thread gets starved is when starting a new song. That's because of CHILD_PENALTY when starting a new copy of xmms while something of prio < 20 is hogging cpu (process_load <grrrr>). Once playing, it's rock solid here.

Quoted 2 lines

No, I wasn't talking about an XMMS hack. I was talking about changing scheduler defaults, as shown in the following patch:

Ah, ok (darn, was hoping for fresh idea)

kernel/sched.c 2003-06-17 20:58:54.840902000 +0200 line 69

Quoted 8 lines
kernel/sched.c 2003-06-17 20:58:54.840902000 +0200 renamed from kernel/sched.c 2003-06-17 21:04:21.240902000 +0200 +1 -1
@@ -66,14 +66,14 @@
  * they expire.
  */
 #define MIN_TIMESLICE          ( 10 * HZ / 1000)
-#define MAX_TIMESLICE          (200 * HZ / 1000)
+#define MAX_TIMESLICE          ( 20 * HZ / 1000)

(tiny slices make for much context switching, but [alone] doesn't help low prio tasks get cpu)

kernel/sched.c 2003-06-17 20:58:54.840902000 +0200 line 75

Quoted 9 lines
kernel/sched.c 2003-06-17 20:58:54.840902000 +0200 renamed from kernel/sched.c 2003-06-17 21:04:21.240902000 +0200 +2 -3
 #define CHILD_PENALTY          50
 #define PARENT_PENALTY         100
 #define EXIT_WEIGHT            3
-#define PRIO_BONUS_RATIO       25
+#define PRIO_BONUS_RATIO       20
 #define INTERACTIVE_DELTA      2
-#define MAX_SLEEP_AVG          (10*HZ)
-#define STARVATION_LIMIT       (10*HZ)
+#define MAX_SLEEP_AVG          (2*HZ)

(this will increase cpu multiplexing drastically, but will also make the desktop feel any background load pretty much instantly. btdt too, ok for very light load, but bad for balls-to-the-wall throughput here)

Quoted 5 lines
kernel/sched.c 2003-06-17 20:58:54.840902000 +0200 renamed from kernel/sched.c 2003-06-17 21:04:21.240902000 +0200 +1 -0
+#define STARVATION_LIMIT       (2*HZ)
 #define NODE_THRESHOLD         125
 #define SCHED_NANOSECOND       1
 #define SCHED_SECOND           (1000000000 * SCHED_NANOSECOND)
Quoted 8 lines

To make XMMS skip, just force the X server to do a lot of repainting, for example, by dragging a big window slowly enough over another one which requires a lot of painting (Evolution, for example, is a good candidate as it requires a lot of CPU to repaint uncovered areas). It's easy to reproduce just after launching XMMS. However, after a while, it gets difficult to make XMMS to skip sound (it seems the scheduler adjusts priorities well enough). This is on a PIII 700Mhz laptop with no niced processes at all.

Thanks. I don't have evolution on my linux box (pine/vi/procmail rules). ImageMagic ought to give X more than enough spurts of frenetic activity though. Do you have that, and does image manipulation make xmms stutter as well? Just moving windows around and changing backgrounds doesn't do anything here. (500mhz piii/128mb ram btw)

Quoted 3 lines

With your patch and my scheduler changes, I've been unable to make XMMS skip audio, even when the X server is reniced to -20, or another CPU hog is running.

<g> I can make it do a skip so big that SysRq-E or BRB are the only recovery options.

-Mike

#6 lore raw
Quoted 9 lines · Mike Galbraith
Quoted 8 lines · Felipe Alfaro Solana
Quoted 7 lines · Mike Galbraith
Quoted 6 lines · Felipe Alfaro Solana

Hi!

I've been poking around and found the following link on O(1) scheduler starvation problems:

http://www.hpl.hp.com/research/linux/kernel/o1-starve.php

<BIG SNIP>

Have you seen this email I just posted to lkml?

[PATCH] 2.5.72 O(1) interactivity bugfix

It may be affecting the scheduler in all sorts of ways.

Con

#7 lore raw
Quoted 6 lines · Con Kolivas
Quoted 5 lines · Mike Galbraith
Quoted 4 lines · Felipe Alfaro Solana
Quoted 3 lines · Mike Galbraith
Quoted 2 lines · Felipe Alfaro Solana

Hi!

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I've been poking around and found the following link on O(1) scheduler starvation problems:

http://www.hpl.hp.com/research/linux/kernel/o1-starve.php

<BIG SNIP>

Have you seen this email I just posted to lkml?

(yeah, replied off-line)

#8 lore raw
In reply to Mike Galbraith
Quoted 9 lines · Mike Galbraith
Quoted 8 lines

To make XMMS skip, just force the X server to do a lot of repainting, for example, by dragging a big window slowly enough over another one which requires a lot of painting (Evolution, for example, is a good candidate as it requires a lot of CPU to repaint uncovered areas). It's easy to reproduce just after launching XMMS. However, after a while, it gets difficult to make XMMS to skip sound (it seems the scheduler adjusts priorities well enough). This is on a PIII 700Mhz laptop with no niced processes at all.

Quoted 5 lines

Thanks. I don't have evolution on my linux box (pine/vi/procmail rules). ImageMagic ought to give X more than enough spurts of frenetic activity though. Do you have that, and does image manipulation make xmms stutter as well? Just moving windows around and changing backgrounds doesn't do anything here. (500mhz piii/128mb ram btw)

In fact, I can only make XMMS skip sound for a very brief period, just after starting it up. After a few seconds, it seems the dynamic priorities are adjusted and I can't make XMMS skip sound anymore. To reproduce it, open up a big window, then launch XMMS and make it play some MP3 file. Then, start moving the big window around. For me, this causes XMMS to skip sound for a brief period of time (~5 seconds, approx).

#9 lore raw
Quoted 16 lines · Felipe Alfaro Solana
Quoted 9 lines · Mike Galbraith
Quoted 8 lines

To make XMMS skip, just force the X server to do a lot of repainting, for example, by dragging a big window slowly enough over another one which requires a lot of painting (Evolution, for example, is a good candidate as it requires a lot of CPU to repaint uncovered areas). It's easy to reproduce just after launching XMMS. However, after a while, it gets difficult to make XMMS to skip sound (it seems the scheduler adjusts priorities well enough). This is on a PIII 700Mhz laptop with no niced processes at all.

Quoted 5 lines

Thanks. I don't have evolution on my linux box (pine/vi/procmail rules). ImageMagic ought to give X more than enough spurts of frenetic activity though. Do you have that, and does image manipulation make xmms stutter as well? Just moving windows around and changing backgrounds doesn't do anything here. (500mhz piii/128mb ram btw)

Quoted 7 lines

In fact, I can only make XMMS skip sound for a very brief period, just after starting it up. After a few seconds, it seems the dynamic priorities are adjusted and I can't make XMMS skip sound anymore. To reproduce it, open up a big window, then launch XMMS and make it play some MP3 file. Then, start moving the big window around. For me, this causes XMMS to skip sound for a brief period of time (~5 seconds, approx).

If you bump CHILD_PENALTY up (to say 75) you should see a marked improvement.

-Mike

#10 lore raw
In reply to Mike Galbraith
Quoted 11 lines · Mike Galbraith

I've got thud licked (without the restricting sleep to time_slice), test-starve works right as well, and interactivity is up. Tasks waking each other in a loop is a bitch and a half though, and need to be beaten about the head and shoulders. Going to a synchronous wakeup for pipes (talking stock kernel now) cures irman process_load's ability to starve... IFF you're running it from a vt. If you're in an xterm, it'll still climb up from the bottom (only place where it can't starve anybody) and starve via pass-the-baton wakeup DoS. That will/does take the joy out of using xmms. If xmms didn't use multiple threads, it'd be much worse... right now, you'll lose eye-candy [cpu hungry visualization stuff] before you lose sound [at next song].

That's great. I'd love to see the patch.

-- wli

#11 lore raw
Quoted 11 lines · William Lee Irwin III
Quoted 10 lines · Mike Galbraith

I've got thud licked (without the restricting sleep to time_slice), test-starve works right as well, and interactivity is up. Tasks waking each other in a loop is a bitch and a half though, and need to be beaten about the head and shoulders. Going to a synchronous wakeup for pipes (talking stock kernel now) cures irman process_load's ability to starve... IFF you're running it from a vt. If you're in an xterm, it'll still climb up from the bottom (only place where it can't starve anybody) and starve via pass-the-baton wakeup DoS. That will/does take the joy out of using xmms. If xmms didn't use multiple threads, it'd be much worse... right now, you'll lose eye-candy [cpu hungry visualization stuff] before you

Quoted 4 lines

lose

Quoted 1 line

sound [at next song].

That's great. I'd love to see the patch.

If I can get the kinks worked out and still have something left. I'm gaining on the darn thing, but only a net millimeter at a time... with much cha-cha-cha action in between ;-)

-Mike

#12 lore raw
In reply to Felipe Alfaro Solana
Quoted 5 lines · Felipe Alfaro Solana

I'm running 2.5.72-mm1 with Mike Galbraith's scheduler patches and a small patch I made myself to improve interactivity (mainly, to stop XMMS from skipping by adjusting some scheduler parameters). What's going on here? Is the previous article outdated, or have the starvation problems been definitively fixed?

The MAX_TIMESLICE change is inappropriate.

There's papering over broken algorithms, and then there's getting really blatant about it -- and MAX_TIMESLICE going from 200 -> 20 is blatant.

-- wli