OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>,
	Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 2/4] sched: keep cfs_rq::nr_iowait balanced for throttled and class changing tasks
Date: Wed, 14 Oct 2026 11:16:25 +0000	[thread overview]
Message-ID: <20261014-ct-iowait-v1-2-9d65fe37cf89@virtuozzo.com> (raw)
In-Reply-To: <20261014-ct-iowait-v1-0-9d65fe37cf89@virtuozzo.com>

Two more paths break the cfs_rq::nr_iowait pairing:

 - A throttled task can go to sleep in iowait before it returns to
   user space, e.g. in blkcg_maybe_throttle_current().
   dequeue_throttled_task() doesn't increment the counter but the
   wakeup decrements it, so it wraps around.
 - A sleeping iowait task can change its class through
   sched_setscheduler() or rt_mutex_setprio(). Fair to RT leaves the
   counter incremented forever, RT to fair decrements it without an
   increment.

A CT with both CPU and IO limits hits the first one.

Fix it by incrementing the counter in dequeue_throttled_task() and by
moving the task between the class counters in check_class_changed(),
like sched_move_task() does for a cgroup change.

https://virtuozzo.atlassian.net/browse/VSTOR-147823
Fixes: 415fe063c53e ("sched: Account cfs_rq::nr_iowait")
Signed-off-by: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>

Feature: sched: enhance task states granularity and accounting
---
 kernel/sched/core.c | 8 ++++++++
 kernel/sched/fair.c | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index dc016d264d19..1acb98c0e8fa 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2271,6 +2271,14 @@ void check_class_changed(struct rq *rq, struct task_struct *p,
 			 int oldprio)
 {
 	if (prev_class != p->sched_class) {
+		/* Move a sleeping iowait task to the new class accounting */
+		if (task_in_nr_iowait(p)) {
+			if (prev_class->nr_iowait_dec)
+				prev_class->nr_iowait_dec(p);
+			if (p->sched_class->nr_iowait_inc)
+				p->sched_class->nr_iowait_inc(p);
+		}
+
 		if (prev_class->switched_from)
 			prev_class->switched_from(rq, p);
 
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 5dd350a0e08b..df296edb828d 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5834,6 +5834,8 @@ static void dequeue_throttled_task(struct task_struct *p, int flags)
 	/* task blocked after throttled */
 	if (flags & DEQUEUE_SLEEP) {
 		p->throttled = false;
+		if (p->in_iowait)
+			task_cfs_rq(p)->nr_iowait++;
 		return;
 	}
 

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-10-14 11:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 11:16 [Devel] [PATCH hci-8.1 0/4] sched: restore Container iowait accounting Vasileios Almpanis
2026-10-14 11:16 ` [Devel] [PATCH hci-8.1 1/4] sched: fix cfs_rq::nr_iowait leak on the remote wakeup path Vasileios Almpanis
2026-10-14 11:23   ` no-reply
2026-10-14 11:16 ` Vasileios Almpanis [this message]
2026-10-14 11:24   ` [Devel] [PATCH hci-8.1 2/4] sched: keep cfs_rq::nr_iowait balanced for throttled and class changing tasks no-reply
2026-10-14 11:16 ` [Devel] [PATCH hci-8.1 3/4] sched: account sleep and block time of a task group entity Vasileios Almpanis
2026-10-14 11:28   ` no-reply
2026-10-14 11:36     ` Vasileios Almpanis
2026-10-14 11:16 ` [Devel] [PATCH hci-8.1 4/4] sched: switch a sleeping task group entity between idle and iowait Vasileios Almpanis
2026-10-14 11:27   ` no-reply

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=20261014-ct-iowait-v1-2-9d65fe37cf89@virtuozzo.com \
    --to=vasileios.almpanis@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=ptikhomirov@virtuozzo.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