Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1354363
| Path | csiph.com!news.freedyn.net!aioe.org!gothmog.csi.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Andrew Hunter <ahh@google.com> |
| Newsgroups | linux.kernel |
| Subject | Re: Migrated CFS task getting an unfair advantage |
| Date | Wed, 09 Mar 2016 20:10:01 +0100 |
| Message-ID | <raREB-3Sz-13@gated-at.bofh.it> (permalink) |
| References | <raIBk-5QY-3@gated-at.bofh.it> <raL6b-7IU-21@gated-at.bofh.it> <raM2f-8kD-21@gated-at.bofh.it> |
| X-Original-To | pavankumar kondeti <pavankumar.kondeti@gmail.com> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=K38Ds73qnm8JiXu5nGbRg1VVocOsgOQXzOE94Q+mV5I=; b=jkJOnmfDW27/Qfv5PdegfH7ZuzzQ2Nptl8B+V++C7lENpvADJOKEFaeYbbMVV9M66k bQ4dnPlkOjMpbXUXz3rkf2kBJ+tDYDaNLMAaJwJeiEHMTj9Fn0nzysEDks0hxNngruiI fTz5uMxs1bwuz0SICey5T9HFGTE1DrzAu4RvbJjeIUl+AlsdFFBjTl0bzlGnStcdMQev /fik7Yw5xAV730VdCFSVu8UKEmhhkaT8J8haeD+Xp8S4Y2uQB0gYugzQ5K5aZnQZfq18 5owM04jvJ7OQy60Jpj+JmGk8Szng2Wp20qe0U0TvT1gRhrQnvX657ywI7L8kjbOYFsaE a6tA== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=K38Ds73qnm8JiXu5nGbRg1VVocOsgOQXzOE94Q+mV5I=; b=Fwee8nDKDB7EUqA+XBTZbu9vNEYrVnVmNGNV/MXrZcXN7WZQpHPOqovO76iyZJ30do 81uDQqXYXgP05SbRjhlc88f89CGVvtTf26e/7J6Ean7+a1EpdgbVtUPoQQW3W5//fE6n SJHtnaRFLh3yNz0ufqg34eKgQf13VaLxtiREJ9IlS2rc9q2KJo4HSkww3JBCfTmdNs4G ih8CNCg5bsHa7GfsW119CSXXhvAlz6H1kPSQ6udPZirPfmJZHBkxldkoU6aV+2pcK4Jb DuCJuFdW3mw+WwtFzCh595WAzCCuSCQwDusiQOQLERs/+w0qEg0HHxK1xloV5cUM5V2c 03/g== |
| X-Gm-Message-State | AD7BkJJifuEn3zK7OM05sDFqRqx+aqtSYt8VfAeZy9/a8+daaKTQQ0S1cRHpeVfs4Id9JxvutaKcQSUVkWFyfLFN |
| MIME-Version | 1.0 |
| X-Received | by 10.50.65.35 with SMTP id u3mr726923igs.3.1457550042518; Wed, 09 Mar 2016 11:00:42 -0800 (PST) |
| Content-Type | text/plain; charset=UTF-8 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 121 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Peter Zijlstra <peterz@infradead.org>, Pavan Kondeti <pkondeti@codeaurora.org>, lkml <linux-kernel@vger.kernel.org>, Mike Galbraith <umgwanakikbuti@gmail.com>, Ingo Molnar <mingo@kernel.org>, Paul Turner <pjt@google.com>, Ben Segall <bsegall@google.com>, Matt Fleming <matt@codeblueprint.co.uk>, Morten Rasmussen <morten.rasmussen@arm.com>, byungchul.park@lge.com |
| X-Original-Date | Wed, 9 Mar 2016 11:00:42 -0800 |
| X-Original-Message-ID | <CADroS=6Ncpao6WWXBxboB6quqUP96EnjbsDUZqNgASd_PzDGaA@mail.gmail.com> |
| X-Original-References | <CAEU1=PnHOwPmt80QWvc5RO096VpNyoxQDAcYCpQRrR+4PpRsOQ@mail.gmail.com> <20160309120403.GK6344@twins.programming.kicks-ass.net> <CAEU1=P=q4beYrMFZj3Q3OCxsYpuG-yCogcBv3AyXaP2i6pPkHQ@mail.gmail.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1354363 |
Show key headers only | View raw
At Google, we essentially reverted 88ec22d and the subsequent tweaks
to it, keeping vruntime absolute always , instead using
task_move_group_fair to change the basis of relative min_vruntime
between cpus. We found this made it a lot easier to reason about and
work with corss-cpu computations. I could post the patch if it would
be of interest...
On Wed, Mar 9, 2016 at 5:06 AM, pavankumar kondeti
<pavankumar.kondeti@gmail.com> wrote:
> Hi Peter,
>
> On Wed, Mar 9, 2016 at 5:34 PM, Peter Zijlstra <peterz@infradead.org> wrote:
>> On Wed, Mar 09, 2016 at 02:52:57PM +0530, Pavan Kondeti wrote:
>>
>>> When a CFS task is enqueued during migration (load balance or change in
>>> affinity), its vruntime is normalized before updating the current and
>>> cfs_rq->min_vruntime.
>>
>> static void
>> enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
>> {
>> /*
>> * Update the normalized vruntime before updating min_vruntime
>> * through calling update_curr().
>> */
>> if (!(flags & ENQUEUE_WAKEUP) || (flags & ENQUEUE_WAKING))
>> se->vruntime += cfs_rq->min_vruntime;
>>
>> update_curr(cfs_rq);
>>
>> This, right? Some idiot wrote a comment but forgot to explain why.
>>
>>> If the current entity is a low priority task or belongs to a cgroup
>>> that has lower cpu.shares and it is the only entity queued, there is a
>>> possibility of big update to the cfs_rq->min_vruntime.
>>
>>> As the migrated task is normalized before this update, it gets an
>>> unfair advantage over tasks queued after this point. If the migrated
>>> task is a CPU hogger, the other CFS tasks queued on this CPU gets
>>> starved.
>>
>> Because it takes a whole while for the newly placed task to gain on the
>> previous task, right?
>>
>
> Yes. The newly woken up task vruntime is adjusted wrt the cfs_rq->min_vruntime.
> The cfs_rq->min_vruntime can potentially be hundreds of msec beyond the
> migrated task.
>
>>> If we add the migrated task to destination CPU cfs_rq's rb tree before
>>> updating the current in enqueue_entity(), the cfs_rq->min_vruntime
>>> does not go beyond the newly migrated task. Is this an acceptable
>>> solution?
>>
>> Hurm.. so I'm not sure how that would solve anything. The existing task
>> would still be shot far into the future.
>>
> In my testing, the problem is gone with this approach.
>
> The update_min_vruntime() called from update_curr() has a check to make
> sure that cfs_rq->min_vruntime does not go beyond the leftmost entity
> (in this case it would be the migrated task) vruntime. so we don't see
> the migrated task getting any advantage.
>
>> What you want is to normalize after update_curr()... but we cannot do
>> that in the case cfs_rq->curr == se (which I suppose is what that
>> comment is on about).
>>
>> Does something like the below work?
>>
>
> Thanks for providing this patch. It solved the problem.
>
>> ---
>> kernel/sched/fair.c | 20 ++++++++++++++------
>> 1 file changed, 14 insertions(+), 6 deletions(-)
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index 33130529e9b5..3c114d971d84 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -3157,17 +3157,25 @@ static inline void check_schedstat_required(void)
>> static void
>> enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
>> {
>> + bool renorm = !(flags & ENQUEUE_WAKEUP) || (flags & ENQUEUE_WAKING);
>> + bool curr = cfs_rq->curr == se;
>> +
>> /*
>> - * Update the normalized vruntime before updating min_vruntime
>> - * through calling update_curr().
>> + * If we're the current task, we must renormalise before calling
>> + * update_curr().
>> */
>> - if (!(flags & ENQUEUE_WAKEUP) || (flags & ENQUEUE_WAKING))
>> + if (renorm && curr)
>> se->vruntime += cfs_rq->min_vruntime;
>>
>> + update_curr(cfs_rq);
>> +
>> /*
>> - * Update run-time statistics of the 'current'.
>> + * Otherwise, renormalise after, such that we're placed at the current
>> + * moment in time, instead of some random moment in the past.
>> */
>> - update_curr(cfs_rq);
>> + if (renorm && !curr)
>> + se->vruntime += cfs_rq->min_vruntime;
>> +
>> enqueue_entity_load_avg(cfs_rq, se);
>> account_entity_enqueue(cfs_rq, se);
>> update_cfs_shares(cfs_rq);
>> @@ -3183,7 +3191,7 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
>> update_stats_enqueue(cfs_rq, se);
>> check_spread(cfs_rq, se);
>> }
>> - if (se != cfs_rq->curr)
>> + if (!curr)
>> __enqueue_entity(cfs_rq, se);
>> se->on_rq = 1;
>>
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Migrated CFS task getting an unfair advantage Pavan Kondeti <pkondeti@codeaurora.org> - 2016-03-09 10:30 +0100
Re: Migrated CFS task getting an unfair advantage Peter Zijlstra <peterz@infradead.org> - 2016-03-09 13:10 +0100
Re: Migrated CFS task getting an unfair advantage pavankumar kondeti <pavankumar.kondeti@gmail.com> - 2016-03-09 14:10 +0100
Re: Migrated CFS task getting an unfair advantage Andrew Hunter <ahh@google.com> - 2016-03-09 20:10 +0100
Re: Migrated CFS task getting an unfair advantage Peter Zijlstra <peterz@infradead.org> - 2016-03-09 20:30 +0100
Re: Migrated CFS task getting an unfair advantage Byungchul Park <byungchul.park@lge.com> - 2016-03-10 00:50 +0100
csiph-web