Re: [PATCH] sched/fair: Fix inaccurate h_nr_runnable accounting with delayed dequeue

From: K Prateek Nayak
Date: Mon Jan 20 2025 - 04:12:40 EST


Hello Madadi Vineeth Reddy,

Thank you for the review and test.

On 1/20/2025 10:36 AM, Madadi Vineeth Reddy wrote:
Hi Prateek,

A SCHED_WARN_ON() to inspect h_nr_runnable post its update in
dequeue_entities() like below:

cfs_rq->h_nr_runnable -= h_nr_runnable;
SCHED_WARN_ON(((int) cfs_rq->h_nr_runnable) < 0);

is consistently tripped when running wakeup intensive workloads like
hackbench in a cgroup.

I observed that the WARN_ON is triggered during the boot process without
the patch, and the patch resolves the issue.

However, I was unable to trigger the WARN_ON by running hackbench in a
cgroup without the patch. Could you please share the specific test
scenario or configuration you used to reproduce it?

Can you try converting the SCHED_WARN_ON() to a WARN_ON() and try again.
I can consistently hit it to a point that it floods my console. With
autogroup enabled on Ubuntu, I believe it is trivial to hit this issue.

Following is the exact diff I'm using on top of tip:sched/core that
floods my console:

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 98ac49ce78ea..7bc2c57601b6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7160,6 +7160,7 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
cfs_rq->h_nr_runnable -= h_nr_runnable;
cfs_rq->h_nr_queued -= h_nr_queued;
+ WARN_ON(((int) cfs_rq->h_nr_runnable) < 0);
cfs_rq->h_nr_idle -= h_nr_idle;
if (cfs_rq_is_idle(cfs_rq))
@@ -7199,6 +7200,7 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
cfs_rq->h_nr_runnable -= h_nr_runnable;
cfs_rq->h_nr_queued -= h_nr_queued;
+ WARN_ON(((int) cfs_rq->h_nr_runnable) < 0);
cfs_rq->h_nr_idle -= h_nr_idle;
if (cfs_rq_is_idle(cfs_rq))
--

I tested this on a 32 vCPU VM and I get similar floods.


For the boot process scenario:
Tested-by: Madadi Vineeth Reddy <vineethr@xxxxxxxxxxxxx>

Thanks a ton for testing!


Thanks,
Madadi Vineeth Reddy

--
Thanks and Regards,
Prateek