public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Cruz Zhao <CruzZhao@linux.alibaba.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	bristot@redhat.com, vschneid@redhat.com, joel@joelfernandes.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 0/4] sched/core: fix cfs_prio_less
Date: Wed, 15 Nov 2023 19:33:37 +0800	[thread overview]
Message-ID: <20231115113341.13261-1-CruzZhao@linux.alibaba.com> (raw)

The update of vruntime snapshot will cause unfair sched, especially when
tasks enqueue/dequeue frequently.

Consider the following case: 
 - Task A1 and A2 share a cookie, and task B has another cookie.
 - A1 is a short task, waking up frequently but running short everytime.
 - A2 and B are long tasks.
 - A1 and B runs on ht0 and A2 runs on ht1.

ht0			ht1		fi_before	fi	update
switch to A1		switch to A2	0		0	1
A1 sleeps
switch to B		A2 force idle	0		1	1
A1 wakes up
switch to A1		switch to A1	1		0	1
A1 sleeps
switch to B		A2 force idle	0		1	1

In this case, cfs_rq->min_vruntime_fi will update every schedule, and
prio of B and A2 will be pulled to the same level, no matter how long A2
and B have run before, which is not fair enough. Extramely, we observed
that the latency of a task became several minutes due to this reason,
which should be 100ms.

To fix this problem, a possible approach is to maintain another vruntime
relative to the core, called core_vruntime, and we compare the priority
of ses using core_vruntime directly, instead of vruntime snapshot. To
achieve this goal, we need to introduce cfs_rq->core, similarity to
rq->core, and record core_min_vruntime in cfs_rq->core.

Cruz Zhao (4):
  sched/core: Introduce core_id
  sched: Introduce cfs_rq->core
  sched: introduce core_vruntime and core_min_vruntime
  fix vruntime snapshot

 include/linux/sched.h |  3 ++
 kernel/sched/core.c   | 37 +++++++---------
 kernel/sched/fair.c   | 98 ++++++++++++++++++++++++++-----------------
 kernel/sched/sched.h  |  5 ++-
 4 files changed, 81 insertions(+), 62 deletions(-)

-- 
2.39.3


             reply	other threads:[~2023-11-15 11:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-15 11:33 Cruz Zhao [this message]
2023-11-15 11:33 ` [PATCH 1/4] sched/core: introduce core_id to struct rq Cruz Zhao
2023-11-15 11:33 ` [PATCH 2/4] sched/core: introduce core to struct cfs_rq Cruz Zhao
2023-11-15 20:08   ` kernel test robot
2023-11-15 20:19   ` kernel test robot
2023-11-18 10:48   ` kernel test robot
2023-11-15 11:33 ` [PATCH 3/4] sched/fair: introduce core_vruntime and core_min_vruntime Cruz Zhao
2023-11-15 12:20   ` Peter Zijlstra
2023-11-15 13:42     ` cruzzhao
2023-11-15 15:22       ` Peter Zijlstra
2023-11-16  6:38         ` cruzzhao
2023-11-17  2:48         ` cruzzhao
2023-11-15 20:51   ` kernel test robot
2023-11-15 11:33 ` [PATCH 4/4] sched/core: fix cfs_prio_less Cruz Zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231115113341.13261-1-CruzZhao@linux.alibaba.com \
    --to=cruzzhao@linux.alibaba.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=joel@joelfernandes.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox