From: Ting Yang <tingy@cs.umass.edu>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [patch] CFS scheduler, -v7
Date: Thu, 03 May 2007 11:02:08 -0400 [thread overview]
Message-ID: <4639F970.5080701@cs.umass.edu> (raw)
In-Reply-To: <20070503074552.GA14960@elte.hu>
Hi, Ingo
This is the test case that I think worth discuss and it leads me to
find 2 things.
>> [...] but there are still some nice issues.
>>
>> Try running 3 chew.c's, then renicing one to -10, starves others for
>> some seconds while switching prio-level. Now renice it back to 10, it
>> starves for up to 45sec.
>>
>
> ok - to make sure i understood you correctly: does this starvation only
> occur right when you renice it (when switching prio levels), and it gets
> rectified quickly once they get over a few reschedules?
The main problem of what Al Boldi saw might come from this piece of code
in sched_fair.c, which scales of fair_key difference needed to preempt
the current task:
+rescale_load(struct task_struct *p, u64 value)
+{
+ int load_shift = p->load_shift;
+
+ if (load_shift == SCHED_LOAD_SHIFT)
+ return value;
+
+ return (value << load_shift) >> SCHED_LOAD_SHIFT;
+}
+
+static u64
+niced_granularity(struct rq *rq, struct task_struct *curr,
+ unsigned long granularity)
+{
+ return rescale_load(curr, granularity);
+}
Here is the checking for pre-emption:
+static inline void
+__check_preempt_curr_fair(struct rq *rq, struct task_struct *p,
+ struct task_struct *curr, unsigned long granularity)
+{
+ s64 __delta = curr->fair_key - p->fair_key;
+
+ /*
+ * Take scheduling granularity into account - do not
+ * preempt the current task unless the best task has
+ * a larger than sched_granularity fairness advantage:
+ */
+ if (__delta > niced_granularity(rq, curr, granularity))
+ resched_task(curr);
+}
This code actually now says, the difference of fair_key needed to
preempt the current task is amplified by a facto of its weigh (in Al
Boldi's example 32). However, the weighted task already advance its
p->fair_key by its weight, (also 32 here). The combination of them
becomes quadratic!
Let's starting from three nice 0 tasks p1, p2, p3, at time t=0, with
niced_granularity set to be 5ms:
Originally each task executes 5 ms in turn:
5ms for p1, 5ms for p2, 5ms p3, 5ms for p1, 5ms for
p2, 5ms for p3 ...
If somehow p3 is re-niced to -10 _right before_ the 16th ms, we run
into the worst case after p3 gets the cpu:
p1->fair_key = p2 ->fair_key = 10, p3->fair_key = 5.
Now, in order for p3 to be preempted, it has to make its fair_key 5
* 32 larger than p1 and p2's fair_key. Furthermore, p3 now is higher
weight, push its fair_key to increase by 1 now needs 32ms,
thus p3 will stay one cpu for 5 * 32 *32ms, which is about 5 second!
Besides this quadratic effect, another minor issue amplified this a
little bit further: p->wait_runtime accumulated before. During renice it
is not adjusted to match the new nice value. The p->wait_runtime earned
using previous weight has to be paid off using the current weight. If
renice to larger weight you pay more than you need, otherwise you paid
less, which introduces unfairness.
Ingo, now, partially solved this problem by clearing
p->wait_runtime when a task is reniced, but the quadratic effect of
scaling is still there.
Thanks
Ting
next prev parent reply other threads:[~2007-05-03 15:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-30 5:20 [patch] CFS scheduler, -v7 Al Boldi
2007-05-03 7:45 ` Ingo Molnar
2007-05-03 8:07 ` Ingo Molnar
2007-05-03 11:16 ` Al Boldi
2007-05-03 12:36 ` Ingo Molnar
2007-05-03 13:49 ` Al Boldi
2007-05-03 8:42 ` Al Boldi
2007-05-03 15:02 ` Ting Yang [this message]
2007-05-03 15:17 ` Ingo Molnar
2007-05-03 16:00 ` Ting Yang
2007-05-03 19:48 ` Ingo Molnar
2007-05-03 19:57 ` William Lee Irwin III
-- strict thread matches above, loose matches on Subject: below --
2007-04-28 15:25 Ingo Molnar
2007-04-28 19:20 ` S.Çağlar Onur
2007-04-28 19:24 ` Ingo Molnar
2007-04-28 23:42 ` S.Çağlar Onur
2007-04-29 7:11 ` Ingo Molnar
2007-04-29 12:37 ` S.Çağlar Onur
2007-04-29 15:58 ` Ingo Molnar
2007-04-29 22:29 ` Dennis Brendel
2007-04-30 14:38 ` S.Çağlar Onur
2007-04-28 19:27 ` S.Çağlar Onur
2007-04-29 17:28 ` Prakash Punnoor
2007-05-04 13:05 ` Prakash Punnoor
2007-04-30 16:29 ` Srivatsa Vaddagiri
2007-04-30 18:30 ` Balbir Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4639F970.5080701@cs.umass.edu \
--to=tingy@cs.umass.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox