Re: [PATCH 9/9] sched,fair: Alternative sched_slice()

From: Peter Zijlstra
Date: Fri Mar 26 2021 - 10:09:01 EST


On Fri, Mar 26, 2021 at 01:08:44PM +0100, Dietmar Eggemann wrote:
> On 26/03/2021 11:34, Peter Zijlstra wrote:
> > The current sched_slice() seems to have issues; there's two possible
> > things that could be improved:
> >
> > - the 'nr_running' used for __sched_period() is daft when cgroups are
> > considered. Using the RQ wide h_nr_running seems like a much more
> > consistent number.
> >
> > - (esp) cgroups can slice it real fine, which makes for easy
> > over-scheduling, ensure min_gran is what the name says.
>
> So ALT_PERIOD considers all runnable CFS tasks now and BASE_SLICE
> guarantees min_gran as a floor for cgroup (hierarchies) with small
> weight value(s)?

Pretty much.

The previous cfs_rq->nr_running is just how many runnable thingies there
are in whatever cgroup you happen to be in on our CPU, not counting its
child cgroups nor whatever is upwards. Which is a pretty arbitrary
value.

By always using h_nr_running of the root, we get a consistent number and
the period is the same for all tasks on the CPU.

And yes, low weight cgroups, or even just a nice -20 and 19 task
together would result in *tiny* slices, which then leads to
over-scheduling. So by only scaling the part between period and
min_gran, we still get a variable slice, but also avoid the worst cases.