Skip to content

Commit af98d8a

Browse files
vishalc-ibmPeter Zijlstra
authored andcommitted
sched/fair: Fix CPU bandwidth limit bypass during CPU hotplug
CPU controller limits are not properly enforced during CPU hotplug operations, particularly during CPU offline. When a CPU goes offline, throttled processes are unintentionally being unthrottled across all CPUs in the system, allowing them to exceed their assigned quota limits. Consider below for an example, Assigning 6.25% bandwidth limit to a cgroup in a 8 CPU system, where, workload is running 8 threads for 20 seconds at 100% CPU utilization, expected (user+sys) time = 10 seconds. $ cat /sys/fs/cgroup/test/cpu.max 50000 100000 $ ./ebizzy -t 8 -S 20 // non-hotplug case real 20.00 s user 10.81 s // intended behaviour sys 0.00 s $ ./ebizzy -t 8 -S 20 // hotplug case real 20.00 s user 14.43 s // Workload is able to run for 14 secs sys 0.00 s // when it should have only run for 10 secs During CPU hotplug, scheduler domains are rebuilt and cpu_attach_domain is called for every active CPU to update the root domain. That ends up calling rq_offline_fair which un-throttles any throttled hierarchies. Unthrottling should only occur for the CPU being hotplugged to allow its throttled processes to become runnable and get migrated to other CPUs. With current patch applied, $ ./ebizzy -t 8 -S 20 // hotplug case real 21.00 s user 10.16 s // intended behaviour sys 0.00 s This also has another symptom, when a CPU goes offline, and if the cfs_rq is not in throttled state and the runtime_remaining still had plenty remaining, it gets reset to 1 here, causing the runtime_remaining of cfs_rq to be quickly depleted. Note: hotplug operation (online, offline) was performed in while(1) loop v3: https://lore.kernel.org/all/[email protected] v2: https://lore.kernel.org/all/[email protected] v1: https://lore.kernel.org/all/[email protected] Suggested-by: Zhang Qiao <[email protected]> Signed-off-by: Vishal Chourasia <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Vincent Guittot <[email protected]> Tested-by: Madadi Vineeth Reddy <[email protected]> Tested-by: Samir Mulani <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7675361 commit af98d8a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

kernel/sched/fair.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6696,6 +6696,10 @@ static void __maybe_unused unthrottle_offline_cfs_rqs(struct rq *rq)
66966696

66976697
lockdep_assert_rq_held(rq);
66986698

6699+
// Do not unthrottle for an active CPU
6700+
if (cpumask_test_cpu(cpu_of(rq), cpu_active_mask))
6701+
return;
6702+
66996703
/*
67006704
* The rq clock has already been updated in the
67016705
* set_rq_offline(), so we should skip updating
@@ -6710,19 +6714,21 @@ static void __maybe_unused unthrottle_offline_cfs_rqs(struct rq *rq)
67106714
if (!cfs_rq->runtime_enabled)
67116715
continue;
67126716

6713-
/*
6714-
* clock_task is not advancing so we just need to make sure
6715-
* there's some valid quota amount
6716-
*/
6717-
cfs_rq->runtime_remaining = 1;
67186717
/*
67196718
* Offline rq is schedulable till CPU is completely disabled
67206719
* in take_cpu_down(), so we prevent new cfs throttling here.
67216720
*/
67226721
cfs_rq->runtime_enabled = 0;
67236722

6724-
if (cfs_rq_throttled(cfs_rq))
6725-
unthrottle_cfs_rq(cfs_rq);
6723+
if (!cfs_rq_throttled(cfs_rq))
6724+
continue;
6725+
6726+
/*
6727+
* clock_task is not advancing so we just need to make sure
6728+
* there's some valid quota amount
6729+
*/
6730+
cfs_rq->runtime_remaining = 1;
6731+
unthrottle_cfs_rq(cfs_rq);
67266732
}
67276733
rcu_read_unlock();
67286734

0 commit comments

Comments
 (0)