Skip to content

Commit b1e50e5

Browse files
isilenceaxboe
authored andcommitted
io_uring: alloc req only after getting sqe
As io_get_sqe() split into 2 stage get/consume, get an sqe before allocating io_kiocb, so no free_req*() for a failure case is needed, and inline back __io_req_do_free(), which has only 1 user. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 709b302 commit b1e50e5

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

fs/io_uring.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,14 +1354,6 @@ static inline void io_put_file(struct io_kiocb *req, struct file *file,
13541354
fput(file);
13551355
}
13561356

1357-
static void __io_req_do_free(struct io_kiocb *req)
1358-
{
1359-
if (likely(!io_is_fallback_req(req)))
1360-
kmem_cache_free(req_cachep, req);
1361-
else
1362-
clear_bit_unlock(0, (unsigned long *) req->ctx->fallback_req);
1363-
}
1364-
13651357
static void __io_req_aux_free(struct io_kiocb *req)
13661358
{
13671359
if (req->flags & REQ_F_NEED_CLEANUP)
@@ -1392,7 +1384,10 @@ static void __io_free_req(struct io_kiocb *req)
13921384
}
13931385

13941386
percpu_ref_put(&req->ctx->refs);
1395-
__io_req_do_free(req);
1387+
if (likely(!io_is_fallback_req(req)))
1388+
kmem_cache_free(req_cachep, req);
1389+
else
1390+
clear_bit_unlock(0, (unsigned long *) req->ctx->fallback_req);
13961391
}
13971392

13981393
struct req_batch {
@@ -5844,18 +5839,17 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
58445839
struct io_kiocb *req;
58455840
int err;
58465841

5842+
sqe = io_get_sqe(ctx);
5843+
if (unlikely(!sqe)) {
5844+
io_consume_sqe(ctx);
5845+
break;
5846+
}
58475847
req = io_get_req(ctx, statep);
58485848
if (unlikely(!req)) {
58495849
if (!submitted)
58505850
submitted = -EAGAIN;
58515851
break;
58525852
}
5853-
sqe = io_get_sqe(ctx);
5854-
if (!sqe) {
5855-
__io_req_do_free(req);
5856-
io_consume_sqe(ctx);
5857-
break;
5858-
}
58595853

58605854
/*
58615855
* All io need record the previous position, if LINK vs DARIN,

0 commit comments

Comments
 (0)