Skip to contentSkip to conversation

io_uring: set error code to be ENOMEM when io_alloc_async_ctx() fails

PATCH In review Xiaoguang Wang 2 participants 3 messages Apr 9, 2020

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

PATCH 1/1 io_uring: set error code to be ENOMEM when io_alloc_async_ctx() fails

We should return ENOMEM for memory allocation failures, fix this issue for io_alloc_async_ctx() calls.

---
 fs/io_uring.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/io_uring.c +3 -3
index 6ac830b2b4fb..42a49a7e7792 100644
@@ -4993,7 +4993,7 @@ static int io_req_defer(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 		return 0;
 
 	if (!req->io && io_alloc_async_ctx(req))
-		return -EAGAIN;
+		return -ENOMEM;
 
 	ret = io_req_defer_prep(req, sqe);
 	if (ret < 0)
@@ -5695,7 +5695,7 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
 			ctx->drain_next = 1;
 		}
 		if (io_alloc_async_ctx(req)) {
-			ret = -EAGAIN;
+			ret = -ENOMEM;
 			goto err_req;
 		}
 
@@ -5723,7 +5723,7 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
 			INIT_LIST_HEAD(&req->link_list);
 
 			if (io_alloc_async_ctx(req)) {
-				ret = -EAGAIN;
+				ret = -ENOMEM;
 				goto err_req;
 			}
 			ret = io_req_defer_prep(req, sqe);
Signature · 1 line
2.17.2
maintainer
#1 lore raw
Quoted 2 lines · Xiaoguang Wang

We should return ENOMEM for memory allocation failures, fix this issue for io_alloc_async_ctx() calls.

It's not uncommon to have out-of-memory turn into -EAGAIN for the application for runtime allocations, indicating that the application could feasibly try again and hope for a better outcome (maybe after freeing memory).

The error code is also documented as such in the io_uring_enter.2 man page.

Signature · 1 line
Jens Axboe
#2 lore raw

hi,

Quoted 8 lines · Xiaoguang Wang
Quoted 2 lines

We should return ENOMEM for memory allocation failures, fix this issue for io_alloc_async_ctx() calls.

It's not uncommon to have out-of-memory turn into -EAGAIN for the application for runtime allocations, indicating that the application could feasibly try again and hope for a better outcome (maybe after freeing memory).

OK, i see, thanks.

Quoted 3 lines

The error code is also documented as such in the io_uring_enter.2 man page.

Yeah, I checked it just now, and I should read the man page carefully again :)

Regards,
Xiaoguang Wang

Quoted 1 line