From 13ef55ac3b56e960be0e17d98443ca344b608f67 Mon Sep 17 00:00:00 2001 From: Jae Hyun Yoo Date: Thu, 11 Jun 2026 11:49:07 -0700 Subject: [PATCH] asio: io_uring: add ASIO_DISABLE_IO_URING_IOWAIT io_uring marks the io_context waiter task as in_iowait whenever any SQE is pending, without distinguishing real I/O from POLL_ADD/TIMEOUT SQEs submitted for socket and timer waits. The backend keeps those pending for the full async_wait, so the flag stays set with nothing blocked on I/O, inflating iowait/load metrics and blocking deeper CPU idle states. Add an opt-in macro calling io_uring_set_iowait(ring, false) after queue init. Default behaviour is unchanged. Requires liburing 2.12 (guarded on IORING_FEAT_NO_IOWAIT, #error otherwise). Older runtime kernels return -EOPNOTSUPP, which is harmless. --- include/asio/detail/impl/io_uring_service.ipp | 8 ++++++++ src/doc/platform_macros.qbk | 7 +++++++ src/doc/using.qbk | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/include/asio/detail/impl/io_uring_service.ipp b/include/asio/detail/impl/io_uring_service.ipp index c43b65d7e8..b249195f98 100644 --- a/include/asio/detail/impl/io_uring_service.ipp +++ b/include/asio/detail/impl/io_uring_service.ipp @@ -538,6 +538,14 @@ void io_uring_service::init_ring() asio::detail::throw_error(ec, "io_uring_queue_init"); } +#if defined(ASIO_DISABLE_IO_URING_IOWAIT) +# if !defined(IORING_FEAT_NO_IOWAIT) +# error ASIO_DISABLE_IO_URING_IOWAIT requires liburing 2.12 or later +# endif // !defined(IORING_FEAT_NO_IOWAIT) + // Opt out of io_uring's in_iowait task marking. + (void)::io_uring_set_iowait(&ring_, false); +#endif // defined(ASIO_DISABLE_IO_URING_IOWAIT) + #if !defined(ASIO_HAS_IO_URING_AS_DEFAULT) event_fd_ = ::eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (event_fd_ < 0) diff --git a/src/doc/platform_macros.qbk b/src/doc/platform_macros.qbk index 8e7f171bf1..ae275518ad 100644 --- a/src/doc/platform_macros.qbk +++ b/src/doc/platform_macros.qbk @@ -268,6 +268,13 @@ needs. ] [] ] + [ + [`ASIO_DISABLE_IO_URING_IOWAIT`] + [ + Linux: suppress io_uring's `in_iowait` task marking. + ] + [] + ] [ [`ASIO_HAS_KQUEUE`] [ diff --git a/src/doc/using.qbk b/src/doc/using.qbk index 08897fc55f..73a8651b8d 100644 --- a/src/doc/using.qbk +++ b/src/doc/using.qbk @@ -260,6 +260,13 @@ functionality, and behaviour of Asio. pipe to interrupt blocked epoll/select system calls. ] ] + [ + [`ASIO_DISABLE_IO_URING_IOWAIT`] + [ + Suppresses io_uring's `in_iowait` task marking on Linux via + `io_uring_set_iowait()`. + ] + ] [ [`ASIO_DISABLE_KQUEUE`] [