From: Kayra Cizmeci <kayracizmeci@gmail.com>
To: Christian Loehle <christian.loehle@arm.com>
Cc: Zhan Xusheng <zhanxusheng1024@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Zhan Xusheng <zhanxusheng@xiaomi.com>,
Ingo Molnar <mingo@redhat.com>,
Balbir Singh <bsingharora@gmail.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Valentin Schneider <vschneid@redhat.com>,
Josh Snyder <joshs@netflix.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCHv2] sched: Account I/O waits independently of delayed dequeue
Date: Thu, 15 Oct 2026 15:16:02 +0300 [thread overview]
Message-ID: <atC76vtYA12_jTar@lima-kdev.local> (raw)
In-Reply-To: <fd8578a1-e60b-4993-ab51-2b5d63abcf77@arm.com>
On Thu, Oct 15, 2026 at 12:37:54PM +0100, Christian Loehle wrote:
Normally I wouldn't add these. But I changed my setup. It adds
these itself. Not a big fan of changes but this is way more easier...
> ---
> include/linux/sched.h | 2 ++
> kernel/sched/core.c | 33 ++++++++++++++++++++-------------
> kernel/sched/sched.h | 5 -----
> 3 files changed, 22 insertions(+), 18 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index d35ae49a991f..d558816cc05a 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -880,6 +880,8 @@ struct task_struct {
> */
> int recent_used_cpu;
> int wake_cpu;
> + /* CPU charged while is_blocked && in_iowait. */
> + int iowait_cpu;
>
> int prio;
> int static_prio;
I wondered if the charge could follow the task while it changes CPUs,
but I think that it would break down more easily than this.
Still, there could be a better approach but right now, I can't find
any. Maybe there's a section that we could reuse? But IDK.
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 1fe40de6ebe3..85eba26f00d6 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -636,7 +636,7 @@ int task_llc(const struct task_struct *p)
> *
> * p->is_blocked <- { 0, 1 }:
> *
> - * is set by try_to_block_task() and cleared by ttwu_do_wakeup() and tracks
> + * is set by try_to_block_task() and cleared by unblock_task() and tracks
> * if the task is blocked. Traditionally this would mirror p->on_rq, however
> * due things like DELAY_DEQUEUE and PROXY_EXEC, this can diverge.
> *
> @@ -3737,12 +3737,22 @@ ttwu_stat(struct task_struct *p, int cpu, int wake_flags)
> __schedstat_inc(p->stats.nr_wakeups_sync);
> }
>
> +static inline void unblock_task(struct task_struct *p)
> +{
> + if (p->is_blocked && p->in_iowait) {
> + delayacct_blkio_end(p);
> + atomic_dec(&cpu_rq(p->iowait_cpu)->nr_iowait);
> + }
> +
> + p->is_blocked = 0;
> +}
> +
> /*
> * Mark the task runnable.
> */
> static inline void ttwu_do_wakeup(struct task_struct *p)
> {
> - p->is_blocked = 0;
> + unblock_task(p);
> WRITE_ONCE(p->__state, TASK_RUNNING);
> trace_sched_wakeup(p);
> }
> @@ -3839,10 +3849,6 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
> en_flags |= ENQUEUE_RQ_SELECTED;
> if (wake_flags & WF_MIGRATED)
> en_flags |= ENQUEUE_MIGRATED;
> - else if (p->in_iowait) {
> - delayacct_blkio_end(p);
> - atomic_dec(&task_rq(p)->nr_iowait);
> - }
>
> activate_task(rq, p, en_flags);
> wakeup_preempt(rq, p, wake_flags);
> @@ -4415,11 +4421,6 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
>
> cpu = select_task_rq(p, p->wake_cpu, &wake_flags);
> if (task_cpu(p) != cpu) {
> - if (p->in_iowait) {
> - delayacct_blkio_end(p);
> - atomic_dec(&task_rq(p)->nr_iowait);
> - }
> -
> wake_flags |= WF_MIGRATED;
> psi_ttwu_dequeue(p);
> set_task_cpu(p, cpu);
> @@ -6762,6 +6763,12 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p,
>
> p->is_blocked = 1;
>
> + if (p->in_iowait) {
> + p->iowait_cpu = cpu_of(rq);
> + atomic_inc(&rq->nr_iowait);
> + delayacct_blkio_start();
> + }
> +
So now we increase this nr_iowait on try_to_block_task(), and decrease it on unblock_task().
Also, there's a wrong comment about this in here:
/*
* This task is about to go to sleep on IO. Increment rq->nr_iowait so
* that process accounting knows that this is a task in IO wait state.
*/
long __sched io_schedule_timeout(long timeout)
{
int token;
long ret;
token = io_schedule_prepare();
ret = schedule_timeout(timeout);
io_schedule_finish(token);
return ret;
}
This doesn't even touch nr_iowait, so this is stale.
Maybe remove this comment or just correct this while in this?
Reviewed-by: Kayra Cizmeci <kayracizmeci@gmail.com>
prev parent reply other threads:[~2026-10-15 12:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 8:17 [PATCH] delayacct: Account blkio start on the correct task Zhan Xusheng
2026-10-14 15:20 ` Christian Loehle
2026-10-14 16:12 ` [PATCH] sched: Account blkio delay independently of delayed dequeue Christian Loehle
2026-10-14 16:55 ` Kayra Cizmeci
2026-10-15 2:59 ` Zhan Xusheng
2026-10-15 10:40 ` Christian Loehle
2026-10-15 11:37 ` [PATCHv2] sched: Account I/O waits " Christian Loehle
2026-10-15 12:02 ` Zhan Xusheng
2026-10-15 12:16 ` Kayra Cizmeci [this message]
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=atC76vtYA12_jTar@lima-kdev.local \
--to=kayracizmeci@gmail.com \
--cc=bsingharora@gmail.com \
--cc=christian.loehle@arm.com \
--cc=dietmar.eggemann@arm.com \
--cc=joshs@netflix.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=zhanxusheng1024@gmail.com \
--cc=zhanxusheng@xiaomi.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
all inboxes | Powered by JetHome®