All Virtuozzo development lists (kernel + QEMU)
 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 4/4] sched: switch a sleeping task group entity between idle and iowait
Date: Wed, 14 Oct 2026 11:16:27 +0000	[thread overview]
Message-ID: <20261014-ct-iowait-v1-4-9d65fe37cf89@virtuozzo.com> (raw)
In-Reply-To: <20261014-ct-iowait-v1-0-9d65fe37cf89@virtuozzo.com>

A sleeping group entity is accounted as blocked if its cfs_rq had
iowait sleepers when it was dequeued and as idle otherwise. But
nr_iowait can change while the group sleeps, e.g. when its iowait task
wakes up on another CPU, moves to another cgroup or changes its class.
The group then keeps accounting iowait on a CPU where nothing waits
for IO anymore.

Fix it like vz7 nr_iowait_{inc,dec}_fair() did: when nr_iowait changes,
close the current period of the sleeping group and start the other
kind. This needs an up to date rq clock, so update it in the migrating
wakeup path of try_to_wake_up(). The other callers already do it.

https://virtuozzo.atlassian.net/browse/VSTOR-147823
Signed-off-by: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>

Feature: sched: emulate virtual cpus for Containers
---
 kernel/sched/core.c |  1 +
 kernel/sched/fair.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 1acb98c0e8fa..77587e9982b7 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4376,6 +4376,7 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
 					struct rq *rq;
 
 					rq = __task_rq_lock(p, &rf);
+					update_rq_clock(rq);
 					p->sched_class->nr_iowait_dec(p);
 					__task_rq_unlock(rq, &rf);
 				}
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 2df5a9b47480..9f76caefc64a 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -13694,11 +13694,40 @@ static unsigned int get_rr_interval_fair(struct rq *rq, struct task_struct *task
 }
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
+/*
+ * A sleeping group entity is accounted as blocked while its cfs_rq has
+ * iowait sleepers and as idle otherwise. Switch it when nr_iowait changes
+ * without an enqueue, e.g. the iowait task wakes up on another CPU.
+ */
+static void nr_iowait_update_group(struct cfs_rq *cfs_rq,
+				   struct sched_entity *se)
+{
+	struct sched_statistics *stats;
+	struct rq *rq;
+
+	if (!schedstat_enabled() || !se)
+		return;
+
+	rq = rq_of(cfs_rq);
+	stats = __schedstats_from_se(se);
+	if (cfs_rq->nr_iowait ? !schedstat_val(stats->sleep_start) :
+				!schedstat_val(stats->block_start))
+		return;
+
+	__update_stats_enqueue_sleeper(rq, NULL, stats);
+
+	if (cfs_rq->nr_iowait)
+		__schedstat_set(stats->block_start, rq_clock(rq));
+	else
+		__schedstat_set(stats->sleep_start, rq_clock(rq));
+}
+
 static void nr_iowait_dec_fair(struct task_struct *p)
 {
 	struct cfs_rq *cfs_rq = task_cfs_rq(p);
 
 	cfs_rq->nr_iowait--;
+	nr_iowait_update_group(cfs_rq, p->se.parent);
 }
 
 static void nr_iowait_inc_fair(struct task_struct *p)
@@ -13706,6 +13735,7 @@ static void nr_iowait_inc_fair(struct task_struct *p)
 	struct cfs_rq *cfs_rq = task_cfs_rq(p);
 
 	cfs_rq->nr_iowait++;
+	nr_iowait_update_group(cfs_rq, p->se.parent);
 }
 #endif /* CONFIG_FAIR_GROUP_SCHED */
 

-- 
2.43.0

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

  parent reply	other threads:[~2026-10-14 11:18 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 ` [Devel] [PATCH hci-8.1 2/4] sched: keep cfs_rq::nr_iowait balanced for throttled and class changing tasks Vasileios Almpanis
2026-10-14 11:24   ` 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 ` Vasileios Almpanis [this message]
2026-10-14 11:27   ` [Devel] [PATCH hci-8.1 4/4] sched: switch a sleeping task group entity between idle and iowait 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-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.