Skip to contentSkip to conversation

io_uring: only account cqring wait time as iowait if enabled for a ring

PATCH In review David Wei 4 participants 20 messages Feb 24, 2024 – Mar 5, 2024

Subsystems (3)
lore
Share & tools
lore

David Wei

author
#0 lore raw

PATCH 1/4 io_uring: only account cqring wait time as iowait if enabled for a ring

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

This patch gates the previously unconditional iowait accounting behind a new IORING_REGISTER opcode. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

---
 include/linux/io_uring_types.h |  1 +
 include/uapi/linux/io_uring.h  |  3 +++
 io_uring/io_uring.c            |  9 +++++----
 io_uring/register.c            | 17 +++++++++++++++++
 4 files changed, 26 insertions(+), 4 deletions(-)
include/linux/io_uring_types.h +1 -0
index bd7071aeec5d..c568e6b8c9f9 100644
@@ -242,6 +242,7 @@ struct io_ring_ctx {
 		unsigned int		drain_disabled: 1;
 		unsigned int		compat: 1;
 		unsigned int		iowq_limits_set : 1;
+		unsigned int		iowait_enabled: 1;
 
 		struct task_struct	*submitter_task;
 		struct io_rings		*rings;
include/uapi/linux/io_uring.h +3 -0
index 7bd10201a02b..b068898c2283 100644
@@ -575,6 +575,9 @@ enum {
 	IORING_REGISTER_NAPI			= 27,
 	IORING_UNREGISTER_NAPI			= 28,
 
+	/* account time spent in cqring wait as iowait */
+	IORING_REGISTER_IOWAIT			= 29,
+
 	/* this goes last */
 	IORING_REGISTER_LAST,
 
io_uring/io_uring.c +5 -4
index cf2f514b7cc0..7f8d2a03cce6 100644
@@ -2533,12 +2533,13 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
 		return 0;
 
 	/*
-	 * Mark us as being in io_wait if we have pending requests, so cpufreq
-	 * can take into account that the task is waiting for IO - turns out
-	 * to be important for low QD IO.
+	 * Mark us as being in io_wait if we have pending requests if enabled
+	 * via IORING_REGISTER_IOWAIT, so cpufreq can take into account that
+	 * the task is waiting for IO - turns out to be important for low QD
+	 * IO.
 	 */
 	io_wait = current->in_iowait;
-	if (current_pending_io())
+	if (ctx->iowait_enabled && current_pending_io())
 		current->in_iowait = 1;
 	ret = 0;
 	if (iowq->timeout == KTIME_MAX)
io_uring/register.c +17 -0
index 99c37775f974..fbdf3d3461d8 100644
@@ -387,6 +387,17 @@ static __cold int io_register_iowq_max_workers(struct io_ring_ctx *ctx,
 	return ret;
 }
 
+static int io_register_iowait(struct io_ring_ctx *ctx, int val)
+{
+	int was_enabled = ctx->iowait_enabled;
+
+	if (val)
+		ctx->iowait_enabled = 1;
+	else
+		ctx->iowait_enabled = 0;
+	return was_enabled;
+}
+
 static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
 			       void __user *arg, unsigned nr_args)
 	__releases(ctx->uring_lock)
@@ -563,6 +574,12 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
 			break;
 		ret = io_unregister_napi(ctx, arg);
 		break;
+	case IORING_REGISTER_IOWAIT:
+		ret = -EINVAL;
+		if (arg)
+			break;
+		ret = io_register_iowait(ctx, nr_args);
+		break;
 	default:
 		ret = -EINVAL;
 		break;
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 2/4 liburing: add examples/proxy to .gitignore

From: David Wei <[email protected]>

Also re-ordered to be alphabetical.

---
 .gitignore | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
.gitignore +3 -2
index d355c59..f08cbe9 100644
@@ -21,10 +21,11 @@
 /examples/link-cp
 /examples/napi-busy-poll-client
 /examples/napi-busy-poll-server
-/examples/ucontext-cp
 /examples/poll-bench
-/examples/send-zerocopy
+/examples/proxy
 /examples/rsrc-update-bench
+/examples/send-zerocopy
+/examples/ucontext-cp
 
 /test/*.t
 /test/*.dmesg
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 3/4 liburing: add helper for IORING_REGISTER_IOWAIT

In reply to David Wei

From: David Wei <[email protected]>

Sync include/liburing/io_uring.h and add io_uring_register_iowait() helper function.

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

Add io_uring_register_iowait() which gates the previously unconditional iowait accounting. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

---
 src/include/liburing.h          | 2 ++
 src/include/liburing/io_uring.h | 3 +++
 src/register.c                  | 6 ++++++
 3 files changed, 11 insertions(+)
src/include/liburing.h +2 -0
index 6850fa7..5e39cc6 100644
@@ -241,6 +241,8 @@ int io_uring_register_file_alloc_range(struct io_uring *ring,
 int io_uring_register_napi(struct io_uring *ring, struct io_uring_napi *napi);
 int io_uring_unregister_napi(struct io_uring *ring, struct io_uring_napi *napi);
 
+int io_uring_register_iowait(struct io_uring *ring, int enabled);
+
 int io_uring_get_events(struct io_uring *ring);
 int io_uring_submit_and_get_events(struct io_uring *ring);
 
src/include/liburing/io_uring.h +3 -0
index bde1199..ba94955 100644
@@ -570,6 +570,9 @@ enum {
 	IORING_REGISTER_NAPI			= 27,
 	IORING_UNREGISTER_NAPI			= 28,
 
+	/* account time spent in cqring wait as iowait */
+	IORING_REGISTER_IOWAIT			= 29,
+
 	/* this goes last */
 	IORING_REGISTER_LAST,
 
src/register.c +6 -0
index f9bc52b..7f2890e 100644
@@ -368,3 +368,9 @@ int io_uring_unregister_napi(struct io_uring *ring, struct io_uring_napi *napi)
 	return __sys_io_uring_register(ring->ring_fd,
 				IORING_UNREGISTER_NAPI, napi, 1);
 }
+
+int io_uring_register_iowait(struct io_uring *ring, int enabled)
+{
+	return __sys_io_uring_register(ring->ring_fd,
+				IORING_REGISTER_IOWAIT, NULL, enabled);
+}
Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH v1 3/4] liburing: add helper for IORING_REGISTER_IOWAIT

Quoted 14 lines · David Wei

From: David Wei <[email protected]>

Sync include/liburing/io_uring.h and add io_uring_register_iowait() helper function.

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

Quoted 5 lines

Add io_uring_register_iowait() which gates the previously unconditional iowait accounting. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

This looks fine, would you be up for writing the man page? If not. I can do it.

Signature · 1 line
Jens Axboe
author
#4 lore raw

Re: [PATCH v1 3/4] liburing: add helper for IORING_REGISTER_IOWAIT

Quoted 15 lines · Jens Axboe
Quoted 14 lines · David Wei

From: David Wei <[email protected]>

Sync include/liburing/io_uring.h and add io_uring_register_iowait() helper function.

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

Quoted 8 lines
Quoted 5 lines

Add io_uring_register_iowait() which gates the previously unconditional iowait accounting. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

This looks fine, would you be up for writing the man page? If not. I can do it.

Oh shoot I totally forgot about that. Yeah, I'll write one up.

author
#5 lore raw

PATCH 4/4 liburing: add unit test for io_uring_register_iowait()

In reply to David Wei

From: David Wei <[email protected]>

Add a unit test for io_uring_register_iowait() by creating a thread that writes into a pipe after a delay, checking iowait before and after.

---
 test/Makefile |   1 +
 test/iowait.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 158 insertions(+)
 create mode 100644 test/iowait.c
test/Makefile +1 -0
index b09228f..779a7db 100644
@@ -107,6 +107,7 @@ test_srcs := \
 	io_uring_passthrough.c \
 	io_uring_register.c \
 	io_uring_setup.c \
+	iowait.c \
 	lfs-openat.c \
 	lfs-openat-write.c \
 	link.c \
test/iowait.c new file +157 -0

157 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#6 lore raw
In reply to David Wei
Quoted 9 lines · David Wei

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

Quoted 5 lines

This patch gates the previously unconditional iowait accounting behind a new IORING_REGISTER opcode. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

Looks good, thanks!

Signature · 1 line
Jens Axboe
#7 lore raw
In reply to David Wei
Quoted 9 lines · David Wei

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

Quoted 5 lines

This patch gates the previously unconditional iowait accounting behind a new IORING_REGISTER opcode. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

I don't believe it's a sane approach. I think we agree that per cpu iowait is a silly and misleading metric. I have hard time to define what it is, and I'm sure most probably people complaining wouldn't be able to tell as well. Now we're taking that metric and expose even more knobs to userspace.

Another argument against is that per ctx is not the right place to have it. It's a system metric, and you can imagine some system admin looking for it. Even in cases when had some meaning w/o io_uring now without looking at what flags io_uring has it's completely meaningless, and it's too much to ask.

I don't understand why people freak out at seeing hi iowait, IMHO it perfectly fits the definition of io_uring waiting for IO / completions, but at this point it might be better to just revert it to the old behaviour of not reporting iowait at all. And if we want to save the cpu freq iowait optimisation, we should just split notion of iowait reporting and iowait cpufreq tuning.

Quoted 91 lines
---
  include/linux/io_uring_types.h |  1 +
  include/uapi/linux/io_uring.h  |  3 +++
  io_uring/io_uring.c            |  9 +++++----
  io_uring/register.c            | 17 +++++++++++++++++
  4 files changed, 26 insertions(+), 4 deletions(-)
include/linux/io_uring_types.h +1 -0
index bd7071aeec5d..c568e6b8c9f9 100644
@@ -242,6 +242,7 @@ struct io_ring_ctx {
  		unsigned int		drain_disabled: 1;
  		unsigned int		compat: 1;
  		unsigned int		iowq_limits_set : 1;
+		unsigned int		iowait_enabled: 1;
 
  		struct task_struct	*submitter_task;
  		struct io_rings		*rings;
include/uapi/linux/io_uring.h +3 -0
index 7bd10201a02b..b068898c2283 100644
@@ -575,6 +575,9 @@ enum {
  	IORING_REGISTER_NAPI			= 27,
  	IORING_UNREGISTER_NAPI			= 28,
 
+	/* account time spent in cqring wait as iowait */
+	IORING_REGISTER_IOWAIT			= 29,
+
  	/* this goes last */
  	IORING_REGISTER_LAST,
 
io_uring/io_uring.c +5 -4
index cf2f514b7cc0..7f8d2a03cce6 100644
@@ -2533,12 +2533,13 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
  		return 0;
 
  	/*
-	 * Mark us as being in io_wait if we have pending requests, so cpufreq
-	 * can take into account that the task is waiting for IO - turns out
-	 * to be important for low QD IO.
+	 * Mark us as being in io_wait if we have pending requests if enabled
+	 * via IORING_REGISTER_IOWAIT, so cpufreq can take into account that
+	 * the task is waiting for IO - turns out to be important for low QD
+	 * IO.
  	 */
  	io_wait = current->in_iowait;
-	if (current_pending_io())
+	if (ctx->iowait_enabled && current_pending_io())
  		current->in_iowait = 1;
  	ret = 0;
  	if (iowq->timeout == KTIME_MAX)
io_uring/register.c +17 -0
index 99c37775f974..fbdf3d3461d8 100644
@@ -387,6 +387,17 @@ static __cold int io_register_iowq_max_workers(struct io_ring_ctx *ctx,
  	return ret;
  }
 
+static int io_register_iowait(struct io_ring_ctx *ctx, int val)
+{
+	int was_enabled = ctx->iowait_enabled;
+
+	if (val)
+		ctx->iowait_enabled = 1;
+	else
+		ctx->iowait_enabled = 0;
+	return was_enabled;
+}
+
  static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
  			       void __user *arg, unsigned nr_args)
  	__releases(ctx->uring_lock)
@@ -563,6 +574,12 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
  			break;
  		ret = io_unregister_napi(ctx, arg);
  		break;
+	case IORING_REGISTER_IOWAIT:
+		ret = -EINVAL;
+		if (arg)
+			break;
+		ret = io_register_iowait(ctx, nr_args);
+		break;
  	default:
  		ret = -EINVAL;
  		break;
Signature · 1 line
Pavel Begunkov
author
#8 lore raw
Quoted 22 lines · Pavel Begunkov
Quoted 9 lines · David Wei

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

Quoted 5 lines

This patch gates the previously unconditional iowait accounting behind a new IORING_REGISTER opcode. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

I don't believe it's a sane approach. I think we agree that per cpu iowait is a silly and misleading metric. I have hard time to define what it is, and I'm sure most probably people complaining wouldn't be able to tell as well. Now we're taking that metric and expose even more knobs to userspace.

Quoted 9 lines

Another argument against is that per ctx is not the right place to have it. It's a system metric, and you can imagine some system admin looking for it. Even in cases when had some meaning w/o io_uring now without looking at what flags io_uring has it's completely meaningless, and it's too much to ask.>
I don't understand why people freak out at seeing hi iowait, IMHO it perfectly fits the definition of io_uring waiting for IO / completions, but at this point it might be better to just revert it to the old behaviour of not reporting iowait at all.

Irrespective of how misleading iowait is, many tools include it in its CPU util/load calculations and users then use those metrics for e.g. load balancing. In situations with storage workloads, iowait can be useful even if its usefulness is limited. The problem that this patch is trying to resolve is in mixed storage/network workloads on the same system, where iowait has some usefulness (due to storage workloads) _but_ I don't want network workloads contributing to the metric.

This does put the onus on userspace to do the right thing - decide whether iowait makes sense for a workload or not. I don't have enough kernel experience to know whether this expectation is realistic or not. But, it is turned off by default so if userspace does not set it (which seems like the most likely thing) then iowait accounting is off just like the old behaviour. Perhaps we need to make it clearer to storage use-cases to turn it on in order to get the optimisation?

Quoted 3 lines

And if we want to save the cpu freq iowait optimisation, we should just split notion of iowait reporting and iowait cpufreq tuning.

Yeah, that could be an option. I'll take a look at it.

Quoted 89 lines
Quoted 88 lines
---
  include/linux/io_uring_types.h |  1 +
  include/uapi/linux/io_uring.h  |  3 +++
  io_uring/io_uring.c            |  9 +++++----
  io_uring/register.c            | 17 +++++++++++++++++
  4 files changed, 26 insertions(+), 4 deletions(-)
include/linux/io_uring_types.h +1 -0
index bd7071aeec5d..c568e6b8c9f9 100644
@@ -242,6 +242,7 @@ struct io_ring_ctx {
          unsigned int        drain_disabled: 1;
          unsigned int        compat: 1;
          unsigned int        iowq_limits_set : 1;
+        unsigned int        iowait_enabled: 1;
            struct task_struct    *submitter_task;
          struct io_rings        *rings;
include/uapi/linux/io_uring.h +2 -0
index 7bd10201a02b..b068898c2283 100644
@@ -575,6 +575,9 @@ enum {
      IORING_REGISTER_NAPI            = 27,
      IORING_UNREGISTER_NAPI            = 28,
  +    /* account time spent in cqring wait as iowait */
+    IORING_REGISTER_IOWAIT            = 29,
+
      /* this goes last */
      IORING_REGISTER_LAST,
  diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c

index cf2f514b7cc0..7f8d2a03cce6 100644

io_uring/io_uring.c +5 -4
@@ -2533,12 +2533,13 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
          return 0;
        /*
-     * Mark us as being in io_wait if we have pending requests, so cpufreq
-     * can take into account that the task is waiting for IO - turns out
-     * to be important for low QD IO.
+     * Mark us as being in io_wait if we have pending requests if enabled
+     * via IORING_REGISTER_IOWAIT, so cpufreq can take into account that
+     * the task is waiting for IO - turns out to be important for low QD
+     * IO.
       */
      io_wait = current->in_iowait;
-    if (current_pending_io())
+    if (ctx->iowait_enabled && current_pending_io())
          current->in_iowait = 1;
      ret = 0;
      if (iowq->timeout == KTIME_MAX)
io_uring/register.c +16 -0
index 99c37775f974..fbdf3d3461d8 100644
@@ -387,6 +387,17 @@ static __cold int io_register_iowq_max_workers(struct io_ring_ctx *ctx,
      return ret;
  }
  +static int io_register_iowait(struct io_ring_ctx *ctx, int val)
+{
+    int was_enabled = ctx->iowait_enabled;
+
+    if (val)
+        ctx->iowait_enabled = 1;
+    else
+        ctx->iowait_enabled = 0;
+    return was_enabled;
+}
+
  static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
                     void __user *arg, unsigned nr_args)
      __releases(ctx->uring_lock)
@@ -563,6 +574,12 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
              break;
          ret = io_unregister_napi(ctx, arg);
          break;
+    case IORING_REGISTER_IOWAIT:
+        ret = -EINVAL;
+        if (arg)
+            break;
+        ret = io_register_iowait(ctx, nr_args);
+        break;
      default:
          ret = -EINVAL;
          break;
maintainer
#9 lore raw
Quoted 24 lines · David Wei
Quoted 6 lines

I don't believe it's a sane approach. I think we agree that per cpu iowait is a silly and misleading metric. I have hard time to define what it is, and I'm sure most probably people complaining wouldn't be able to tell as well. Now we're taking that metric and expose even more knobs to userspace.

Quoted 9 lines

Another argument against is that per ctx is not the right place to have it. It's a system metric, and you can imagine some system admin looking for it. Even in cases when had some meaning w/o io_uring now without looking at what flags io_uring has it's completely meaningless, and it's too much to ask.>
I don't understand why people freak out at seeing hi iowait, IMHO it perfectly fits the definition of io_uring waiting for IO / completions, but at this point it might be better to just revert it to the old behaviour of not reporting iowait at all.

Irrespective of how misleading iowait is, many tools include it in its CPU util/load calculations and users then use those metrics for e.g. load balancing. In situations with storage workloads, iowait can be useful even if its usefulness is limited. The problem that this patch is trying to resolve is in mixed storage/network workloads on the same system, where iowait has some usefulness (due to storage workloads) _but_ I don't want network workloads contributing to the metric.

Quoted 7 lines

This does put the onus on userspace to do the right thing - decide whether iowait makes sense for a workload or not. I don't have enough kernel experience to know whether this expectation is realistic or not. But, it is turned off by default so if userspace does not set it (which seems like the most likely thing) then iowait accounting is off just like the old behaviour. Perhaps we need to make it clearer to storage use-cases to turn it on in order to get the optimisation?

Personally I don't care too much about per-ctx iowait, I don't think it's an issue at all. Fact is, most workloads that do storage and networking would likely use a ring for each. And if they do mix, then just pick if you care about iowait or not. Long term, would the toggle iowait thing most likely just go away? Yep it would. But it's not like it's any kind of maintenance burden. tldr - if we can do cpufreq boosting easily on waits without adding iowait to the mix, then that'd be great and we can just do that. If not, let's add the iowait toggle and just be done with it.

Quoted 5 lines
Quoted 3 lines

And if we want to save the cpu freq iowait optimisation, we should just split notion of iowait reporting and iowait cpufreq tuning.

Yeah, that could be an option. I'll take a look at it.

It'd be trivial to do, only issue I see is that it'd require another set of per-runqueue atomics to count for short waits on top of the nr_iowaits we already do. I doubt the scheduling side will be receptive to that.

Signature · 1 line
Jens Axboe
#10 lore raw
Quoted 33 lines · Jens Axboe
Quoted 24 lines · David Wei
Quoted 6 lines

I don't believe it's a sane approach. I think we agree that per cpu iowait is a silly and misleading metric. I have hard time to define what it is, and I'm sure most probably people complaining wouldn't be able to tell as well. Now we're taking that metric and expose even more knobs to userspace.

Quoted 9 lines

Another argument against is that per ctx is not the right place to have it. It's a system metric, and you can imagine some system admin looking for it. Even in cases when had some meaning w/o io_uring now without looking at what flags io_uring has it's completely meaningless, and it's too much to ask.>
I don't understand why people freak out at seeing hi iowait, IMHO it perfectly fits the definition of io_uring waiting for IO / completions, but at this point it might be better to just revert it to the old behaviour of not reporting iowait at all.

Irrespective of how misleading iowait is, many tools include it in its CPU util/load calculations and users then use those metrics for e.g. load balancing. In situations with storage workloads, iowait can be useful even if its usefulness is limited. The problem that this patch is trying to resolve is in mixed storage/network workloads on the same system, where iowait has some usefulness (due to storage workloads) _but_ I don't want network workloads contributing to the metric.

Quoted 7 lines

This does put the onus on userspace to do the right thing - decide whether iowait makes sense for a workload or not. I don't have enough kernel experience to know whether this expectation is realistic or not. But, it is turned off by default so if userspace does not set it (which seems like the most likely thing) then iowait accounting is off just like the old behaviour. Perhaps we need to make it clearer to storage use-cases to turn it on in order to get the optimisation?

Quoted 4 lines

Personally I don't care too much about per-ctx iowait, I don't think it's an issue at all. Fact is, most workloads that do storage and networking would likely use a ring for each. And if they do mix, then just pick if you care about iowait or not. Long term, would the toggle

Let's say you want the optimisation, but don't want to screw up system iowait stats because as we've seen there will be people complaining. What do you do? 99% of frameworks and libraries would never enable it, which is a shame. If it's some container hosting, the vendors might start complaining, especially since it's inconsistent and depends on the user, then we might need to blacklist it globally. Then the cases when you control the entire stack, you need to tell people from other teams and PEs that it's how it is.

Quoted 1 line

iowait thing most likely just go away? Yep it would. But it's not like

I predict that with enough time if you'd try to root it out there will be someone complaining that iowait is unexpectedly 0, it's a regression please return the flag back. I doubt it would just go away, but probably depends on the timeline.

Quoted 1 line

it's any kind of maintenance burden. tldr - if we can do cpufreq

ala death from thousand useless apis nobody cares about nor truly understands.

Quoted 8 lines

boosting easily on waits without adding iowait to the mix, then that'd be great and we can just do that. If not, let's add the iowait toggle and just be done with it.

Quoted 4 lines
Quoted 3 lines

And if we want to save the cpu freq iowait optimisation, we should just split notion of iowait reporting and iowait cpufreq tuning.

Quoted 6 lines
Quoted 1 line

Yeah, that could be an option. I'll take a look at it.

It'd be trivial to do, only issue I see is that it'd require another set of per-runqueue atomics to count for short waits on top of the nr_iowaits we already do. I doubt the scheduling side will be receptive to that.

Looked it up, sounds unfortunate, but also seems like the status quo can be optimised with an additional cpu local var.

Signature · 1 line
Pavel Begunkov
maintainer
#11 lore raw
Quoted 39 lines · Pavel Begunkov
Quoted 33 lines · Jens Axboe
Quoted 24 lines · David Wei
Quoted 6 lines

I don't believe it's a sane approach. I think we agree that per cpu iowait is a silly and misleading metric. I have hard time to define what it is, and I'm sure most probably people complaining wouldn't be able to tell as well. Now we're taking that metric and expose even more knobs to userspace.

Quoted 9 lines

Another argument against is that per ctx is not the right place to have it. It's a system metric, and you can imagine some system admin looking for it. Even in cases when had some meaning w/o io_uring now without looking at what flags io_uring has it's completely meaningless, and it's too much to ask.>
I don't understand why people freak out at seeing hi iowait, IMHO it perfectly fits the definition of io_uring waiting for IO / completions, but at this point it might be better to just revert it to the old behaviour of not reporting iowait at all.

Irrespective of how misleading iowait is, many tools include it in its CPU util/load calculations and users then use those metrics for e.g. load balancing. In situations with storage workloads, iowait can be useful even if its usefulness is limited. The problem that this patch is trying to resolve is in mixed storage/network workloads on the same system, where iowait has some usefulness (due to storage workloads) _but_ I don't want network workloads contributing to the metric.

Quoted 7 lines

This does put the onus on userspace to do the right thing - decide whether iowait makes sense for a workload or not. I don't have enough kernel experience to know whether this expectation is realistic or not. But, it is turned off by default so if userspace does not set it (which seems like the most likely thing) then iowait accounting is off just like the old behaviour. Perhaps we need to make it clearer to storage use-cases to turn it on in order to get the optimisation?

Quoted 4 lines

Personally I don't care too much about per-ctx iowait, I don't think it's an issue at all. Fact is, most workloads that do storage and networking would likely use a ring for each. And if they do mix, then just pick if you care about iowait or not. Long term, would the toggle

Quoted 8 lines

Let's say you want the optimisation, but don't want to screw up system iowait stats because as we've seen there will be people complaining. What do you do? 99% of frameworks and libraries would never enable it, which is a shame. If it's some container hosting, the vendors might start complaining, especially since it's inconsistent and depends on the user, then we might need to blacklist it globally. Then the cases when you control the entire stack, you need to tell people from other teams and PEs that it's how it is.

I suspect the best way would be to leave it as-is, eg iowait is on by default. That way if people start noticing they will look around, find the knob, an tweak it. For a pure storage kind of workload, people are used to iowait and they will probably think nothing of it. For a pure networking workload, people might find it odd and that'll trigger the incentive to start searching for it and then they will pretty quickly figure out how to turn it off.

Quoted 6 lines
Quoted 1 line

iowait thing most likely just go away? Yep it would. But it's not like

I predict that with enough time if you'd try to root it out there will be someone complaining that iowait is unexpectedly 0, it's a regression please return the flag back. I doubt it would just go away, but probably depends on the timeline.

Right, so just keep it as-is by default.

Quoted 4 lines
Quoted 1 line

it's any kind of maintenance burden. tldr - if we can do cpufreq

ala death from thousand useless apis nobody cares about nor truly understands.

Let's be real, some toggle function isn't really going to cause any maintenance burden going forward. It's not like it's a complicated API. If it rots in a corner years from now, which I hope it will, it won't really add any burden on maintainers. It'll most likely never get touched again once it has landed.

Quoted 10 lines
Quoted 10 lines

boosting easily on waits without adding iowait to the mix, then that'd be great and we can just do that. If not, let's add the iowait toggle and just be done with it.

Quoted 5 lines
Quoted 3 lines

And if we want to save the cpu freq iowait optimisation, we should just split notion of iowait reporting and iowait cpufreq tuning.

Yeah, that could be an option. I'll take a look at it.

Quoted 8 lines
Quoted 4 lines

It'd be trivial to do, only issue I see is that it'd require another set of per-runqueue atomics to count for short waits on top of the nr_iowaits we already do. I doubt the scheduling side will be receptive to that.

Looked it up, sounds unfortunate, but also seems like the status quo can be optimised with an additional cpu local var.

If you are motivated, please dig into it. If not, I guess I will take a look this week.

Signature · 1 line
Jens Axboe
maintainer
#12 lore raw
Quoted 2 lines · Jens Axboe

If you are motivated, please dig into it. If not, I guess I will take a look this week.

The straight forward approach - add a nr_short_wait and ->in_short_wait and ensure that the idle governor factors that in. Not sure how palatable it is, would be nice fold iowait under this, but doesn't really work with how we pass back the previous state.

drivers/cpuidle/governors/menu.c +9 -9
index b96e3da0fedd..39f05d6062e1 100644
@@ -119,7 +119,7 @@ struct menu_device {
 	int		interval_ptr;
 };
 
-static inline int which_bucket(u64 duration_ns, unsigned int nr_iowaiters)
+static inline int which_bucket(u64 duration_ns, unsigned int nr_short_waiters)
 {
 	int bucket = 0;
 
@@ -129,7 +129,7 @@ static inline int which_bucket(u64 duration_ns, unsigned int nr_iowaiters)
 	 * This allows us to calculate
 	 * E(duration)|iowait
 	 */
-	if (nr_iowaiters)
+	if (nr_short_waiters)
 		bucket = BUCKETS/2;
 
 	if (duration_ns < 10ULL * NSEC_PER_USEC)
@@ -152,10 +152,10 @@ static inline int which_bucket(u64 duration_ns, unsigned int nr_iowaiters)
  * to be, the higher this multiplier, and thus the higher
  * the barrier to go to an expensive C state.
  */
-static inline int performance_multiplier(unsigned int nr_iowaiters)
+static inline int performance_multiplier(unsigned int nr_short_waiters)
 {
 	/* for IO wait tasks (per cpu!) we add 10x each */
-	return 1 + 10 * nr_iowaiters;
+	return 1 + 10 * nr_short_waiters;
 }
 
 static DEFINE_PER_CPU(struct menu_device, menu_devices);
@@ -266,7 +266,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 	s64 latency_req = cpuidle_governor_latency_req(dev->cpu);
 	u64 predicted_ns;
 	u64 interactivity_req;
-	unsigned int nr_iowaiters;
+	unsigned int nr_short_waiters;
 	ktime_t delta, delta_tick;
 	int i, idx;
 
@@ -275,7 +275,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 		data->needs_update = 0;
 	}
 
-	nr_iowaiters = nr_iowait_cpu(dev->cpu);
+	nr_short_waiters = nr_iowait_cpu(dev->cpu) + nr_short_wait_cpu(dev->cpu);
 
 	/* Find the shortest expected idle interval. */
 	predicted_ns = get_typical_interval(data) * NSEC_PER_USEC;
@@ -290,7 +290,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 		}
 
 		data->next_timer_ns = delta;
-		data->bucket = which_bucket(data->next_timer_ns, nr_iowaiters);
+		data->bucket = which_bucket(data->next_timer_ns, nr_short_waiters);
 
 		/* Round up the result for half microseconds. */
 		timer_us = div_u64((RESOLUTION * DECAY * NSEC_PER_USEC) / 2 +
@@ -308,7 +308,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 		 */
 		data->next_timer_ns = KTIME_MAX;
 		delta_tick = TICK_NSEC / 2;
-		data->bucket = which_bucket(KTIME_MAX, nr_iowaiters);
+		data->bucket = which_bucket(KTIME_MAX, nr_short_waiters);
 	}
 
 	if (unlikely(drv->state_count <= 1 || latency_req == 0) ||
@@ -341,7 +341,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 		 * latency_req to determine the maximum exit latency.
 		 */
 		interactivity_req = div64_u64(predicted_ns,
-					      performance_multiplier(nr_iowaiters));
+					      performance_multiplier(nr_short_waiters));
 		if (latency_req > interactivity_req)
 			latency_req = interactivity_req;
 	}
include/linux/sched.h +1 -0
index ffe8f618ab86..b04c08cadf1f 100644
@@ -923,6 +923,7 @@ struct task_struct {
 	/* Bit to tell TOMOYO we're in execve(): */
 	unsigned			in_execve:1;
 	unsigned			in_iowait:1;
+	unsigned			in_short_wait:1;
 #ifndef TIF_RESTORE_SIGMASK
 	unsigned			restore_sigmask:1;
 #endif
include/linux/sched/stat.h +1 -0
index 0108a38bb64d..12f5795c4c32 100644
@@ -21,6 +21,7 @@ extern unsigned int nr_running(void);
 extern bool single_task_running(void);
 extern unsigned int nr_iowait(void);
 extern unsigned int nr_iowait_cpu(int cpu);
+unsigned int nr_short_wait_cpu(int cpu);
 
 static inline int sched_info_on(void)
 {
io_uring/io_uring.c +4 -4
index f6332fc56bed..024af44ead12 100644
@@ -2519,7 +2519,7 @@ static bool current_pending_io(void)
 static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
 					  struct io_wait_queue *iowq)
 {
-	int io_wait, ret;
+	int short_wait, ret;
 
 	if (unlikely(READ_ONCE(ctx->check_cq)))
 		return 1;
@@ -2537,15 +2537,15 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
 	 * can take into account that the task is waiting for IO - turns out
 	 * to be important for low QD IO.
 	 */
-	io_wait = current->in_iowait;
+	short_wait = current->in_short_wait;
 	if (current_pending_io())
-		current->in_iowait = 1;
+		current->in_short_wait = 1;
 	ret = 0;
 	if (iowq->timeout == KTIME_MAX)
 		schedule();
 	else if (!schedule_hrtimeout(&iowq->timeout, HRTIMER_MODE_ABS))
 		ret = -ETIME;
-	current->in_iowait = io_wait;
+	current->in_short_wait = short_wait;
 	return ret;
 }
 
kernel/sched/core.c +12 -0
index 9116bcc90346..dc7a08db8921 100644
@@ -3790,6 +3790,8 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
 	if (p->in_iowait) {
 		delayacct_blkio_end(p);
 		atomic_dec(&task_rq(p)->nr_iowait);
+	} else if (p->in_short_wait) {
+		atomic_dec(&task_rq(p)->nr_short_wait);
 	}
 
 	activate_task(rq, p, en_flags);
@@ -4356,6 +4358,8 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
 			if (p->in_iowait) {
 				delayacct_blkio_end(p);
 				atomic_dec(&task_rq(p)->nr_iowait);
+			} else if (p->in_short_wait) {
+				atomic_dec(&task_rq(p)->nr_short_wait);
 			}
 
 			wake_flags |= WF_MIGRATED;
@@ -5506,6 +5510,11 @@ unsigned int nr_iowait(void)
 	return sum;
 }
 
+unsigned int nr_short_wait_cpu(int cpu)
+{
+	return atomic_read(&cpu_rq(cpu)->nr_short_wait);
+}
+
 #ifdef CONFIG_SMP
 
 /*
@@ -6683,6 +6692,8 @@ static void __sched notrace __schedule(unsigned int sched_mode)
 			if (prev->in_iowait) {
 				atomic_inc(&rq->nr_iowait);
 				delayacct_blkio_start();
+			} else if (prev->in_short_wait) {
+				atomic_inc(&rq->nr_short_wait);
 			}
 		}
 		switch_count = &prev->nvcsw;
@@ -10030,6 +10041,7 @@ void __init sched_init(void)
 #endif /* CONFIG_SMP */
 		hrtick_rq_init(rq);
 		atomic_set(&rq->nr_iowait, 0);
+		atomic_set(&rq->nr_short_wait, 0);
 
 #ifdef CONFIG_SCHED_CORE
 		rq->core = rq;
kernel/sched/fair.c +1 -1
index 533547e3c90a..9d4fc0b9de26 100644
@@ -6721,7 +6721,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 	 * utilization updates, so do it here explicitly with the IOWAIT flag
 	 * passed.
 	 */
-	if (p->in_iowait)
+	if (p->in_iowait || p->in_short_wait)
 		cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT);
 
 	for_each_sched_entity(se) {
kernel/sched/sched.h +1 -0
index 001fe047bd5d..0530e9e97ecb 100644
@@ -1050,6 +1050,7 @@ struct rq {
 #endif
 
 	atomic_t		nr_iowait;
+	atomic_t		nr_short_wait;
 
 #ifdef CONFIG_SCHED_DEBUG
 	u64 last_seen_need_resched_ns;
Signature · 1 line
Jens Axboe
maintainer
#13 lore raw
Quoted 8 lines · Jens Axboe
Quoted 2 lines · Jens Axboe

If you are motivated, please dig into it. If not, I guess I will take a look this week.

The straight forward approach - add a nr_short_wait and ->in_short_wait and ensure that the idle governor factors that in. Not sure how palatable it is, would be nice fold iowait under this, but doesn't really work with how we pass back the previous state.

Split into 3 separate patches here. No changes from the previous email. Tested it, and it works.

https://git.kernel.dk/cgit/linux/log/?h=iowait

Signature · 1 line
Jens Axboe
#14 lore raw
In reply to Jens Axboe
Quoted 3 lines · Jens Axboe
Quoted 2 lines · Jens Axboe

If you are motivated, please dig into it. If not, I guess I will take a look this week.

I tried to split the atomic as mentioned, but I don't think anybody cares, it was 0.1% in perf, so wouldn't even be benchmarkeable, and it's iowait only patch anyway. If anything you'd need to read two vars every tick now, so nevermind

Quoted 4 lines

The straight forward approach - add a nr_short_wait and ->in_short_wait and ensure that the idle governor factors that in. Not sure how palatable it is, would be nice fold iowait under this, but doesn't really work with how we pass back the previous state.

It might look nicer if instead adding nr_short_waiters you'd do nr_iowait_account for the iowait% and leave nr_iowait for cpufreq.

The block iowaiting / io_schedule / etc. would need to set both flags...

Quoted 14 lines
kernel/sched/core.c +2 -0
index 9116bcc90346..dc7a08db8921 100644
@@ -3790,6 +3790,8 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
  	if (p->in_iowait) {
  		delayacct_blkio_end(p);
  		atomic_dec(&task_rq(p)->nr_iowait);
+	} else if (p->in_short_wait) {
+		atomic_dec(&task_rq(p)->nr_short_wait);
  	}
 
  	activate_task(rq, p, en_flags);

kernel/sched/core.c int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) · line 4362

Quoted 5 lines
kernel/sched/core.c +2 -0
@@ -4356,6 +4358,8 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
  			if (p->in_iowait) {
  				delayacct_blkio_end(p);
  				atomic_dec(&task_rq(p)->nr_iowait);
+			} else if (p->in_short_wait) {
+				atomic_dec(&task_rq(p)->nr_short_wait);

... which would get this branch folded into the previous one, which should be more welcome by the sched guys.

Signature · 1 line
Pavel Begunkov
maintainer
#15 lore raw
Quoted 9 lines · Pavel Begunkov
Quoted 3 lines · Jens Axboe
Quoted 2 lines · Jens Axboe

If you are motivated, please dig into it. If not, I guess I will take a look this week.

I tried to split the atomic as mentioned, but I don't think anybody cares, it was 0.1% in perf, so wouldn't even be benchmarkeable, and it's iowait only patch anyway. If anything you'd need to read two vars every tick now, so nevermind

Agree, I did ponder that too, but seems not worth it at all.

Quoted 11 lines
Quoted 4 lines

The straight forward approach - add a nr_short_wait and ->in_short_wait and ensure that the idle governor factors that in. Not sure how palatable it is, would be nice fold iowait under this, but doesn't really work with how we pass back the previous state.

It might look nicer if instead adding nr_short_waiters you'd do nr_iowait_account for the iowait% and leave nr_iowait for cpufreq.

The block iowaiting / io_schedule / etc. would need to set both flags...

That's what I meant with the nesting too, but then we need to return flags from eg io_schedule_prepare(). Not a big issue as I think that's the only spot, and we can even just keep the type the same. Callers should treat it as a cookie/token anyway.

I'll make that change.

Signature · 1 line
Jens Axboe
maintainer
#16 lore raw
In reply to Pavel Begunkov
Quoted 16 lines · Pavel Begunkov
Quoted 9 lines · David Wei

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

Quoted 5 lines

This patch gates the previously unconditional iowait accounting behind a new IORING_REGISTER opcode. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

Quoted 5 lines

I don't believe it's a sane approach. I think we agree that per cpu iowait is a silly and misleading metric. I have hard time to define what it is, and I'm sure most probably people complaining wouldn't be able to tell as well. Now we're taking that metric and expose even more knobs to userspace.

For sure, it's a stupid metric. But at the same time, educating people on this can be like talking to a brick wall, and it'll be years of doing that before we're making a dent in it. Hence I do think that just exposing the knob and letting the storage side use it, if they want, is the path of least resistance. I'm personally not going to do a crusade on iowait to eliminate it, I don't have the time for that. I'll educate people when it comes up, like I have been doing, but pulling this to conclusion would be 10+ years easily.

Quoted 6 lines

Another argument against is that per ctx is not the right place to have it. It's a system metric, and you can imagine some system admin looking for it. Even in cases when had some meaning w/o io_uring now without looking at what flags io_uring has it's completely meaningless, and it's too much to ask.

Quoted 7 lines

I don't understand why people freak out at seeing hi iowait, IMHO it perfectly fits the definition of io_uring waiting for IO / completions, but at this point it might be better to just revert it to the old behaviour of not reporting iowait at all. And if we want to save the cpu freq iowait optimisation, we should just split notion of iowait reporting and iowait cpufreq tuning.

For io_uring, splitting the cpufreq from iowait is certainly the right approach. And then just getting rid of iowait completely on the io_uring side. This can be done without preaching about iowait to everyone that has bad metrics for their healt monitoring, which is why I like that a lot. I did ponder that the other day as well.

You still kind of run into a problem with that in terms of when short vs long waits are expected. On the io_uring side, we use the "do I have any requests pending" for that, which is obviously not fine grained enough. We could apply it on just "do I have any requests against regular files" instead, which would then translate to needing further tracking on our side. Probably fine to just apply it for the existing logic, imho.

Signature · 1 line
Jens Axboe
#17 lore raw
Quoted 23 lines · Jens Axboe
Quoted 16 lines · Pavel Begunkov
Quoted 9 lines · David Wei

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

Quoted 5 lines

This patch gates the previously unconditional iowait accounting behind a new IORING_REGISTER opcode. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

Quoted 5 lines

I don't believe it's a sane approach. I think we agree that per cpu iowait is a silly and misleading metric. I have hard time to define what it is, and I'm sure most probably people complaining wouldn't be able to tell as well. Now we're taking that metric and expose even more knobs to userspace.

Quoted 6 lines

For sure, it's a stupid metric. But at the same time, educating people on this can be like talking to a brick wall, and it'll be years of doing that before we're making a dent in it. Hence I do think that just exposing the knob and letting the storage side use it, if they want, is the path of least resistance. I'm personally not going to do a crusade on iowait to eliminate it, I don't have the time for that. I'll educate

Exactly my point but with a different conclusion. The path of least resistance is to have io_uring not accounted to iowait. That's how it was so nobody should complain about it, you don't have to care about it at all, you don't have to educate people on iowait when it comes up with in the context of that knob, and you don't have to educate folks on what this knob is and wtf it's there, and we're not pretending that it works when it's not.

Quoted 23 lines

people when it comes up, like I have been doing, but pulling this to conclusion would be 10+ years easily.

Quoted 6 lines

Another argument against is that per ctx is not the right place to have it. It's a system metric, and you can imagine some system admin looking for it. Even in cases when had some meaning w/o io_uring now without looking at what flags io_uring has it's completely meaningless, and it's too much to ask.

Quoted 7 lines

I don't understand why people freak out at seeing hi iowait, IMHO it perfectly fits the definition of io_uring waiting for IO / completions, but at this point it might be better to just revert it to the old behaviour of not reporting iowait at all. And if we want to save the cpu freq iowait optimisation, we should just split notion of iowait reporting and iowait cpufreq tuning.

For io_uring, splitting the cpufreq from iowait is certainly the right approach. And then just getting rid of iowait completely on the io_uring side. This can be done without preaching about iowait to everyone that has bad metrics for their healt monitoring, which is why I like that a lot. I did ponder that the other day as well.

Quoted 7 lines

You still kind of run into a problem with that in terms of when short vs long waits are expected. On the io_uring side, we use the "do I have any requests pending" for that, which is obviously not fine grained enough. We could apply it on just "do I have any requests against regular files" instead, which would then translate to needing further tracking on our side. Probably fine to just apply it for the existing logic, imho.

Let's say there are two problems, one is the accounting mess, which is IMHO clear. The second is the optimisation, which is not mentioned in the patch and kind of an orthogonal issue. If we want a knob to disable/enable the cpufreq thing, it should be separate from iowait accounting, because it sounds like a really unfortunate side effect when you enable the optimisation and the iowait goes pounding the roof. Then people never touch it, especially in a framework, because an system admin will be pretty surprised by the metric.

Not like I'm a fan of the idea of having a userspace knob for the optimisation, it'd be pretty complicated to use, and hopefully there is a more intelligent approach.

Signature · 1 line
Pavel Begunkov
maintainer
#18 lore raw
Quoted 24 lines · Pavel Begunkov
Quoted 23 lines · Jens Axboe
Quoted 21 lines · Pavel Begunkov
Quoted 9 lines · David Wei

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

Quoted 5 lines

This patch gates the previously unconditional iowait accounting behind a new IORING_REGISTER opcode. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

I don't believe it's a sane approach. I think we agree that per cpu iowait is a silly and misleading metric. I have hard time to define what it is, and I'm sure most probably people complaining wouldn't be able to tell as well. Now we're taking that metric and expose even more knobs to userspace.

Quoted 8 lines
Quoted 6 lines

For sure, it's a stupid metric. But at the same time, educating people on this can be like talking to a brick wall, and it'll be years of doing that before we're making a dent in it. Hence I do think that just exposing the knob and letting the storage side use it, if they want, is the path of least resistance. I'm personally not going to do a crusade on iowait to eliminate it, I don't have the time for that. I'll educate

Exactly my point but with a different conclusion. The path of least

I think that's because I'm a realist, and you are an idealist ;-)

Quoted 6 lines

resistance is to have io_uring not accounted to iowait. That's how it was so nobody should complain about it, you don't have to care about it at all, you don't have to educate people on iowait when it comes up with in the context of that knob, and you don't have to educate folks on what this knob is and wtf it's there, and we're not pretending that it works when it's not.

I don't think anyone cares about iowait going away for waiting on events with io_uring, but some would very much care about losing the cpufreq connection which is why it got added in the first place. If we can trivially do that without iowait, then we should certainly just do that and call it good. THAT is the main question to answer, in form of a patch.

Quoted 31 lines
Quoted 23 lines

people when it comes up, like I have been doing, but pulling this to conclusion would be 10+ years easily.

Quoted 6 lines

Another argument against is that per ctx is not the right place to have it. It's a system metric, and you can imagine some system admin looking for it. Even in cases when had some meaning w/o io_uring now without looking at what flags io_uring has it's completely meaningless, and it's too much to ask.

Quoted 7 lines

I don't understand why people freak out at seeing hi iowait, IMHO it perfectly fits the definition of io_uring waiting for IO / completions, but at this point it might be better to just revert it to the old behaviour of not reporting iowait at all. And if we want to save the cpu freq iowait optimisation, we should just split notion of iowait reporting and iowait cpufreq tuning.

For io_uring, splitting the cpufreq from iowait is certainly the right approach. And then just getting rid of iowait completely on the io_uring side. This can be done without preaching about iowait to everyone that has bad metrics for their healt monitoring, which is why I like that a lot. I did ponder that the other day as well.

Quoted 7 lines

You still kind of run into a problem with that in terms of when short vs long waits are expected. On the io_uring side, we use the "do I have any requests pending" for that, which is obviously not fine grained enough. We could apply it on just "do I have any requests against regular files" instead, which would then translate to needing further tracking on our side. Probably fine to just apply it for the existing logic, imho.

Quoted 8 lines

Let's say there are two problems, one is the accounting mess, which is IMHO clear. The second is the optimisation, which is not mentioned in the patch and kind of an orthogonal issue. If we want a knob to disable/enable the cpufreq thing, it should be separate from iowait accounting, because it sounds like a really unfortunate side effect when you enable the optimisation and the iowait goes pounding the roof. Then people never touch it, especially in a framework, because an system admin will be pretty surprised by the metric.

Fully agree, it's all about not losing the short sleep high latency wakeup, which is what caused the performance to drop for low QD IOs.

Quoted 3 lines

Not like I'm a fan of the idea of having a userspace knob for the optimisation, it'd be pretty complicated to use, and hopefully there is a more intelligent approach.

That would certainly be nice.

Signature · 1 line
Jens Axboe
#19 lore raw

Hi folks,

Quoted 43 lines · Jens Axboe
Quoted 24 lines · Pavel Begunkov
Quoted 23 lines · Jens Axboe
Quoted 21 lines · Pavel Begunkov
Quoted 9 lines · David Wei

Currently we unconditionally account time spent waiting for events in CQ ring as iowait time.

Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling.

Quoted 5 lines

This patch gates the previously unconditional iowait accounting behind a new IORING_REGISTER opcode. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not.

I don't believe it's a sane approach. I think we agree that per cpu iowait is a silly and misleading metric. I have hard time to define what it is, and I'm sure most probably people complaining wouldn't be able to tell as well. Now we're taking that metric and expose even more knobs to userspace.

Quoted 8 lines
Quoted 6 lines

For sure, it's a stupid metric. But at the same time, educating people on this can be like talking to a brick wall, and it'll be years of doing that before we're making a dent in it. Hence I do think that just exposing the knob and letting the storage side use it, if they want, is the path of least resistance. I'm personally not going to do a crusade on iowait to eliminate it, I don't have the time for that. I'll educate

Exactly my point but with a different conclusion. The path of least

I think that's because I'm a realist, and you are an idealist ;-)

Quoted 6 lines

resistance is to have io_uring not accounted to iowait. That's how it was so nobody should complain about it, you don't have to care about it at all, you don't have to educate people on iowait when it comes up with in the context of that knob, and you don't have to educate folks on what this knob is and wtf it's there, and we're not pretending that it works when it's not.

Quoted 6 lines

I don't think anyone cares about iowait going away for waiting on events with io_uring, but some would very much care about losing the cpufreq connection which is why it got added in the first place. If we can trivially do that without iowait, then we should certainly just do that and call it good. THAT is the main question to answer, in form of a patch.

I commented on Jens' patch regarding iowait and iowait_acct, which is probably the path of least resistance for that specific issue, but let me expand a bit on the cpufreq iowait connection problem.
cpufreq iowait handling and cpuidle iowait handling I would consider vastly different in that respect and it seems to me that improving cpufreq should be feasible effort (if it only catches 90% of scenarios at first then so be it).
I'm thinking something of a in_iowait_boost (or the opposite in_iowait_queue_full full meaning reasonably non-empty).
The current behaviour of boosting CPU frequency on anything is just very unfortunate and for io_uring in particular destroys all of the power-savings it could have due to reduced CPU usage.
(Just to be clear, current iowait boosting is not just broken in io_uring, but rather everywhere, particularly because of the lack of definition what iowait even means and when it should be set. Thus boosting on any iowait seen is like taking a sledgehammer to crack a nut.)
I'm happy to propose some io_uring patch (that is probably nonsensical because of a lot of reasons) or test whatever ideas you have.
Something like
if pending_requests > device_queue_size: Don't boost
would be an improvement from what I can tell.

And I know I'm heavily reducing io_uring to block IO here and am aware of how wrong that is, but storage device IO was the original story that got iowait boosting introduced in the first place.
If you have any cpufreq (or rather DVFS) related issues with anything else io_uring like networking I'll give reproducing that a shot as well. Would love to hear your thoughts!

Kind Regards,
Christian