Commit a1ab7b35 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: move req link into submit_state

Move struct io_submit_link into submit_state, which is a part of a
submission state and so belongs to it. It saves us from explicitly
passing it, and init/deinit is now nicely hidden in
io_submit_state_[start,end].
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent a6b8cadc
...@@ -283,8 +283,14 @@ struct io_comp_state { ...@@ -283,8 +283,14 @@ struct io_comp_state {
struct list_head locked_free_list; struct list_head locked_free_list;
}; };
struct io_submit_link {
struct io_kiocb *head;
struct io_kiocb *last;
};
struct io_submit_state { struct io_submit_state {
struct blk_plug plug; struct blk_plug plug;
struct io_submit_link link;
/* /*
* io_kiocb alloc cache * io_kiocb alloc cache
...@@ -6746,15 +6752,10 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, ...@@ -6746,15 +6752,10 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
return ret; return ret;
} }
struct io_submit_link {
struct io_kiocb *head;
struct io_kiocb *last;
};
static int io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, static int io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req,
const struct io_uring_sqe *sqe, const struct io_uring_sqe *sqe)
struct io_submit_link *link)
{ {
struct io_submit_link *link = &ctx->submit_state.link;
int ret; int ret;
ret = io_init_req(ctx, req, sqe); ret = io_init_req(ctx, req, sqe);
...@@ -6829,6 +6830,8 @@ static int io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, ...@@ -6829,6 +6830,8 @@ static int io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req,
static void io_submit_state_end(struct io_submit_state *state, static void io_submit_state_end(struct io_submit_state *state,
struct io_ring_ctx *ctx) struct io_ring_ctx *ctx)
{ {
if (state->link.head)
io_queue_link_head(state->link.head);
if (state->comp.nr) if (state->comp.nr)
io_submit_flush_completions(&state->comp, ctx); io_submit_flush_completions(&state->comp, ctx);
if (state->plug_started) if (state->plug_started)
...@@ -6844,6 +6847,8 @@ static void io_submit_state_start(struct io_submit_state *state, ...@@ -6844,6 +6847,8 @@ static void io_submit_state_start(struct io_submit_state *state,
{ {
state->plug_started = false; state->plug_started = false;
state->ios_left = max_ios; state->ios_left = max_ios;
/* set only head, no need to init link_last in advance */
state->link.head = NULL;
} }
static void io_commit_sqring(struct io_ring_ctx *ctx) static void io_commit_sqring(struct io_ring_ctx *ctx)
...@@ -6891,7 +6896,6 @@ static const struct io_uring_sqe *io_get_sqe(struct io_ring_ctx *ctx) ...@@ -6891,7 +6896,6 @@ static const struct io_uring_sqe *io_get_sqe(struct io_ring_ctx *ctx)
static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr) static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
{ {
struct io_submit_link link;
int submitted = 0; int submitted = 0;
/* if we have a backlog and couldn't flush it all, return BUSY */ /* if we have a backlog and couldn't flush it all, return BUSY */
...@@ -6908,9 +6912,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr) ...@@ -6908,9 +6912,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
percpu_counter_add(&current->io_uring->inflight, nr); percpu_counter_add(&current->io_uring->inflight, nr);
refcount_add(nr, &current->usage); refcount_add(nr, &current->usage);
io_submit_state_start(&ctx->submit_state, nr); io_submit_state_start(&ctx->submit_state, nr);
link.head = NULL;
while (submitted < nr) { while (submitted < nr) {
const struct io_uring_sqe *sqe; const struct io_uring_sqe *sqe;
...@@ -6929,7 +6931,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr) ...@@ -6929,7 +6931,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
} }
/* will complete beyond this point, count as submitted */ /* will complete beyond this point, count as submitted */
submitted++; submitted++;
if (io_submit_sqe(ctx, req, sqe, &link)) if (io_submit_sqe(ctx, req, sqe))
break; break;
} }
...@@ -6942,10 +6944,8 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr) ...@@ -6942,10 +6944,8 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
percpu_counter_sub(&tctx->inflight, unused); percpu_counter_sub(&tctx->inflight, unused);
put_task_struct_many(current, unused); put_task_struct_many(current, unused);
} }
if (link.head)
io_queue_link_head(link.head);
io_submit_state_end(&ctx->submit_state, ctx);
io_submit_state_end(&ctx->submit_state, ctx);
/* Commit SQ ring head once we've consumed and submitted all SQEs */ /* Commit SQ ring head once we've consumed and submitted all SQEs */
io_commit_sqring(ctx); io_commit_sqring(ctx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment