Skip to content

Commit 71b547c

Browse files
isilenceaxboe
authored andcommitted
io_uring: improve submit_state.ios_left accounting
state->ios_left isn't decremented for requests that don't need a file, so it might be larger than number of SQEs left. That in some circumstances makes us to grab more files that is needed so imposing extra put. Deaccount one ios_left for each request. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 8371adf commit 71b547c

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

fs/io_uring.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,6 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)
25812581
if (state->file) {
25822582
if (state->fd == fd) {
25832583
state->has_refs--;
2584-
state->ios_left--;
25852584
return state->file;
25862585
}
25872586
__io_state_file_put(state);
@@ -2591,8 +2590,7 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)
25912590
return NULL;
25922591

25932592
state->fd = fd;
2594-
state->ios_left--;
2595-
state->has_refs = state->ios_left;
2593+
state->has_refs = state->ios_left - 1;
25962594
return state->file;
25972595
}
25982596

@@ -6386,7 +6384,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
63866384
struct io_submit_state *state)
63876385
{
63886386
unsigned int sqe_flags;
6389-
int id;
6387+
int id, ret;
63906388

63916389
req->opcode = READ_ONCE(sqe->opcode);
63926390
req->user_data = READ_ONCE(sqe->user_data);
@@ -6432,7 +6430,9 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
64326430
if (!io_op_defs[req->opcode].needs_file)
64336431
return 0;
64346432

6435-
return io_req_set_file(state, req, READ_ONCE(sqe->fd));
6433+
ret = io_req_set_file(state, req, READ_ONCE(sqe->fd));
6434+
state->ios_left--;
6435+
return ret;
64366436
}
64376437

64386438
static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)

0 commit comments

Comments
 (0)