Skip to content

Commit 3f30238

Browse files
committed
io_uring/rsrc: improve code generation for fixed file assignment
For the normal read/write path, we have already locked the ring submission side when assigning the file. This causes branch mispredictions when we then check and try and lock again in io_req_set_rsrc_node(). As this is a very hot path, this matters. Add a basic helper that already assumes we already have it locked, and use that in io_file_get_fixed(). Signed-off-by: Jens Axboe <[email protected]>
1 parent fe80eb1 commit 3f30238

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

io_uring/io_uring.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,9 +2000,10 @@ inline struct file *io_file_get_fixed(struct io_kiocb *req, int fd,
20002000
goto out;
20012001
fd = array_index_nospec(fd, ctx->nr_user_files);
20022002
slot = io_fixed_file_slot(&ctx->file_table, fd);
2003-
file = io_slot_file(slot);
2003+
if (!req->rsrc_node)
2004+
__io_req_set_rsrc_node(req, ctx);
20042005
req->flags |= io_slot_flags(slot);
2005-
io_req_set_rsrc_node(req, ctx, 0);
2006+
file = io_slot_file(slot);
20062007
out:
20072008
io_ring_submit_unlock(ctx, issue_flags);
20082009
return file;

io_uring/rsrc.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,21 @@ static inline void io_charge_rsrc_node(struct io_ring_ctx *ctx,
102102
node->refs++;
103103
}
104104

105+
static inline void __io_req_set_rsrc_node(struct io_kiocb *req,
106+
struct io_ring_ctx *ctx)
107+
{
108+
lockdep_assert_held(&ctx->uring_lock);
109+
req->rsrc_node = ctx->rsrc_node;
110+
io_charge_rsrc_node(ctx, ctx->rsrc_node);
111+
}
112+
105113
static inline void io_req_set_rsrc_node(struct io_kiocb *req,
106114
struct io_ring_ctx *ctx,
107115
unsigned int issue_flags)
108116
{
109117
if (!req->rsrc_node) {
110118
io_ring_submit_lock(ctx, issue_flags);
111-
112-
lockdep_assert_held(&ctx->uring_lock);
113-
114-
req->rsrc_node = ctx->rsrc_node;
115-
io_charge_rsrc_node(ctx, ctx->rsrc_node);
119+
__io_req_set_rsrc_node(req, ctx);
116120
io_ring_submit_unlock(ctx, issue_flags);
117121
}
118122
}

0 commit comments

Comments
 (0)