Skip to contentSkip to conversation

io_uring: don't iterate ctx list to update sq_thread_idle

PATCH In review Hao Xu 2 participants 3 messages Mar 15, 2021 – Mar 16, 2021

Subsystems (2)
lore
Share & tools
lore

Hao Xu

author
#0 lore raw

PATCH 1/1 io_uring: don't iterate ctx list to update sq_thread_idle

sqd->sq_thread_idle can be updated by a simple max(), rather than iterating the whole ctx list to get the max one.

---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index a4bce17af506..17697b9890e3 100644
@@ -7871,7 +7871,7 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
 			ret = -ENXIO;
 		} else {
 			list_add(&ctx->sqd_list, &sqd->ctx_list);
-			io_sqd_update_thread_idle(sqd);
+			sqd->sq_thread_idle = max(sqd->sq_thread_idle, ctx->sq_thread_idle);
 		}
 		io_sq_thread_unpark(sqd);
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 2 lines · Hao Xu

sqd->sq_thread_idle can be updated by a simple max(), rather than iterating the whole ctx list to get the max one.

I left it as a more fool proof option. Do you have a performance issue with it? E.g. dozens rings sharing a single SQPOLL and constantly adding new ones.

Quoted 20 lines
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index a4bce17af506..17697b9890e3 100644
@@ -7871,7 +7871,7 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
 			ret = -ENXIO;
 		} else {
 			list_add(&ctx->sqd_list, &sqd->ctx_list);
-			io_sqd_update_thread_idle(sqd);
+			sqd->sq_thread_idle = max(sqd->sq_thread_idle, ctx->sq_thread_idle);
 		}
 		io_sq_thread_unpark(sqd);
 
Signature · 1 line
Pavel Begunkov
author
#2 lore raw
Quoted 7 lines · Pavel Begunkov
Quoted 2 lines · Hao Xu

sqd->sq_thread_idle can be updated by a simple max(), rather than iterating the whole ctx list to get the max one.

I left it as a more fool proof option. Do you have a performance issue with it? E.g. dozens rings sharing a single SQPOLL and constantly adding new ones.

Currently no performance cases, just happen to see this and make the code change.

Quoted 22 lines
Quoted 21 lines
---
  fs/io_uring.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index a4bce17af506..17697b9890e3 100644
@@ -7871,7 +7871,7 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
  			ret = -ENXIO;
  		} else {
  			list_add(&ctx->sqd_list, &sqd->ctx_list);
-			io_sqd_update_thread_idle(sqd);
+			sqd->sq_thread_idle = max(sqd->sq_thread_idle, ctx->sq_thread_idle);
  		}
  		io_sq_thread_unpark(sqd);