Skip to content

Commit 0553b8b

Browse files
isilenceaxboe
authored andcommitted
io_uring: remove req init from io_get_req()
io_get_req() do two different things: io_kiocb allocation and initialisation. Move init part out of it and rename into io_alloc_req(). It's simpler this way and also have better data locality. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b1e50e5 commit 0553b8b

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

fs/io_uring.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,8 @@ static struct io_kiocb *io_get_fallback_req(struct io_ring_ctx *ctx)
12931293
return NULL;
12941294
}
12951295

1296-
static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
1297-
struct io_submit_state *state)
1296+
static struct io_kiocb *io_alloc_req(struct io_ring_ctx *ctx,
1297+
struct io_submit_state *state)
12981298
{
12991299
gfp_t gfp = GFP_KERNEL | __GFP_NOWARN;
13001300
struct io_kiocb *req;
@@ -1327,22 +1327,9 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
13271327
req = state->reqs[state->free_reqs];
13281328
}
13291329

1330-
got_it:
1331-
req->io = NULL;
1332-
req->file = NULL;
1333-
req->ctx = ctx;
1334-
req->flags = 0;
1335-
/* one is dropped after submission, the other at completion */
1336-
refcount_set(&req->refs, 2);
1337-
req->task = NULL;
1338-
req->result = 0;
1339-
INIT_IO_WORK(&req->work, io_wq_submit_work);
13401330
return req;
13411331
fallback:
1342-
req = io_get_fallback_req(ctx);
1343-
if (req)
1344-
goto got_it;
1345-
return NULL;
1332+
return io_get_fallback_req(ctx);
13461333
}
13471334

13481335
static inline void io_put_file(struct io_kiocb *req, struct file *file,
@@ -5804,6 +5791,28 @@ static inline void io_consume_sqe(struct io_ring_ctx *ctx)
58045791
ctx->cached_sq_head++;
58055792
}
58065793

5794+
static void io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
5795+
const struct io_uring_sqe *sqe)
5796+
{
5797+
/*
5798+
* All io need record the previous position, if LINK vs DARIN,
5799+
* it can be used to mark the position of the first IO in the
5800+
* link list.
5801+
*/
5802+
req->sequence = ctx->cached_sq_head;
5803+
req->opcode = READ_ONCE(sqe->opcode);
5804+
req->user_data = READ_ONCE(sqe->user_data);
5805+
req->io = NULL;
5806+
req->file = NULL;
5807+
req->ctx = ctx;
5808+
req->flags = 0;
5809+
/* one is dropped after submission, the other at completion */
5810+
refcount_set(&req->refs, 2);
5811+
req->task = NULL;
5812+
req->result = 0;
5813+
INIT_IO_WORK(&req->work, io_wq_submit_work);
5814+
}
5815+
58075816
static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
58085817
struct file *ring_file, int ring_fd,
58095818
struct mm_struct **mm, bool async)
@@ -5844,23 +5853,15 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
58445853
io_consume_sqe(ctx);
58455854
break;
58465855
}
5847-
req = io_get_req(ctx, statep);
5856+
req = io_alloc_req(ctx, statep);
58485857
if (unlikely(!req)) {
58495858
if (!submitted)
58505859
submitted = -EAGAIN;
58515860
break;
58525861
}
58535862

5854-
/*
5855-
* All io need record the previous position, if LINK vs DARIN,
5856-
* it can be used to mark the position of the first IO in the
5857-
* link list.
5858-
*/
5859-
req->sequence = ctx->cached_sq_head;
5860-
req->opcode = READ_ONCE(sqe->opcode);
5861-
req->user_data = READ_ONCE(sqe->user_data);
5863+
io_init_req(ctx, req, sqe);
58625864
io_consume_sqe(ctx);
5863-
58645865
/* will complete beyond this point, count as submitted */
58655866
submitted++;
58665867

0 commit comments

Comments
 (0)