linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] O8int for interactivity
@ 2003-07-23 11:55 Con Kolivas
  2003-07-23 16:46 ` Felipe Alfaro Solana
  0 siblings, 1 reply; 5+ messages in thread
From: Con Kolivas @ 2003-07-23 11:55 UTC (permalink / raw)
  To: linux kernel mailing list
  Cc: Andrew Morton, Mike Galbraith, Felipe Alfaro Solana,
	Davide Libenzi, Mike Fedyk, Wiktor Wodecki, Eugene Teo,
	Danek Duvall, William Lee Irwin III

Here is an addon to the interactivity work so far. As the ability to become 
interactive was made much faster and easier in O6*, I was able to remove a lot 
of extra code uneeded in this latest patch, and remove a lot of the noticable 
unfairness in the code. This is closer to the original scheduler code after 
all these patches than any of my previous patches. All of O8int is aimed
at fixing unfairness in my interactivity patches.

Changes:
Removed the entire two tier MIN_SLEEP_AVG -> MAX_SLEEP_AVG code I started 
with. All code that goes with it was removed. The MAX_SLEEP_AVG can be very 
small now as even if applications (like X) have periods of cpu hogness, they 
can become interactive very rapidly again. Growth of sleep_avg is now purely
based on number of wakeups longer than one tick.

Changed MAX_SLEEP_AVG and STARVATION_LIMIT to 1 second to benefit from the 
above changes. This fixes a heck of a lot of the nasty corner cases (eg 
launching acrobat reader from within mozilla etc.)

CHILD_PENALTY is now set to 60%; this means fully interactive tasks can only 
spawn just under interactive tasks now (the same as idle tasks), but they can 
climb rapidly anyway. Although buggy applications are busy on wait with this, 
because the parents now drop interactive state faster it will be less 
noticable, and is fairer. As previous threads stated, the buggy applications 
should be fixed rather than have a scheduler that works around them.

Tiny optimisation and documentation changes to correspond to changes.

This patch applies on top of 2.6.0-test1-mm2 or an O7int patched kernel.

Con

Patch available here:
http://kernel.kolivas.org/2.5

and here:

diff -Naurp linux-2.6.0-test1-mm2/kernel/sched.c linux-2.6.0-test1ck2/kernel/sched.c
--- linux-2.6.0-test1-mm2/kernel/sched.c	2003-07-23 21:05:34.000000000 +1000
+++ linux-2.6.0-test1ck2/kernel/sched.c	2003-07-23 21:07:39.000000000 +1000
@@ -68,14 +68,13 @@
  */
 #define MIN_TIMESLICE		( 10 * HZ / 1000)
 #define MAX_TIMESLICE		(200 * HZ / 1000)
-#define CHILD_PENALTY		95
+#define CHILD_PENALTY		60
 #define PARENT_PENALTY		100
 #define EXIT_WEIGHT		3
 #define PRIO_BONUS_RATIO	25
 #define INTERACTIVE_DELTA	2
-#define MIN_SLEEP_AVG		(HZ)
-#define MAX_SLEEP_AVG		(10*HZ)
-#define STARVATION_LIMIT	(10*HZ)
+#define MAX_SLEEP_AVG		(HZ)
+#define STARVATION_LIMIT	(HZ)
 #define NODE_THRESHOLD		125
 #define MAX_BONUS		(MAX_USER_PRIO * PRIO_BONUS_RATIO / 100)
 
@@ -299,26 +298,6 @@ static inline void enqueue_task(struct t
 	array->nr_active++;
 	p->array = array;
 }
-/*
- * normalise_sleep converts a task's sleep_avg to
- * an appropriate proportion of MIN_SLEEP_AVG.
- */
-static inline void normalise_sleep(task_t *p)
-{
-	unsigned long old_avg_time = jiffies - p->avg_start;
-
-	if (unlikely(old_avg_time < MIN_SLEEP_AVG))
-		return;
-
-	if (p->sleep_avg > MAX_SLEEP_AVG)
-		p->sleep_avg = MAX_SLEEP_AVG;
-
-	if (old_avg_time > MAX_SLEEP_AVG)
-		old_avg_time = MAX_SLEEP_AVG;
-
-	p->sleep_avg = p->sleep_avg * MIN_SLEEP_AVG / old_avg_time;
-	p->avg_start = jiffies - MIN_SLEEP_AVG;
-}
 
 /*
  * effective_prio - return the priority that is based on the static
@@ -337,28 +316,11 @@ static inline void normalise_sleep(task_
 static int effective_prio(task_t *p)
 {
 	int bonus, prio;
-	unsigned long sleep_period;
 
 	if (rt_task(p))
 		return p->prio;
 
-	sleep_period = jiffies - p->avg_start;
-
-	if (unlikely(!sleep_period))
-		return p->static_prio;
-
-	if (sleep_period > MAX_SLEEP_AVG)
-		sleep_period = MAX_SLEEP_AVG;
-
-	if (p->sleep_avg > sleep_period)
-		sleep_period = p->sleep_avg;
-
-	/*
-	 * The bonus is determined according to the accumulated
-	 * sleep avg over the duration the task has been running
-	 * until it reaches MAX_SLEEP_AVG. -ck
-	 */
-	bonus = MAX_USER_PRIO*PRIO_BONUS_RATIO*p->sleep_avg/sleep_period/100 -
+	bonus = MAX_USER_PRIO*PRIO_BONUS_RATIO*p->sleep_avg/MAX_SLEEP_AVG/100 -
 			MAX_USER_PRIO*PRIO_BONUS_RATIO/100/2;
 
 	prio = p->static_prio - bonus;
@@ -391,43 +353,22 @@ static inline void activate_task(task_t 
 	if (sleep_time > 0) {
 		/*
 		 * User tasks that sleep a long time are categorised as idle and
-		 * will get just under interactive status with a small runtime
-		 * to allow them to become interactive or non-interactive rapidly
+		 * will get just under interactive status to prevent them suddenly
+		 * becoming cpu hogs and starving other processes.
 		 */
-		if (sleep_time > MIN_SLEEP_AVG && p->mm){
-			p->avg_start = jiffies - MIN_SLEEP_AVG;
-			p->sleep_avg = MIN_SLEEP_AVG * (MAX_BONUS - INTERACTIVE_DELTA - 2) /
-				MAX_BONUS;
-		} else {
-			unsigned long runtime = jiffies - p->avg_start;
-
-			if (runtime > MAX_SLEEP_AVG)
-				runtime = MAX_SLEEP_AVG;
+		if (p->mm && sleep_time > HZ)
+			p->sleep_avg = MAX_SLEEP_AVG * (MAX_BONUS - INTERACTIVE_DELTA - 2) / MAX_BONUS;
+		else {
 
 			/*
-			 * This code gives a bonus to interactive tasks.
-			 *
-			 * The boost works by updating the 'average sleep time'
-			 * value here, based on ->last_run. The more time a task
-			 * spends sleeping, the higher the average gets - and the
-			 * higher the priority boost gets as well.
+			 * Processes that sleep get pushed to one higher priority
+			 * each time they sleep greater than one tick. -ck
 			 */
-			p->sleep_avg += sleep_time;
-
-			/*
-			 * Processes that sleep get pushed to a higher priority
-			 * each time they sleep
-			 */
-			p->sleep_avg = (p->sleep_avg * MAX_BONUS / runtime + 1) * runtime / MAX_BONUS;
+			p->sleep_avg = (p->sleep_avg * MAX_BONUS / MAX_SLEEP_AVG + 1) * MAX_SLEEP_AVG / MAX_BONUS;
 
 			if (p->sleep_avg > MAX_SLEEP_AVG)
 				p->sleep_avg = MAX_SLEEP_AVG;
 		}
-
-		if (unlikely(p->avg_start > jiffies)){
-			p->avg_start = jiffies;
-			p->sleep_avg = 0;
-		}
 	}
 	p->prio = effective_prio(p);
 	__activate_task(p, rq);
@@ -606,7 +547,6 @@ void wake_up_forked_process(task_t * p)
 	 * from forking tasks that are max-interactive.
 	 */
 	current->sleep_avg = current->sleep_avg * PARENT_PENALTY / 100;
-	normalise_sleep(p);
 	p->sleep_avg = p->sleep_avg * CHILD_PENALTY / 100;
 	p->prio = effective_prio(p);
 	set_task_cpu(p, smp_processor_id());
@@ -647,8 +587,6 @@ void sched_exit(task_t * p)
 	 * If the child was a (relative-) CPU hog then decrease
 	 * the sleep_avg of the parent as well.
 	 */
-	normalise_sleep(p);
-	normalise_sleep(p->parent);
 	if (p->sleep_avg < p->parent->sleep_avg)
 		p->parent->sleep_avg = (p->parent->sleep_avg * EXIT_WEIGHT +
 			p->sleep_avg) / (EXIT_WEIGHT + 1);
--- linux-2.6.0-test1-mm2/include/linux/sched.h	2003-07-23 21:05:34.000000000 +1000
+++ linux-2.6.0-test1ck2/include/linux/sched.h	2003-07-23 21:07:39.000000000 +1000
@@ -341,7 +341,6 @@ struct task_struct {
 	prio_array_t *array;
 
 	unsigned long sleep_avg;
-	unsigned long avg_start;
 	unsigned long last_run;
 
 	unsigned long policy;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] O8int for interactivity
  2003-07-23 11:55 [PATCH] O8int for interactivity Con Kolivas
@ 2003-07-23 16:46 ` Felipe Alfaro Solana
  2003-07-24 16:12   ` Szonyi Calin
  2003-07-26  9:03   ` Eugene Teo
  0 siblings, 2 replies; 5+ messages in thread
From: Felipe Alfaro Solana @ 2003-07-23 16:46 UTC (permalink / raw)
  To: Con Kolivas
  Cc: linux kernel mailing list, Andrew Morton, Mike Galbraith,
	Davide Libenzi, Mike Fedyk, Wiktor Wodecki, Eugene Teo,
	Danek Duvall, William Lee Irwin III

On Wed, 2003-07-23 at 13:55, Con Kolivas wrote:
> Here is an addon to the interactivity work so far. As the ability to become 
> interactive was made much faster and easier in O6*, I was able to remove a lot 
> of extra code uneeded in this latest patch, and remove a lot of the noticable 
> unfairness in the code. This is closer to the original scheduler code after 
> all these patches than any of my previous patches. All of O8int is aimed
> at fixing unfairness in my interactivity patches.

Testing it right now on top of 2.6.0-test1-mm2 :-)

Overall it feels better. I can't make XMMS skip at all. Under low load,
X is very smooth, but X is still jerky/jumpy when the system is under
heavy load (while true; do a=2; done) and I start moving windows all
around my KDE desktop. Renicing the X server to -20 makes it very smooth
under load (yeah, I know I shouldn't do this).

I'm playing a bit with tunables to see if I can tune the scheduler a
little bit for my system/workload. I've had good results reducing max
timeslice to 100 (yeah, I know I shouldn't do this too).

Will keep you informed :-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] O8int for interactivity
  2003-07-23 16:46 ` Felipe Alfaro Solana
@ 2003-07-24 16:12   ` Szonyi Calin
  2003-07-24 22:20     ` Con Kolivas
  2003-07-26  9:03   ` Eugene Teo
  1 sibling, 1 reply; 5+ messages in thread
From: Szonyi Calin @ 2003-07-24 16:12 UTC (permalink / raw)
  To: felipe_alfaro; +Cc: kernel, linux-kernel, akpm


Felipe Alfaro Solana said:
>
> I'm playing a bit with tunables to see if I can tune the scheduler a
> little bit for my system/workload. I've had good results reducing max
> timeslice to 100 (yeah, I know I shouldn't do this too).
>
> Will keep you informed :-)
>

same thing here. Reducing max timeslice to 100 is much better.
It's the only thing that allow me to watch a movie while compiling
the kernel with make -j 2 bzImage on my Duron 700Mhz with 256M RAM

I have to find some docs about those tunables.

Thanks
Bye
Calin



-----------------------------------------
This email was sent using SquirrelMail.
   "Webmail for nuts!"
http://squirrelmail.org/



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] O8int for interactivity
  2003-07-24 16:12   ` Szonyi Calin
@ 2003-07-24 22:20     ` Con Kolivas
  0 siblings, 0 replies; 5+ messages in thread
From: Con Kolivas @ 2003-07-24 22:20 UTC (permalink / raw)
  To: Szonyi Calin, felipe_alfaro; +Cc: linux-kernel

On Fri, 25 Jul 2003 02:12, Szonyi Calin wrote:
> Felipe Alfaro Solana said:
> > I'm playing a bit with tunables to see if I can tune the scheduler a
> > little bit for my system/workload. I've had good results reducing max
> > timeslice to 100 (yeah, I know I shouldn't do this too).
> >
> > Will keep you informed :-)
>
> same thing here. Reducing max timeslice to 100 is much better.
> It's the only thing that allow me to watch a movie while compiling
> the kernel with make -j 2 bzImage on my Duron 700Mhz with 256M RAM

Does this patch help?

Con

--- linux-2.6.0-test1-mm2/kernel/sched.c	2003-07-24 10:31:41.000000000 +1000
+++ linux-2.6.0-test1ck2/kernel/sched.c	2003-07-25 08:18:54.000000000 +1000
@@ -1243,7 +1243,7 @@ void scheduler_tick(int user_ticks, int 
 		} else
 			enqueue_task(p, rq->active);
 	} else if (p->mm && !((task_timeslice(p) - p->time_slice) %
-		 (MIN_TIMESLICE * (MAX_BONUS + 1 - p->sleep_avg * MAX_BONUS / MAX_SLEEP_AVG)))){
+		 (MIN_TIMESLICE * (1 + (MAX_BONUS - p->sleep_avg * MAX_BONUS / MAX_SLEEP_AVG) / 2)))){
 		/*
 		 * Running user tasks get requeued with their remaining timeslice
 		 * after a period proportional to how cpu intensive they are to


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] O8int for interactivity
  2003-07-23 16:46 ` Felipe Alfaro Solana
  2003-07-24 16:12   ` Szonyi Calin
@ 2003-07-26  9:03   ` Eugene Teo
  1 sibling, 0 replies; 5+ messages in thread
From: Eugene Teo @ 2003-07-26  9:03 UTC (permalink / raw)
  To: Felipe Alfaro Solana
  Cc: Con Kolivas, linux kernel mailing list, Andrew Morton,
	Mike Galbraith, Davide Libenzi, Mike Fedyk, Wiktor Wodecki,
	Eugene Teo, Danek Duvall, William Lee Irwin III

<quote sender="Felipe Alfaro Solana">
> On Wed, 2003-07-23 at 13:55, Con Kolivas wrote:
> > Here is an addon to the interactivity work so far. As the ability to become 
> > interactive was made much faster and easier in O6*, I was able to remove a lot 
> > of extra code uneeded in this latest patch, and remove a lot of the noticable 
> > unfairness in the code. This is closer to the original scheduler code after 
> > all these patches than any of my previous patches. All of O8int is aimed
> > at fixing unfairness in my interactivity patches.
> 
> Overall it feels better. I can't make XMMS skip at all. Under low load,
> X is very smooth, but X is still jerky/jumpy when the system is under
> heavy load (while true; do a=2; done) and I start moving windows all
> around my KDE desktop. Renicing the X server to -20 makes it very smooth
> under load (yeah, I know I shouldn't do this).

X server was niced to -10. XMMS doesn't skip when under load, except
when I try to hide, and unhide maximised aterm. Other than that,
everything went smoothly. Didn't encounter what I experienced when I
was using O7int (con knows what happened :D). X server was niced to 0
now. So far so good. 

Eugene


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-07-26  8:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-23 11:55 [PATCH] O8int for interactivity Con Kolivas
2003-07-23 16:46 ` Felipe Alfaro Solana
2003-07-24 16:12   ` Szonyi Calin
2003-07-24 22:20     ` Con Kolivas
2003-07-26  9:03   ` Eugene Teo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).