Skip to content

Commit 2f2af35

Browse files
isilenceaxboe
authored andcommitted
io_uring/rsrc: inline switch_start fast path
Inline the part of io_rsrc_node_switch_start() that checks whether the cache is empty or not, as most of the times it will have some number of entries in there. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/9619c1717a0e01f22c5fce2f1ba2735f804da0f2.1681395792.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 0b222ee commit 2f2af35

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

io_uring/rsrc.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,13 @@ void io_rsrc_node_switch(struct io_ring_ctx *ctx,
230230
ctx->rsrc_node = backup;
231231
}
232232

233-
int io_rsrc_node_switch_start(struct io_ring_ctx *ctx)
233+
int __io_rsrc_node_switch_start(struct io_ring_ctx *ctx)
234234
{
235-
if (io_alloc_cache_empty(&ctx->rsrc_node_cache)) {
236-
struct io_rsrc_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
235+
struct io_rsrc_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
237236

238-
if (!node)
239-
return -ENOMEM;
240-
io_alloc_cache_put(&ctx->rsrc_node_cache, &node->cache);
241-
}
237+
if (!node)
238+
return -ENOMEM;
239+
io_alloc_cache_put(&ctx->rsrc_node_cache, &node->cache);
242240
return 0;
243241
}
244242

io_uring/rsrc.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void io_rsrc_put_tw(struct callback_head *cb);
6969
void io_rsrc_node_ref_zero(struct io_rsrc_node *node);
7070
void io_rsrc_put_work(struct work_struct *work);
7171
void io_rsrc_node_destroy(struct io_ring_ctx *ctx, struct io_rsrc_node *ref_node);
72-
int io_rsrc_node_switch_start(struct io_ring_ctx *ctx);
72+
int __io_rsrc_node_switch_start(struct io_ring_ctx *ctx);
7373
struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx);
7474
int io_queue_rsrc_removal(struct io_rsrc_data *data, unsigned idx,
7575
struct io_rsrc_node *node, void *rsrc);
@@ -111,6 +111,13 @@ static inline int io_scm_file_account(struct io_ring_ctx *ctx,
111111
return __io_scm_file_account(ctx, file);
112112
}
113113

114+
static inline int io_rsrc_node_switch_start(struct io_ring_ctx *ctx)
115+
{
116+
if (unlikely(io_alloc_cache_empty(&ctx->rsrc_node_cache)))
117+
return __io_rsrc_node_switch_start(ctx);
118+
return 0;
119+
}
120+
114121
int io_register_files_update(struct io_ring_ctx *ctx, void __user *arg,
115122
unsigned nr_args);
116123
int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,

0 commit comments

Comments
 (0)