Skip to contentSkip to conversation

io_uring: assign ctx->ring_file and ctx->ring_fd early in io_uring_create()

RFC PATCH New Xiaoguang Wang 1 participant 1 message Sep 13, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 io_uring: assign ctx->ring_file and ctx->ring_fd early in io_uring_create()

While testing the feature which supports multiple rings to share same poll thread by specifying same cpu, fio often hangs in fio_ioring_getevents() infinitely. After some investigations, I find it's because ctx->ring_file is NULL, so io_sq_thread doest not submit this ctx's requests.

While ring initialization completes, IORING_SQ_NEED_WAKEUP will be not set initially, app may already submit some reqs and the corresponding io_sq_thread may already see these reqs, but will not submit them because ring_file is NULL. Some apps just check IORING_SQ_NEED_WAKEUP beforce submitting reqs, for example, fio just checks it in fio_ioring_commit() and will not check it in fio_ioring_getevents(), then fio will hang forever. To fix this issue, we assign ctx->ring_file and ctx->ring_fd early in io_uring_create().

---
 fs/io_uring.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/io_uring.c +5 -0
index 321a430ff3f7..5ddb2cddc695 100644
@@ -9034,6 +9034,11 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,
 		goto err;
 	}
 
+	if (p->flags & IORING_SETUP_SQPOLL) {
+		ctx->ring_fd = fd;
+		ctx->ring_file = file;
+	}
+
 	ret = io_sq_offload_create(ctx, p);
 	if (ret)
 		goto err;
Signature · 1 line
2.17.2