[RFC PATCH V2 0/3] sched/fair: Fix nr-running vs delayed-dequeue

Xuewen Yan posted 3 patches 11 months, 1 week ago
kernel/sched/core.c  |  2 +-
kernel/sched/fair.c  | 10 +++++++---
kernel/sched/sched.h |  5 +++++
3 files changed, 13 insertions(+), 4 deletions(-)
[RFC PATCH V2 0/3] sched/fair: Fix nr-running vs delayed-dequeue
Posted by Xuewen Yan 11 months, 1 week ago
Delayed dequeued feature keeps a sleeping sched_entitiy enqueued until its
lag has elapsed. As a result, it stays also visible in rq->nr_running.
However, sometimes when using nr-running, we should not consider
sched-delayed tasks.
This serie fixes those by adding a helper function which return the
number of sched-delayed tasks. And when we should get the real runnable
tasks, we sub the nr-delayed tasks.

Changes sinc v1:
- add cover-letter
- add helper function;
- add more fixes

Xuewen Yan (3):
  sched/fair: Fixup-wake_up_sync-vs-DELAYED_DEQUEUE
  sched/fair: Do not consider the sched-delayed task when yield
  sched: Do not consider the delayed task when cpu is about to enter
    idle

 kernel/sched/core.c  |  2 +-
 kernel/sched/fair.c  | 10 +++++++---
 kernel/sched/sched.h |  5 +++++
 3 files changed, 13 insertions(+), 4 deletions(-)

-- 
2.25.1
Re: [RFC PATCH V2 0/3] sched/fair: Fix nr-running vs delayed-dequeue
Posted by Peter Zijlstra 11 months, 1 week ago
On Mon, Mar 03, 2025 at 06:52:38PM +0800, Xuewen Yan wrote:
> Delayed dequeued feature keeps a sleeping sched_entitiy enqueued until its
> lag has elapsed. As a result, it stays also visible in rq->nr_running.
> However, sometimes when using nr-running, we should not consider
> sched-delayed tasks.
> This serie fixes those by adding a helper function which return the
> number of sched-delayed tasks. And when we should get the real runnable
> tasks, we sub the nr-delayed tasks.
> 

Is there an actual performance improvement? Because when a runqueue
looses competition, delayed tasks very quickly dissipate.
Re: [RFC PATCH V2 0/3] sched/fair: Fix nr-running vs delayed-dequeue
Posted by Xuewen Yan 11 months, 1 week ago
Hi Peter

On Mon, Mar 3, 2025 at 8:00 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Mon, Mar 03, 2025 at 06:52:38PM +0800, Xuewen Yan wrote:
> > Delayed dequeued feature keeps a sleeping sched_entitiy enqueued until its
> > lag has elapsed. As a result, it stays also visible in rq->nr_running.
> > However, sometimes when using nr-running, we should not consider
> > sched-delayed tasks.
> > This serie fixes those by adding a helper function which return the
> > number of sched-delayed tasks. And when we should get the real runnable
> > tasks, we sub the nr-delayed tasks.
> >
>
> Is there an actual performance improvement? Because when a runqueue
> looses competition, delayed tasks very quickly dissipate.

At the moment, I don't have very detailed test data. I've been
studying delay-dequeue carefully recently, and these are the issues I
feel might need modification as I go through the code.

Thanks!

BR
Re: [RFC PATCH V2 0/3] sched/fair: Fix nr-running vs delayed-dequeue
Posted by Vincent Guittot 11 months, 1 week ago
On Tue, 4 Mar 2025 at 02:56, Xuewen Yan <xuewen.yan94@gmail.com> wrote:
>
> Hi Peter
>
> On Mon, Mar 3, 2025 at 8:00 PM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Mon, Mar 03, 2025 at 06:52:38PM +0800, Xuewen Yan wrote:
> > > Delayed dequeued feature keeps a sleeping sched_entitiy enqueued until its
> > > lag has elapsed. As a result, it stays also visible in rq->nr_running.
> > > However, sometimes when using nr-running, we should not consider
> > > sched-delayed tasks.
> > > This serie fixes those by adding a helper function which return the
> > > number of sched-delayed tasks. And when we should get the real runnable
> > > tasks, we sub the nr-delayed tasks.
> > >
> >
> > Is there an actual performance improvement? Because when a runqueue
> > looses competition, delayed tasks very quickly dissipate.
>
> At the moment, I don't have very detailed test data. I've been
> studying delay-dequeue carefully recently, and these are the issues I
> feel might need modification as I go through the code.

Patch 1 makes sense for me but I'm less convinced by patch 2 and 3. As
Peter also mentioned, the state where cpu_rq(cpu)->nr_running ==
cfs_h_nr_delayed(cpu_rq(cpu)) is really transient as they will be
picked as soon as the last runnable task will be dequeued

>
> Thanks!
>
> BR
Re: [RFC PATCH V2 0/3] sched/fair: Fix nr-running vs delayed-dequeue
Posted by Xuewen Yan 11 months, 1 week ago
Hi Vincent,

On Wed, Mar 5, 2025 at 4:17 PM Vincent Guittot
<vincent.guittot@linaro.org> wrote:
>
> On Tue, 4 Mar 2025 at 02:56, Xuewen Yan <xuewen.yan94@gmail.com> wrote:
> >
> > Hi Peter
> >
> > On Mon, Mar 3, 2025 at 8:00 PM Peter Zijlstra <peterz@infradead.org> wrote:
> > >
> > > On Mon, Mar 03, 2025 at 06:52:38PM +0800, Xuewen Yan wrote:
> > > > Delayed dequeued feature keeps a sleeping sched_entitiy enqueued until its
> > > > lag has elapsed. As a result, it stays also visible in rq->nr_running.
> > > > However, sometimes when using nr-running, we should not consider
> > > > sched-delayed tasks.
> > > > This serie fixes those by adding a helper function which return the
> > > > number of sched-delayed tasks. And when we should get the real runnable
> > > > tasks, we sub the nr-delayed tasks.
> > > >
> > >
> > > Is there an actual performance improvement? Because when a runqueue
> > > looses competition, delayed tasks very quickly dissipate.
> >
> > At the moment, I don't have very detailed test data. I've been
> > studying delay-dequeue carefully recently, and these are the issues I
> > feel might need modification as I go through the code.
>
> Patch 1 makes sense for me but I'm less convinced by patch 2 and 3. As
> Peter also mentioned, the state where cpu_rq(cpu)->nr_running ==
> cfs_h_nr_delayed(cpu_rq(cpu)) is really transient as they will be
> picked as soon as the last runnable task will be dequeued
>

Thanks for the comments, based on your and Peter's explanation, it
seems that patch2 and patch3 might not have any significant impact at
the moment.
I will also test patch2 and patch3 later.
Thank you again!

BR

> >
> > Thanks!
> >
> > BR