Re: [PATCH 07/15] sched,cfs: fix zero length timeslice calculation
From: Vincent Guittot
Date: Wed Aug 28 2019 - 12:59:34 EST
On Thu, 22 Aug 2019 at 04:18, Rik van Riel <riel@xxxxxxxxxxx> wrote:
> The way the time slice length is currently calculated, not only do high
> priority tasks get longer time slices than low priority tasks, but due
> to fixed point math, low priority tasks could end up with a zero length
> time slice. This can lead to cache thrashing and other inefficiencies.
Have you got more details of those UCs ?
> Cap the minimum time slice length to sysctl_sched_min_granularity.
> Tasks that end up getting a time slice length too long for their relative
> priority will simply end up having their vruntime advanced much faster than
> other tasks, resulting in them receiving time slices less frequently.
In fact that already happen as we wait for the tick to preempt a task
(unless you enable sched_feat(HRTICK))
so it sounds reasonable
> Signed-off-by: Rik van Riel <riel@xxxxxxxxxxx>
> kernel/sched/fair.c | 7 +++++++
> 1 file changed, 7 insertions(+)
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 31a26737a873..8f8c85c6da9b 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -732,6 +732,13 @@ static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
> slice = __calc_delta(slice, se->load.weight, load);
> + /*
> + * To avoid cache thrashing, run at least sysctl_sched_min_granularity.
> + * The vruntime of a low priority task advances faster; those tasks
> + * will simply get time slices less frequently.
> + */
> + slice = max_t(u64, slice, sysctl_sched_min_granularity);
> return slice;