Repository navigation
Commit b4fb015
sched/rt: Optimize checking group RT scheduler constraints
Group RT scheduler contains protection against setting zero runtime for
cgroup with RT tasks. Right now function tg_set_rt_bandwidth() iterates
over all CPU cgroups and calls tg_has_rt_tasks() for any cgroup which
runtime is zero (not only for changed one). Default RT runtime is zero,
thus tg_has_rt_tasks() will is called for almost at CPU cgroups.
This protection already is slightly racy: runtime limit could be changed
between cpu_cgroup_can_attach() and cpu_cgroup_attach() because changing
cgroup attribute does not lock cgroup_mutex while attach does not lock
rt_constraints_mutex. Changing task scheduler class also races with
changing rt runtime: check in __sched_setscheduler() isn't protected.
Function tg_has_rt_tasks() iterates over all threads in the system.
This gives NR_CGROUPS * NR_TASKS operations under single tasklist_lock
locked for read tg_set_rt_bandwidth(). Any concurrent attempt of locking
tasklist_lock for write (for example fork) will stuck with disabled irqs.
This patch makes two optimizations:
1) Remove locking tasklist_lock and iterate only tasks in cgroup
2) Call tg_has_rt_tasks() iff rt runtime changes from non-zero to zero
All changed code is under CONFIG_RT_GROUP_SCHED.
Testcase:
# mkdir /sys/fs/cgroup/cpu/test{1..10000}
# echo 0 | tee /sys/fs/cgroup/cpu/test*/cpu.rt_runtime_us
At the same time without patch fork time will be >100ms:
# perf trace -e clone --duration 100 stress-ng --fork 1
Also remote ping will show timings >100ms caused by irq latency.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lkml.kernel.org/r/157996383820.4651.11292439232549211693.stgit@buzz1 parent bec2860 commit b4fb015
1 file changed
Lines changed: 11 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2449 | 2449 | | |
2450 | 2450 | | |
2451 | 2451 | | |
2452 | | - | |
2453 | 2452 | | |
2454 | 2453 | | |
2455 | | - | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
2456 | 2457 | | |
2457 | 2458 | | |
2458 | 2459 | | |
2459 | 2460 | | |
2460 | 2461 | | |
2461 | 2462 | | |
2462 | 2463 | | |
2463 | | - | |
2464 | | - | |
2465 | | - | |
2466 | | - | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
2467 | 2468 | | |
2468 | | - | |
| 2469 | + | |
2469 | 2470 | | |
2470 | 2471 | | |
2471 | 2472 | | |
| |||
2496 | 2497 | | |
2497 | 2498 | | |
2498 | 2499 | | |
2499 | | - | |
| 2500 | + | |
2500 | 2501 | | |
2501 | | - | |
| 2502 | + | |
| 2503 | + | |
2502 | 2504 | | |
2503 | 2505 | | |
2504 | 2506 | | |
| |||
2564 | 2566 | | |
2565 | 2567 | | |
2566 | 2568 | | |
2567 | | - | |
2568 | 2569 | | |
2569 | 2570 | | |
2570 | 2571 | | |
| |||
2582 | 2583 | | |
2583 | 2584 | | |
2584 | 2585 | | |
2585 | | - | |
2586 | 2586 | | |
2587 | 2587 | | |
2588 | 2588 | | |
| |||
2641 | 2641 | | |
2642 | 2642 | | |
2643 | 2643 | | |
2644 | | - | |
2645 | 2644 | | |
2646 | | - | |
2647 | 2645 | | |
2648 | 2646 | | |
2649 | 2647 | | |
| |||
0 commit comments