sched/fair: Eliminate bandwidth race between throttling and distribution
authorPaul Turner <pjt@google.com>
Fri, 10 Apr 2020 22:52:07 +0000 (15:52 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 30 Apr 2020 18:14:38 +0000 (20:14 +0200)
commite98fa02c4f2ea4991dae422ac7e34d102d2f0599
treed808815afdf5835b06a6977f7f33b3a04d296809
parentf080d93e1d419099a99d7473ed532289ca8dc717
sched/fair: Eliminate bandwidth race between throttling and distribution

There is a race window in which an entity begins throttling before quota
is added to the pool, but does not finish throttling until after we have
finished with distribute_cfs_runtime(). This entity is not observed by
distribute_cfs_runtime() because it was not on the throttled list at the
time that distribution was running. This race manifests as rare
period-length statlls for such entities.

Rather than heavy-weight the synchronization with the progress of
distribution, we can fix this by aborting throttling if bandwidth has
become available. Otherwise, we immediately add the entity to the
throttled list so that it can be observed by a subsequent distribution.

Additionally, we can remove the case of adding the throttled entity to
the head of the throttled list, and simply always add to the tail.
Thanks to 26a8b12747c97, distribute_cfs_runtime() no longer holds onto
its own pool of runtime. This means that if we do hit the !assign and
distribute_running case, we know that distribution is about to end.

Signed-off-by: Paul Turner <pjt@google.com>
Signed-off-by: Ben Segall <bsegall@google.com>
Signed-off-by: Josh Don <joshdon@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Phil Auld <pauld@redhat.com>
Link: https://lkml.kernel.org/r/20200410225208.109717-2-joshdon@google.com
kernel/sched/fair.c