* false nr_running check in load balance?
@ 2013-08-06 13:23 Lei Wen
2013-08-12 14:43 ` Peter Zijlstra
0 siblings, 1 reply; 11+ messages in thread
From: Lei Wen @ 2013-08-06 13:23 UTC (permalink / raw)
To: Paul Turner, linux-kernel, Peter Zijlstra, Ingo Molnar, leiwen
Hi Paul,
I notice in load_balance function, it would check busiest->nr_running
to decide whether to perform the real task movement.
But in some case, I saw the nr_running is not matching with
the task in the queue, which seems make scheduler to do many redundant
checking.
What I means is like there is only one task in the queue, but nr_running
shows it has two. So if that task cannot be moved, it would be still checked
for twice.
With further checking, I find there is one patch you submit before:
commit 953bfcd10e6f3697233e8e5128c611d275da39c1
Author: Paul Turner <pjt@google.com>
Date: Thu Jul 21 09:43:27 2011 -0700
sched: Implement hierarchical task accounting for SCHED_OTHER
In this patch, you increase nr_running when enqueue enqueue_task_stop,
which is the reason nr_running is increase while task not be increased.
It is true at that time, the stopper has been waken up and enqueue again
into cpu, and do the migration job. So the logic should be right there.
My question is whether we could change the judgment into cfs_rq->nr_running?
Since the load_balance is only for cfs, right?
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index bb456f4..ffc0d35 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5096,7 +5096,7 @@ redo:
schedstat_add(sd, lb_imbalance[idle], env.imbalance);
ld_moved = 0;
- if (busiest->nr_running > 1) {
+ if (busiest->cfs.nr_running > 1) {
/*
* Attempt to move tasks. If find_busiest_group has found
* an imbalance but busiest->nr_running <= 1, the group is
Thanks,
Lei
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: false nr_running check in load balance?
2013-08-06 13:23 false nr_running check in load balance? Lei Wen
@ 2013-08-12 14:43 ` Peter Zijlstra
2013-08-13 4:45 ` Lei Wen
0 siblings, 1 reply; 11+ messages in thread
From: Peter Zijlstra @ 2013-08-12 14:43 UTC (permalink / raw)
To: Lei Wen; +Cc: Paul Turner, linux-kernel, Ingo Molnar, leiwen
On Tue, Aug 06, 2013 at 09:23:46PM +0800, Lei Wen wrote:
> Hi Paul,
>
> I notice in load_balance function, it would check busiest->nr_running
> to decide whether to perform the real task movement.
>
> But in some case, I saw the nr_running is not matching with
> the task in the queue, which seems make scheduler to do many redundant
> checking.
> What I means is like there is only one task in the queue, but nr_running
> shows it has two. So if that task cannot be moved, it would be still checked
> for twice.
>
> With further checking, I find there is one patch you submit before:
> commit 953bfcd10e6f3697233e8e5128c611d275da39c1
> Author: Paul Turner <pjt@google.com>
> Date: Thu Jul 21 09:43:27 2011 -0700
>
> sched: Implement hierarchical task accounting for SCHED_OTHER
>
> In this patch, you increase nr_running when enqueue enqueue_task_stop,
> which is the reason nr_running is increase while task not be increased.
> It is true at that time, the stopper has been waken up and enqueue again
> into cpu, and do the migration job. So the logic should be right there.
>
> My question is whether we could change the judgment into cfs_rq->nr_running?
> Since the load_balance is only for cfs, right?
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index bb456f4..ffc0d35 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -5096,7 +5096,7 @@ redo:
> schedstat_add(sd, lb_imbalance[idle], env.imbalance);
>
> ld_moved = 0;
> - if (busiest->nr_running > 1) {
> + if (busiest->cfs.nr_running > 1) {
> /*
> * Attempt to move tasks. If find_busiest_group has found
> * an imbalance but busiest->nr_running <= 1, the group is
>
Not quite right; I think you need busiest->cfs.h_nr_running.
cfs.nr_running is the number of entries running in this 'group'. If
you've got nested groups like:
'root'
\
'A'
/ \
t1 t2
root.nr_running := 1 'A', even though you've got multiple running tasks.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: false nr_running check in load balance?
2013-08-12 14:43 ` Peter Zijlstra
@ 2013-08-13 4:45 ` Lei Wen
2013-08-13 7:38 ` Peter Zijlstra
0 siblings, 1 reply; 11+ messages in thread
From: Lei Wen @ 2013-08-13 4:45 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: Paul Turner, linux-kernel, Ingo Molnar, leiwen
Peter,
On Mon, Aug 12, 2013 at 10:43 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Tue, Aug 06, 2013 at 09:23:46PM +0800, Lei Wen wrote:
>> Hi Paul,
>>
>> I notice in load_balance function, it would check busiest->nr_running
>> to decide whether to perform the real task movement.
>>
>> But in some case, I saw the nr_running is not matching with
>> the task in the queue, which seems make scheduler to do many redundant
>> checking.
>> What I means is like there is only one task in the queue, but nr_running
>> shows it has two. So if that task cannot be moved, it would be still checked
>> for twice.
>>
>> With further checking, I find there is one patch you submit before:
>> commit 953bfcd10e6f3697233e8e5128c611d275da39c1
>> Author: Paul Turner <pjt@google.com>
>> Date: Thu Jul 21 09:43:27 2011 -0700
>>
>> sched: Implement hierarchical task accounting for SCHED_OTHER
>>
>> In this patch, you increase nr_running when enqueue enqueue_task_stop,
>> which is the reason nr_running is increase while task not be increased.
>> It is true at that time, the stopper has been waken up and enqueue again
>> into cpu, and do the migration job. So the logic should be right there.
>>
>> My question is whether we could change the judgment into cfs_rq->nr_running?
>> Since the load_balance is only for cfs, right?
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index bb456f4..ffc0d35 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -5096,7 +5096,7 @@ redo:
>> schedstat_add(sd, lb_imbalance[idle], env.imbalance);
>>
>> ld_moved = 0;
>> - if (busiest->nr_running > 1) {
>> + if (busiest->cfs.nr_running > 1) {
>> /*
>> * Attempt to move tasks. If find_busiest_group has found
>> * an imbalance but busiest->nr_running <= 1, the group is
>>
>
> Not quite right; I think you need busiest->cfs.h_nr_running.
> cfs.nr_running is the number of entries running in this 'group'. If
> you've got nested groups like:
>
> 'root'
> \
> 'A'
> / \
> t1 t2
>
> root.nr_running := 1 'A', even though you've got multiple running tasks.
>
You're absolutely right for this. :)
I miss it for not considering the group case...
Then do you think it is necessary to do below change in load_balance() code?
- if (busiest->nr_running > 1) {
+ if (busiest->cfs.h_nr_running > 1) {
Thanks,
Lei
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: false nr_running check in load balance?
2013-08-13 4:45 ` Lei Wen
@ 2013-08-13 7:38 ` Peter Zijlstra
2013-08-13 8:08 ` Paul Turner
0 siblings, 1 reply; 11+ messages in thread
From: Peter Zijlstra @ 2013-08-13 7:38 UTC (permalink / raw)
To: Lei Wen; +Cc: Paul Turner, linux-kernel, Ingo Molnar, leiwen
On Tue, Aug 13, 2013 at 12:45:12PM +0800, Lei Wen wrote:
> > Not quite right; I think you need busiest->cfs.h_nr_running.
> > cfs.nr_running is the number of entries running in this 'group'. If
> > you've got nested groups like:
> >
> > 'root'
> > \
> > 'A'
> > / \
> > t1 t2
> >
> > root.nr_running := 1 'A', even though you've got multiple running tasks.
> >
>
> You're absolutely right for this. :)
> I miss it for not considering the group case...
>
> Then do you think it is necessary to do below change in load_balance() code?
> - if (busiest->nr_running > 1) {
> + if (busiest->cfs.h_nr_running > 1) {
>
Yes I think that would be fine.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: false nr_running check in load balance?
2013-08-13 7:38 ` Peter Zijlstra
@ 2013-08-13 8:08 ` Paul Turner
2013-08-13 8:18 ` Lei Wen
2013-08-15 17:39 ` Peter Zijlstra
0 siblings, 2 replies; 11+ messages in thread
From: Paul Turner @ 2013-08-13 8:08 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: Lei Wen, LKML, Ingo Molnar, Lei Wen
On Tue, Aug 13, 2013 at 12:38 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Tue, Aug 13, 2013 at 12:45:12PM +0800, Lei Wen wrote:
>> > Not quite right; I think you need busiest->cfs.h_nr_running.
>> > cfs.nr_running is the number of entries running in this 'group'. If
>> > you've got nested groups like:
>> >
>> > 'root'
>> > \
>> > 'A'
>> > / \
>> > t1 t2
>> >
>> > root.nr_running := 1 'A', even though you've got multiple running tasks.
>> >
>>
>> You're absolutely right for this. :)
>> I miss it for not considering the group case...
>>
>> Then do you think it is necessary to do below change in load_balance() code?
>> - if (busiest->nr_running > 1) {
>> + if (busiest->cfs.h_nr_running > 1) {
>>
>
> Yes I think that would be fine.
If we pivot to use h_nr_running we should probably also update
call-sites such as cpu_load_avg_per_task() for consistency.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: false nr_running check in load balance?
2013-08-13 8:08 ` Paul Turner
@ 2013-08-13 8:18 ` Lei Wen
2013-08-13 9:25 ` Paul Turner
2013-08-15 17:39 ` Peter Zijlstra
1 sibling, 1 reply; 11+ messages in thread
From: Lei Wen @ 2013-08-13 8:18 UTC (permalink / raw)
To: Paul Turner; +Cc: Peter Zijlstra, LKML, Ingo Molnar, Lei Wen
Hi Paul,
On Tue, Aug 13, 2013 at 4:08 PM, Paul Turner <pjt@google.com> wrote:
> On Tue, Aug 13, 2013 at 12:38 AM, Peter Zijlstra <peterz@infradead.org> wrote:
>> On Tue, Aug 13, 2013 at 12:45:12PM +0800, Lei Wen wrote:
>>> > Not quite right; I think you need busiest->cfs.h_nr_running.
>>> > cfs.nr_running is the number of entries running in this 'group'. If
>>> > you've got nested groups like:
>>> >
>>> > 'root'
>>> > \
>>> > 'A'
>>> > / \
>>> > t1 t2
>>> >
>>> > root.nr_running := 1 'A', even though you've got multiple running tasks.
>>> >
>>>
>>> You're absolutely right for this. :)
>>> I miss it for not considering the group case...
>>>
>>> Then do you think it is necessary to do below change in load_balance() code?
>>> - if (busiest->nr_running > 1) {
>>> + if (busiest->cfs.h_nr_running > 1) {
>>>
>>
>> Yes I think that would be fine.
>
> If we pivot to use h_nr_running we should probably also update
> call-sites such as cpu_load_avg_per_task() for consistency.
I didn't find cpu_load_avg_per_task in the latest linux git...
Is it a new patch pending while not being submitted?
Thanks,
Lei
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: false nr_running check in load balance?
2013-08-13 8:18 ` Lei Wen
@ 2013-08-13 9:25 ` Paul Turner
2013-08-18 9:12 ` Lei Wen
0 siblings, 1 reply; 11+ messages in thread
From: Paul Turner @ 2013-08-13 9:25 UTC (permalink / raw)
To: Lei Wen; +Cc: Peter Zijlstra, LKML, Ingo Molnar, Lei Wen
On Tue, Aug 13, 2013 at 1:18 AM, Lei Wen <adrian.wenl@gmail.com> wrote:
> Hi Paul,
>
> On Tue, Aug 13, 2013 at 4:08 PM, Paul Turner <pjt@google.com> wrote:
>> On Tue, Aug 13, 2013 at 12:38 AM, Peter Zijlstra <peterz@infradead.org> wrote:
>>> On Tue, Aug 13, 2013 at 12:45:12PM +0800, Lei Wen wrote:
>>>> > Not quite right; I think you need busiest->cfs.h_nr_running.
>>>> > cfs.nr_running is the number of entries running in this 'group'. If
>>>> > you've got nested groups like:
>>>> >
>>>> > 'root'
>>>> > \
>>>> > 'A'
>>>> > / \
>>>> > t1 t2
>>>> >
>>>> > root.nr_running := 1 'A', even though you've got multiple running tasks.
>>>> >
>>>>
>>>> You're absolutely right for this. :)
>>>> I miss it for not considering the group case...
>>>>
>>>> Then do you think it is necessary to do below change in load_balance() code?
>>>> - if (busiest->nr_running > 1) {
>>>> + if (busiest->cfs.h_nr_running > 1) {
>>>>
>>>
>>> Yes I think that would be fine.
>>
>> If we pivot to use h_nr_running we should probably also update
>> call-sites such as cpu_load_avg_per_task() for consistency.
>
> I didn't find cpu_load_avg_per_task in the latest linux git...
> Is it a new patch pending while not being submitted?
Transposition typo: cpu_avg_load_per_task()
More generally: Most things that examine ->nr_running in the fair
load-balance path.
>
> Thanks,
> Lei
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: false nr_running check in load balance?
2013-08-13 9:25 ` Paul Turner
@ 2013-08-18 9:12 ` Lei Wen
0 siblings, 0 replies; 11+ messages in thread
From: Lei Wen @ 2013-08-18 9:12 UTC (permalink / raw)
To: Paul Turner; +Cc: Peter Zijlstra, LKML, Ingo Molnar, Lei Wen
Paul,
On Tue, Aug 13, 2013 at 5:25 PM, Paul Turner <pjt@google.com> wrote:
> On Tue, Aug 13, 2013 at 1:18 AM, Lei Wen <adrian.wenl@gmail.com> wrote:
>> Hi Paul,
>>
>> On Tue, Aug 13, 2013 at 4:08 PM, Paul Turner <pjt@google.com> wrote:
>>> On Tue, Aug 13, 2013 at 12:38 AM, Peter Zijlstra <peterz@infradead.org> wrote:
>>>> On Tue, Aug 13, 2013 at 12:45:12PM +0800, Lei Wen wrote:
>>>>> > Not quite right; I think you need busiest->cfs.h_nr_running.
>>>>> > cfs.nr_running is the number of entries running in this 'group'. If
>>>>> > you've got nested groups like:
>>>>> >
>>>>> > 'root'
>>>>> > \
>>>>> > 'A'
>>>>> > / \
>>>>> > t1 t2
>>>>> >
>>>>> > root.nr_running := 1 'A', even though you've got multiple running tasks.
>>>>> >
>>>>>
>>>>> You're absolutely right for this. :)
>>>>> I miss it for not considering the group case...
>>>>>
>>>>> Then do you think it is necessary to do below change in load_balance() code?
>>>>> - if (busiest->nr_running > 1) {
>>>>> + if (busiest->cfs.h_nr_running > 1) {
>>>>>
>>>>
>>>> Yes I think that would be fine.
>>>
>>> If we pivot to use h_nr_running we should probably also update
>>> call-sites such as cpu_load_avg_per_task() for consistency.
>>
>> I didn't find cpu_load_avg_per_task in the latest linux git...
>> Is it a new patch pending while not being submitted?
>
> Transposition typo: cpu_avg_load_per_task()
> More generally: Most things that examine ->nr_running in the fair
> load-balance path.
>
I see...
I have submitted several patches, which covers cpu_avg_load_per_task.
Please help to check them.
Thanks,
Lei
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: false nr_running check in load balance?
2013-08-13 8:08 ` Paul Turner
2013-08-13 8:18 ` Lei Wen
@ 2013-08-15 17:39 ` Peter Zijlstra
2013-08-15 18:23 ` Paul Turner
1 sibling, 1 reply; 11+ messages in thread
From: Peter Zijlstra @ 2013-08-15 17:39 UTC (permalink / raw)
To: Paul Turner; +Cc: Lei Wen, LKML, Ingo Molnar, Lei Wen
On Tue, Aug 13, 2013 at 01:08:17AM -0700, Paul Turner wrote:
> On Tue, Aug 13, 2013 at 12:38 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> > On Tue, Aug 13, 2013 at 12:45:12PM +0800, Lei Wen wrote:
> >> > Not quite right; I think you need busiest->cfs.h_nr_running.
> >> > cfs.nr_running is the number of entries running in this 'group'. If
> >> > you've got nested groups like:
> >> >
> >> > 'root'
> >> > \
> >> > 'A'
> >> > / \
> >> > t1 t2
> >> >
> >> > root.nr_running := 1 'A', even though you've got multiple running tasks.
One thing though; doesn't h_nr_running over count the number of tasks?
That is, doesn't it count the runnable entities so the above case would
give root.h_nr_running := 3, where we would only have 2 runnable tasks.
Double check this and be careful when doing the conversion.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: false nr_running check in load balance?
2013-08-15 17:39 ` Peter Zijlstra
@ 2013-08-15 18:23 ` Paul Turner
2013-08-15 18:39 ` Peter Zijlstra
0 siblings, 1 reply; 11+ messages in thread
From: Paul Turner @ 2013-08-15 18:23 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: Lei Wen, LKML, Ingo Molnar, Lei Wen
On Thu, Aug 15, 2013 at 10:39 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Tue, Aug 13, 2013 at 01:08:17AM -0700, Paul Turner wrote:
>> On Tue, Aug 13, 2013 at 12:38 AM, Peter Zijlstra <peterz@infradead.org> wrote:
>> > On Tue, Aug 13, 2013 at 12:45:12PM +0800, Lei Wen wrote:
>> >> > Not quite right; I think you need busiest->cfs.h_nr_running.
>> >> > cfs.nr_running is the number of entries running in this 'group'. If
>> >> > you've got nested groups like:
>> >> >
>> >> > 'root'
>> >> > \
>> >> > 'A'
>> >> > / \
>> >> > t1 t2
>> >> >
>> >> > root.nr_running := 1 'A', even though you've got multiple running tasks.
>
> One thing though; doesn't h_nr_running over count the number of tasks?
> That is, doesn't it count the runnable entities so the above case would
> give root.h_nr_running := 3, where we would only have 2 runnable tasks.
>
> Double check this and be careful when doing the conversion.
This should be ok: it's accounted like rq->nr_running, not cfs_rq->nr_running.
Specifically: both only account tasks; group-entities do not contribute.
The fact that this distinction exists, despite the very similar names
is unfortunate.
We could consider renaming to h_nr_{running_,}tasks for clarity.
The same applies to rq->nr_running, although that would involve more churn.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: false nr_running check in load balance?
2013-08-15 18:23 ` Paul Turner
@ 2013-08-15 18:39 ` Peter Zijlstra
0 siblings, 0 replies; 11+ messages in thread
From: Peter Zijlstra @ 2013-08-15 18:39 UTC (permalink / raw)
To: Paul Turner; +Cc: Lei Wen, LKML, Ingo Molnar, Lei Wen
On Thu, Aug 15, 2013 at 11:23:53AM -0700, Paul Turner wrote:
> On Thu, Aug 15, 2013 at 10:39 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> > On Tue, Aug 13, 2013 at 01:08:17AM -0700, Paul Turner wrote:
> >> On Tue, Aug 13, 2013 at 12:38 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> >> > On Tue, Aug 13, 2013 at 12:45:12PM +0800, Lei Wen wrote:
> >> >> > Not quite right; I think you need busiest->cfs.h_nr_running.
> >> >> > cfs.nr_running is the number of entries running in this 'group'. If
> >> >> > you've got nested groups like:
> >> >> >
> >> >> > 'root'
> >> >> > \
> >> >> > 'A'
> >> >> > / \
> >> >> > t1 t2
> >> >> >
> >> >> > root.nr_running := 1 'A', even though you've got multiple running tasks.
> >
> > One thing though; doesn't h_nr_running over count the number of tasks?
> > That is, doesn't it count the runnable entities so the above case would
> > give root.h_nr_running := 3, where we would only have 2 runnable tasks.
> >
> > Double check this and be careful when doing the conversion.
>
> This should be ok: it's accounted like rq->nr_running, not cfs_rq->nr_running.
> Specifically: both only account tasks; group-entities do not contribute.
Ah, ok. I should have looked at the code I guess... :-)
> The fact that this distinction exists, despite the very similar names
> is unfortunate.
> We could consider renaming to h_nr_{running_,}tasks for clarity.
> The same applies to rq->nr_running, although that would involve more churn.
Yah.. that would clarify, although longer variable names will also get
us into more line-breaks I'm sure.
Lets keep it as is. Maybe a comment somewhere would be enough.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-08-18 9:12 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-06 13:23 false nr_running check in load balance? Lei Wen
2013-08-12 14:43 ` Peter Zijlstra
2013-08-13 4:45 ` Lei Wen
2013-08-13 7:38 ` Peter Zijlstra
2013-08-13 8:08 ` Paul Turner
2013-08-13 8:18 ` Lei Wen
2013-08-13 9:25 ` Paul Turner
2013-08-18 9:12 ` Lei Wen
2013-08-15 17:39 ` Peter Zijlstra
2013-08-15 18:23 ` Paul Turner
2013-08-15 18:39 ` Peter Zijlstra
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.