Skip to content

Commit ada79b5

Browse files
koct9igregkh
authored andcommitted
sched/fair: Initialize throttle_count for new task-groups lazily
commit 094f469172e00d6ab0a3130b0e01c83b3cf3a98d upstream. Cgroup created inside throttled group must inherit current throttle_count. Broken throttle_count allows to nominate throttled entries as a next buddy, later this leads to null pointer dereference in pick_next_task_fair(). This patch initialize cfs_rq->throttle_count at first enqueue: laziness allows to skip locking all rq at group creation. Lazy approach also allows to skip full sub-tree scan at throttling hierarchy (not in this patch). Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: bsegall@google.com Link: http://lkml.kernel.org/r/146608182119.21870.8439834428248129633.stgit@buzz Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Ben Pineau <benjamin.pineau@mirakl.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f01ae9c commit ada79b5

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

kernel/sched/fair.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,6 +3918,26 @@ static void check_enqueue_throttle(struct cfs_rq *cfs_rq)
39183918
if (!cfs_bandwidth_used())
39193919
return;
39203920

3921+
/* Synchronize hierarchical throttle counter: */
3922+
if (unlikely(!cfs_rq->throttle_uptodate)) {
3923+
struct rq *rq = rq_of(cfs_rq);
3924+
struct cfs_rq *pcfs_rq;
3925+
struct task_group *tg;
3926+
3927+
cfs_rq->throttle_uptodate = 1;
3928+
3929+
/* Get closest up-to-date node, because leaves go first: */
3930+
for (tg = cfs_rq->tg->parent; tg; tg = tg->parent) {
3931+
pcfs_rq = tg->cfs_rq[cpu_of(rq)];
3932+
if (pcfs_rq->throttle_uptodate)
3933+
break;
3934+
}
3935+
if (tg) {
3936+
cfs_rq->throttle_count = pcfs_rq->throttle_count;
3937+
cfs_rq->throttled_clock_task = rq_clock_task(rq);
3938+
}
3939+
}
3940+
39213941
/* an active group must be handled by the update_curr()->put() path */
39223942
if (!cfs_rq->runtime_enabled || cfs_rq->curr)
39233943
return;

kernel/sched/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ struct cfs_rq {
417417

418418
u64 throttled_clock, throttled_clock_task;
419419
u64 throttled_clock_task_time;
420-
int throttled, throttle_count;
420+
int throttled, throttle_count, throttle_uptodate;
421421
struct list_head throttled_list;
422422
#endif /* CONFIG_CFS_BANDWIDTH */
423423
#endif /* CONFIG_FAIR_GROUP_SCHED */

0 commit comments

Comments
 (0)