From: Roman Kagan <rkagan@amazon.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Zhang Qiao <zhangqiao22@huawei.com>,
Waiman Long <longman@redhat.com>, Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
"Daniel Bristot de Oliveira" <bristot@redhat.com>,
lkml <linux-kernel@vger.kernel.org>
Subject: Re: [bug-report] possible s64 overflow in max_vruntime()
Date: Thu, 26 Jan 2023 19:31:02 +0100 [thread overview]
Message-ID: <Y9LG5vkf/4ufJb35@u40bc5e070a0153.ant.amazon.com> (raw)
In-Reply-To: <Y9J25xMrItpeHIxD@hirez.programming.kicks-ass.net>
On Thu, Jan 26, 2023 at 01:49:43PM +0100, Peter Zijlstra wrote:
> On Wed, Jan 25, 2023 at 08:45:32PM +0100, Roman Kagan wrote:
>
> > The calculation is indeed safe against the overflow of the vruntimes
> > themselves. However, when the two vruntimes are more than 2^63 apart,
> > their comparison gets inverted due to that s64 overflow.
>
> Yes, but that's a whole different issue. vruntime are not expected to be
> *that* far apart.
>
> That is surely the abnormal case. The normal case is wrap around, and
> that happens 'often' and should continue working.
>
> > And this is what happens here: one scheduling entity has accumulated a
> > vruntime more than 2^63 ahead of another. Now the comparison is
> > inverted due to s64 overflow, and the latter can't get to the cpu,
> > because it appears to have vruntime (much) bigger than that of the
> > former.
>
> If it can be 2^63 ahead, it can also be 2^(64+) ahead and nothing will
> help.
>
> > This situation is reproducible e.g. when one scheduling entity is a
> > multi-cpu hog, and the other is woken up from a long sleep. Normally
>
> A very low weight CPU hog?
Right. In our case this weight was due to the task group consuming
all 448 cpus on the machine; presumably one can achive this on a smaller
machine by tweaking shares of the cgroup.
> > when a task is placed on a cfs_rq, its vruntime is pulled to
> > min_vruntime, to avoid boosting the woken up task. However in this case
> > the task is so much behind in vruntime that it appears ahead instead,
> > its vruntime is not adjusted in place_entity(), and then it looses the
> > cpu to the current scheduling entity.
>
> What I think might be a way out here is passing the the sleep wall-time
> (cfs_rq_clock_pelt() time I suppose) to place entity and simply skip the
> magic if 'big'.
>
> All that only matters for small sleeps anyway.
>
> Something like:
>
> sleep_time = U64_MAX;
> if (se->avg.last_update_time)
> sleep_time = cfs_rq_clock_pelt(cfs_rq) - se->avg.last_update_time;
Interesting, why not rq_clock_task(rq_of(cfs_rq)) - se->exec_start, as
others were suggesting? It appears to better match the notion of sleep
wall-time, no?
Thanks,
Roman.
>
> if (sleep_time > 60*NSEC_PER_SEC) { // 1 minute is huge
> se->vruntime = cfs_rq->min_vruntime;
> return;
> }
>
> // ... rest of place_entity()
>
> Hmm... ?
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
next prev parent reply other threads:[~2023-01-26 18:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-21 15:19 Zhang Qiao
2022-12-21 16:10 ` Waiman Long
2022-12-22 12:45 ` Peter Zijlstra
2022-12-23 13:57 ` Zhang Qiao
2023-01-12 3:01 ` Zhang Qiao
2023-01-25 19:57 ` Roman Kagan
2023-01-25 19:45 ` Roman Kagan
2023-01-26 12:49 ` Peter Zijlstra
2023-01-26 18:31 ` Roman Kagan [this message]
2023-01-27 11:44 ` Peter Zijlstra
2023-01-27 16:18 ` Vincent Guittot
2023-01-27 22:10 ` Benjamin Segall
2023-01-27 22:29 ` Vincent Guittot
2023-01-31 3:21 ` Chen Yu
2023-01-31 9:59 ` Roman Kagan
2023-01-31 11:10 ` Vincent Guittot
2023-02-01 12:52 ` Chen Yu
2023-02-07 19:37 ` Roman Kagan
2023-02-08 10:13 ` Vincent Guittot
2023-02-08 18:09 ` Roman Kagan
2023-02-09 11:26 ` Vincent Guittot
2023-02-09 13:33 ` Roman Kagan
2023-02-09 13:44 ` Vincent Guittot
2023-02-09 14:34 ` Roman Kagan
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=Y9LG5vkf/4ufJb35@u40bc5e070a0153.ant.amazon.com \
--to=rkagan@amazon.de \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=zhangqiao22@huawei.com \
/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
all inboxes | Powered by JetHome®