Skip to content

Commit 62906e8

Browse files
isilenceaxboe
authored andcommitted
io_uring: remove file batch-get optimisation
For requests with non-fixed files, instead of grabbing just one reference, we get by the number of left requests, so the following requests using the same file can take it without atomics. However, it's not all win. If there is one request in the middle not using files or having a fixed file, we'll need to put back the left references. Even worse if an application submits requests dealing with different files, it will do a put for each new request, so doubling the number of atomics needed. Also, even if not used, it's still takes some cycles in the submission path. If a file used many times, it rather makes sense to pre-register it, if not, we may fall in the described pitfall. So, this optimisation is a matter of use case. Go with the simpliest code-wise way, remove it. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 6294f36 commit 62906e8

File tree

1 file changed

+4
-49
lines changed

1 file changed

+4
-49
lines changed

fs/io_uring.c

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,6 @@ struct io_submit_state {
324324
/* inline/task_work completion list, under ->uring_lock */
325325
struct list_head free_list;
326326

327-
/*
328-
* File reference cache
329-
*/
330-
struct file *file;
331-
unsigned int fd;
332-
unsigned int file_refs;
333327
unsigned int ios_left;
334328
};
335329

@@ -1052,7 +1046,6 @@ static int __io_register_rsrc_update(struct io_ring_ctx *ctx, unsigned type,
10521046
unsigned nr_args);
10531047
static void io_clean_op(struct io_kiocb *req);
10541048
static struct file *io_file_get(struct io_ring_ctx *ctx,
1055-
struct io_submit_state *state,
10561049
struct io_kiocb *req, int fd, bool fixed);
10571050
static void __io_queue_sqe(struct io_kiocb *req);
10581051
static void io_rsrc_put_work(struct work_struct *work);
@@ -2583,40 +2576,6 @@ static void io_iopoll_req_issued(struct io_kiocb *req)
25832576
}
25842577
}
25852578

2586-
static inline void io_state_file_put(struct io_submit_state *state)
2587-
{
2588-
if (state->file_refs) {
2589-
fput_many(state->file, state->file_refs);
2590-
state->file_refs = 0;
2591-
}
2592-
}
2593-
2594-
/*
2595-
* Get as many references to a file as we have IOs left in this submission,
2596-
* assuming most submissions are for one file, or at least that each file
2597-
* has more than one submission.
2598-
*/
2599-
static struct file *__io_file_get(struct io_submit_state *state, int fd)
2600-
{
2601-
if (!state)
2602-
return fget(fd);
2603-
2604-
if (state->file_refs) {
2605-
if (state->fd == fd) {
2606-
state->file_refs--;
2607-
return state->file;
2608-
}
2609-
io_state_file_put(state);
2610-
}
2611-
state->file = fget_many(fd, state->ios_left);
2612-
if (unlikely(!state->file))
2613-
return NULL;
2614-
2615-
state->fd = fd;
2616-
state->file_refs = state->ios_left - 1;
2617-
return state->file;
2618-
}
2619-
26202579
static bool io_bdev_nowait(struct block_device *bdev)
26212580
{
26222581
return !bdev || blk_queue_nowait(bdev_get_queue(bdev));
@@ -3618,8 +3577,7 @@ static int __io_splice_prep(struct io_kiocb *req,
36183577
if (unlikely(sp->flags & ~valid_flags))
36193578
return -EINVAL;
36203579

3621-
sp->file_in = io_file_get(req->ctx, NULL, req,
3622-
READ_ONCE(sqe->splice_fd_in),
3580+
sp->file_in = io_file_get(req->ctx, req, READ_ONCE(sqe->splice_fd_in),
36233581
(sp->flags & SPLICE_F_FD_IN_FIXED));
36243582
if (!sp->file_in)
36253583
return -EBADF;
@@ -6356,10 +6314,9 @@ static inline struct file *io_file_get_fixed(struct io_ring_ctx *ctx,
63566314
}
63576315

63586316
static struct file *io_file_get_normal(struct io_ring_ctx *ctx,
6359-
struct io_submit_state *state,
63606317
struct io_kiocb *req, int fd)
63616318
{
6362-
struct file *file = __io_file_get(state, fd);
6319+
struct file *file = fget(fd);
63636320

63646321
trace_io_uring_file_get(ctx, fd);
63656322

@@ -6370,13 +6327,12 @@ static struct file *io_file_get_normal(struct io_ring_ctx *ctx,
63706327
}
63716328

63726329
static inline struct file *io_file_get(struct io_ring_ctx *ctx,
6373-
struct io_submit_state *state,
63746330
struct io_kiocb *req, int fd, bool fixed)
63756331
{
63766332
if (fixed)
63776333
return io_file_get_fixed(ctx, req, fd);
63786334
else
6379-
return io_file_get_normal(ctx, state, req, fd);
6335+
return io_file_get_normal(ctx, req, fd);
63806336
}
63816337

63826338
static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
@@ -6589,7 +6545,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
65896545
}
65906546

65916547
if (io_op_defs[req->opcode].needs_file) {
6592-
req->file = io_file_get(ctx, state, req, READ_ONCE(sqe->fd),
6548+
req->file = io_file_get(ctx, req, READ_ONCE(sqe->fd),
65936549
(sqe_flags & IOSQE_FIXED_FILE));
65946550
if (unlikely(!req->file))
65956551
ret = -EBADF;
@@ -6674,7 +6630,6 @@ static void io_submit_state_end(struct io_submit_state *state,
66746630
io_submit_flush_completions(ctx);
66756631
if (state->plug_started)
66766632
blk_finish_plug(&state->plug);
6677-
io_state_file_put(state);
66786633
}
66796634

66806635
/*

0 commit comments

Comments
 (0)