* [PATCH] io_uring: add IORING_SETUP_NO_SQTHREAD_STATS flag to disable sqthread stats collection
@ 2025-10-16 11:45 Fengnan Chang
2025-10-16 12:04 ` Pavel Begunkov
0 siblings, 1 reply; 5+ messages in thread
From: Fengnan Chang @ 2025-10-16 11:45 UTC (permalink / raw)
To: axboe, xiaobing.li, io-uring; +Cc: Fengnan Chang, Diangang Li
introduces a new flag IORING_SETUP_NO_SQTHREAD_STATS that allows
user to disable the collection of statistics in the sqthread.
When this flag is set, the getrusage() calls in the sqthread are
skipped, which can provide a small performance improvement in high
IOPS workloads.
./t/io_uring -p1 -d128 -b4096 -s32 -c1 -F1 -B1 -R1 -X1 -n1 ./testfile
IOPS base: 570K, patch: 590K
./t/io_uring -p1 -d128 -b4096 -s32 -c1 -F1 -B1 -R1 -X1 -n1 /dev/nvme1n1
IOPS base: 826K, patch: 889K
Signed-off-by: Fengnan Chang <changfengnan@bytedance.com>
Reviewed-by: Diangang Li <lidiangang@bytedance.com>
---
include/uapi/linux/io_uring.h | 5 +++++
io_uring/fdinfo.c | 15 ++++++++++-----
io_uring/io_uring.h | 3 ++-
io_uring/sqpoll.c | 10 +++++++---
io_uring/sqpoll.h | 1 +
5 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 263bed13473e..57adae0d67e5 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -231,6 +231,11 @@ enum io_uring_sqe_flags_bit {
*/
#define IORING_SETUP_CQE_MIXED (1U << 18)
+/*
+ * Disable SQPOLL thread stats collection, skipping getrusage() calls
+ */
+#define IORING_SETUP_NO_SQTHREAD_STATS (1U << 19)
+
enum io_uring_op {
IORING_OP_NOP,
IORING_OP_READV,
diff --git a/io_uring/fdinfo.c b/io_uring/fdinfo.c
index ff3364531c77..055a505fa27c 100644
--- a/io_uring/fdinfo.c
+++ b/io_uring/fdinfo.c
@@ -154,13 +154,16 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
if (tsk) {
get_task_struct(tsk);
rcu_read_unlock();
- getrusage(tsk, RUSAGE_SELF, &sq_usage);
+ if (sq->enable_work_time_stat)
+ getrusage(tsk, RUSAGE_SELF, &sq_usage);
put_task_struct(tsk);
sq_pid = sq->task_pid;
sq_cpu = sq->sq_cpu;
- sq_total_time = (sq_usage.ru_stime.tv_sec * 1000000
+ if (sq->enable_work_time_stat) {
+ sq_total_time = (sq_usage.ru_stime.tv_sec * 1000000
+ sq_usage.ru_stime.tv_usec);
- sq_work_time = sq->work_time;
+ sq_work_time = sq->work_time;
+ }
} else {
rcu_read_unlock();
}
@@ -168,8 +171,10 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
seq_printf(m, "SqThread:\t%d\n", sq_pid);
seq_printf(m, "SqThreadCpu:\t%d\n", sq_cpu);
- seq_printf(m, "SqTotalTime:\t%llu\n", sq_total_time);
- seq_printf(m, "SqWorkTime:\t%llu\n", sq_work_time);
+ if (!(ctx->flags & IORING_SETUP_NO_SQTHREAD_STATS)) {
+ seq_printf(m, "SqTotalTime:\t%llu\n", sq_total_time);
+ seq_printf(m, "SqWorkTime:\t%llu\n", sq_work_time);
+ }
seq_printf(m, "UserFiles:\t%u\n", ctx->file_table.data.nr);
for (i = 0; i < ctx->file_table.data.nr; i++) {
struct file *f = NULL;
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 46d9141d772a..f3e72b447fca 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -54,7 +54,8 @@
IORING_SETUP_REGISTERED_FD_ONLY |\
IORING_SETUP_NO_SQARRAY |\
IORING_SETUP_HYBRID_IOPOLL |\
- IORING_SETUP_CQE_MIXED)
+ IORING_SETUP_CQE_MIXED |\
+ IORING_SETUP_NO_SQTHREAD_STATS)
#define IORING_ENTER_FLAGS (IORING_ENTER_GETEVENTS |\
IORING_ENTER_SQ_WAKEUP |\
diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index a3f11349ce06..4169dd02833b 100644
--- a/io_uring/sqpoll.c
+++ b/io_uring/sqpoll.c
@@ -161,6 +161,7 @@ static struct io_sq_data *io_get_sq_data(struct io_uring_params *p,
mutex_init(&sqd->lock);
init_waitqueue_head(&sqd->wait);
init_completion(&sqd->exited);
+ sqd->enable_work_time_stat = true;
return sqd;
}
@@ -317,7 +318,8 @@ static int io_sq_thread(void *data)
}
cap_entries = !list_is_singular(&sqd->ctx_list);
- getrusage(current, RUSAGE_SELF, &start);
+ if (sqd->enable_work_time_stat)
+ getrusage(current, RUSAGE_SELF, &start);
list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
int ret = __io_sq_thread(ctx, cap_entries);
@@ -333,7 +335,8 @@ static int io_sq_thread(void *data)
if (sqt_spin || !time_after(jiffies, timeout)) {
if (sqt_spin) {
- io_sq_update_worktime(sqd, &start);
+ if (sqd->enable_work_time_stat)
+ io_sq_update_worktime(sqd, &start);
timeout = jiffies + sqd->sq_thread_idle;
}
if (unlikely(need_resched())) {
@@ -445,7 +448,8 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
ret = PTR_ERR(sqd);
goto err;
}
-
+ if (ctx->flags & IORING_SETUP_NO_SQTHREAD_STATS)
+ sqd->enable_work_time_stat = false;
ctx->sq_creds = get_current_cred();
ctx->sq_data = sqd;
ctx->sq_thread_idle = msecs_to_jiffies(p->sq_thread_idle);
diff --git a/io_uring/sqpoll.h b/io_uring/sqpoll.h
index b83dcdec9765..55f2e4d46d54 100644
--- a/io_uring/sqpoll.h
+++ b/io_uring/sqpoll.h
@@ -19,6 +19,7 @@ struct io_sq_data {
u64 work_time;
unsigned long state;
struct completion exited;
+ bool enable_work_time_stat;
};
int io_sq_offload_create(struct io_ring_ctx *ctx, struct io_uring_params *p);
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] io_uring: add IORING_SETUP_NO_SQTHREAD_STATS flag to disable sqthread stats collection
2025-10-16 11:45 [PATCH] io_uring: add IORING_SETUP_NO_SQTHREAD_STATS flag to disable sqthread stats collection Fengnan Chang
@ 2025-10-16 12:04 ` Pavel Begunkov
2025-10-16 12:09 ` [External] " Fengnan Chang
0 siblings, 1 reply; 5+ messages in thread
From: Pavel Begunkov @ 2025-10-16 12:04 UTC (permalink / raw)
To: Fengnan Chang, axboe, xiaobing.li, io-uring; +Cc: Diangang Li
On 10/16/25 12:45, Fengnan Chang wrote:
> introduces a new flag IORING_SETUP_NO_SQTHREAD_STATS that allows
> user to disable the collection of statistics in the sqthread.
> When this flag is set, the getrusage() calls in the sqthread are
> skipped, which can provide a small performance improvement in high
> IOPS workloads.
It was added for dynamically adjusting SQPOLL timeouts, at least that
what the author said, but then there is only the fdinfo to access it,
which is slow and unreliable, and no follow up to expose it in a
better way. To be honest, I have serious doubts it has ever been used,
and I'd be tempted to completely remove it out of the kernel. Fdinfo
format wasn't really stable for io_uring and we can leave it printing
some made up values like 100% util.
If it's there for outside monitoring, that should be done with bpf,
with maybe additional tracepoints.
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [External] Re: [PATCH] io_uring: add IORING_SETUP_NO_SQTHREAD_STATS flag to disable sqthread stats collection
2025-10-16 12:04 ` Pavel Begunkov
@ 2025-10-16 12:09 ` Fengnan Chang
[not found] ` <CGME20251017091046epcas5p35dfbcf4979f79b3a80441aed2d31a906@epcas5p3.samsung.com>
0 siblings, 1 reply; 5+ messages in thread
From: Fengnan Chang @ 2025-10-16 12:09 UTC (permalink / raw)
To: Pavel Begunkov; +Cc: axboe, xiaobing.li, io-uring, Diangang Li
Pavel Begunkov <asml.silence@gmail.com> 于2025年10月16日周四 20:03写道:
>
> On 10/16/25 12:45, Fengnan Chang wrote:
> > introduces a new flag IORING_SETUP_NO_SQTHREAD_STATS that allows
> > user to disable the collection of statistics in the sqthread.
> > When this flag is set, the getrusage() calls in the sqthread are
> > skipped, which can provide a small performance improvement in high
> > IOPS workloads.
>
> It was added for dynamically adjusting SQPOLL timeouts, at least that
> what the author said, but then there is only the fdinfo to access it,
> which is slow and unreliable, and no follow up to expose it in a
> better way. To be honest, I have serious doubts it has ever been used,
> and I'd be tempted to completely remove it out of the kernel. Fdinfo
> format wasn't really stable for io_uring and we can leave it printing
> some made up values like 100% util.
Agree, IMO turning off stats by default would be a better approach, but
I'm concerned that some people are using this in fdinfo. I'd like to hear
the author's opinion.
>
> If it's there for outside monitoring, that should be done with bpf,
> with maybe additional tracepoints.
>
> --
> Pavel Begunkov
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] io_uring: add IORING_SETUP_NO_SQTHREAD_STATS flag to disable sqthread stats collection.
[not found] ` <CGME20251017091046epcas5p35dfbcf4979f79b3a80441aed2d31a906@epcas5p3.samsung.com>
@ 2025-10-17 9:06 ` Xiaobing Li
2025-10-17 9:21 ` [External] " Fengnan Chang
0 siblings, 1 reply; 5+ messages in thread
From: Xiaobing Li @ 2025-10-17 9:06 UTC (permalink / raw)
To: changfengnan
Cc: asml.silence, axboe, io-uring, lidiangang, kun.dou, peiwei.li,
joshi.k
On 10/16/25 20:09, Fengnan Chang wrote:
>On 10/16/25 20:03, Pavel Begunkov wrote:
>>
>> On 10/16/25 12:45, Fengnan Chang wrote:
>> > introduces a new flag IORING_SETUP_NO_SQTHREAD_STATS that allows
>> > user to disable the collection of statistics in the sqthread.
>> > When this flag is set, the getrusage() calls in the sqthread are
>> > skipped, which can provide a small performance improvement in high
>> > IOPS workloads.
>>
>> It was added for dynamically adjusting SQPOLL timeouts, at least that
>> what the author said, but then there is only the fdinfo to access it,
>> which is slow and unreliable, and no follow up to expose it in a
>> better way. To be honest, I have serious doubts it has ever been used,
>> and I'd be tempted to completely remove it out of the kernel. Fdinfo
>> format wasn't really stable for io_uring and we can leave it printing
>> some made up values like 100% util.
>
>Agree, IMO turning off stats by default would be a better approach, but
>I'm concerned that some people are using this in fdinfo. I'd like to hear
>the author's opinion.
We use fdinfo statistics to evaluate some of our internal test data.
Initially, I tested the performance impact of adding this feature, and the
results showed that it had little impact on performance. Therefore,
I didn't consider adding a switch to control its use. However,
adding a switch to control whether to enable utilization statistics
is a good idea.
--
Xiaobing Li
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [External] Re: [PATCH] io_uring: add IORING_SETUP_NO_SQTHREAD_STATS flag to disable sqthread stats collection.
2025-10-17 9:06 ` Xiaobing Li
@ 2025-10-17 9:21 ` Fengnan Chang
0 siblings, 0 replies; 5+ messages in thread
From: Fengnan Chang @ 2025-10-17 9:21 UTC (permalink / raw)
To: Xiaobing Li
Cc: asml.silence, axboe, io-uring, lidiangang, kun.dou, peiwei.li,
joshi.k
Xiaobing Li <xiaobing.li@samsung.com> 于2025年10月17日周五 17:18写道:
>
> On 10/16/25 20:09, Fengnan Chang wrote:
> >On 10/16/25 20:03, Pavel Begunkov wrote:
> >>
> >> On 10/16/25 12:45, Fengnan Chang wrote:
> >> > introduces a new flag IORING_SETUP_NO_SQTHREAD_STATS that allows
> >> > user to disable the collection of statistics in the sqthread.
> >> > When this flag is set, the getrusage() calls in the sqthread are
> >> > skipped, which can provide a small performance improvement in high
> >> > IOPS workloads.
> >>
> >> It was added for dynamically adjusting SQPOLL timeouts, at least that
> >> what the author said, but then there is only the fdinfo to access it,
> >> which is slow and unreliable, and no follow up to expose it in a
> >> better way. To be honest, I have serious doubts it has ever been used,
> >> and I'd be tempted to completely remove it out of the kernel. Fdinfo
> >> format wasn't really stable for io_uring and we can leave it printing
> >> some made up values like 100% util.
> >
> >Agree, IMO turning off stats by default would be a better approach, but
> >I'm concerned that some people are using this in fdinfo. I'd like to hear
> >the author's opinion.
>
> We use fdinfo statistics to evaluate some of our internal test data.
> Initially, I tested the performance impact of adding this feature, and the
> results showed that it had little impact on performance. Therefore,
> I didn't consider adding a switch to control its use. However,
> adding a switch to control whether to enable utilization statistics
> is a good idea.
Get, I think we have a common understanding to turn off stats by default
and add flags to turn them on. I'll send patch V2 to do this.
>
> --
> Xiaobing Li
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-10-17 9:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-16 11:45 [PATCH] io_uring: add IORING_SETUP_NO_SQTHREAD_STATS flag to disable sqthread stats collection Fengnan Chang
2025-10-16 12:04 ` Pavel Begunkov
2025-10-16 12:09 ` [External] " Fengnan Chang
[not found] ` <CGME20251017091046epcas5p35dfbcf4979f79b3a80441aed2d31a906@epcas5p3.samsung.com>
2025-10-17 9:06 ` Xiaobing Li
2025-10-17 9:21 ` [External] " Fengnan Chang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox