Skip to content

Commit e67e3e7

Browse files
kudureranganathgregkh
authored andcommitted
sched/fair: Block delayed tasks on throttled hierarchy during dequeue
Dequeuing a fair task on a throttled hierarchy returns early on encountering a throttled cfs_rq since the throttle path has already dequeued the hierarchy above and has adjusted the h_nr_* accounting till the root cfs_rq. dequeue_entities() crucially misses calling __block_task() for delayed tasks being dequeued on the throttled hierarchies, but this was mostly harmless until commit b7ca574 ("sched/core: Tweak wait_task_inactive() to force dequeue sched_delayed tasks") since all existing cases would re-enqueue the task if task_on_rq_queued() returned true and the task would eventually be blocked at pick after the hierarchy was unthrottled. wait_task_inactive() is special as it expects the delayed task on throttled hierarchy to reach the blocked state on dequeue but since __block_task() is never called, task_on_rq_queued() continues to return true. Furthermore, since the task is now off the hierarchy, the pick never reaches it to fully block the task even after unthrottle leading to wait_task_inactive() looping endlessly. Remedy this by calling __block_task() if a delayed task is being dequeued on a throttled hierarchy. This fix is only required for stabled kernels implementing delay dequeue (>= v6.12) before v6.18 since upstream commit e1fad12 ("sched/fair: Switch to task based throttle model") indirectly fixes this by removing the early return conditions in dequeue_entities() as part of the per-task throttle feature. Cc: stable@vger.kernel.org Reported-by: Matt Fleming <matt@readmodwrite.com> Closes: https://lore.kernel.org/all/20250925133310.1843863-1-matt@readmodwrite.com/ Fixes: b7ca574 ("sched/core: Tweak wait_task_inactive() to force dequeue sched_delayed tasks") Tested-by: Matt Fleming <mfleming@cloudflare.com> Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 496b5ef commit e67e3e7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

kernel/sched/fair.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7187,6 +7187,7 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
71877187
int h_nr_delayed = 0;
71887188
struct cfs_rq *cfs_rq;
71897189
u64 slice = 0;
7190+
int ret = 0;
71907191

71917192
if (entity_is_task(se)) {
71927193
p = task_of(se);
@@ -7218,7 +7219,7 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
72187219

72197220
/* end evaluation on encountering a throttled cfs_rq */
72207221
if (cfs_rq_throttled(cfs_rq))
7221-
return 0;
7222+
goto out;
72227223

72237224
/* Don't dequeue parent if it has other entities besides us */
72247225
if (cfs_rq->load.weight) {
@@ -7261,7 +7262,7 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
72617262

72627263
/* end evaluation on encountering a throttled cfs_rq */
72637264
if (cfs_rq_throttled(cfs_rq))
7264-
return 0;
7265+
goto out;
72657266
}
72667267

72677268
sub_nr_running(rq, h_nr_queued);
@@ -7273,6 +7274,8 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
72737274
if (unlikely(!was_sched_idle && sched_idle_rq(rq)))
72747275
rq->next_balance = jiffies;
72757276

7277+
ret = 1;
7278+
out:
72767279
if (p && task_delayed) {
72777280
SCHED_WARN_ON(!task_sleep);
72787281
SCHED_WARN_ON(p->on_rq != 1);
@@ -7288,7 +7291,7 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
72887291
__block_task(rq, p);
72897292
}
72907293

7291-
return 1;
7294+
return ret;
72927295
}
72937296

72947297
/*

0 commit comments

Comments
 (0)