io_uring/rsrc: inline switch_start fast path
authorPavel Begunkov <asml.silence@gmail.com>
Thu, 13 Apr 2023 14:28:11 +0000 (15:28 +0100)
committerJens Axboe <axboe@kernel.dk>
Sat, 15 Apr 2023 20:44:57 +0000 (14:44 -0600)
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 <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/9619c1717a0e01f22c5fce2f1ba2735f804da0f2.1681395792.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/rsrc.c
io_uring/rsrc.h

index 5415a18844e0b188a394944a49588a6e1b5e522b..bfa0b382c6c6a6e07f37c777797e3aac532d1281 100644 (file)
@@ -230,15 +230,13 @@ void io_rsrc_node_switch(struct io_ring_ctx *ctx,
        ctx->rsrc_node = backup;
 }
 
-int io_rsrc_node_switch_start(struct io_ring_ctx *ctx)
+int __io_rsrc_node_switch_start(struct io_ring_ctx *ctx)
 {
-       if (io_alloc_cache_empty(&ctx->rsrc_node_cache)) {
-               struct io_rsrc_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
+       struct io_rsrc_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
 
-               if (!node)
-                       return -ENOMEM;
-               io_alloc_cache_put(&ctx->rsrc_node_cache, &node->cache);
-       }
+       if (!node)
+               return -ENOMEM;
+       io_alloc_cache_put(&ctx->rsrc_node_cache, &node->cache);
        return 0;
 }
 
index 5dd2fcb2806962304427fbccd455aac0959c041d..732496afed4cebc6269a38a67bab6c5267a65a92 100644 (file)
@@ -69,7 +69,7 @@ void io_rsrc_put_tw(struct callback_head *cb);
 void io_rsrc_node_ref_zero(struct io_rsrc_node *node);
 void io_rsrc_put_work(struct work_struct *work);
 void io_rsrc_node_destroy(struct io_ring_ctx *ctx, struct io_rsrc_node *ref_node);
-int io_rsrc_node_switch_start(struct io_ring_ctx *ctx);
+int __io_rsrc_node_switch_start(struct io_ring_ctx *ctx);
 struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx);
 int io_queue_rsrc_removal(struct io_rsrc_data *data, unsigned idx,
                          struct io_rsrc_node *node, void *rsrc);
@@ -111,6 +111,13 @@ static inline int io_scm_file_account(struct io_ring_ctx *ctx,
        return __io_scm_file_account(ctx, file);
 }
 
+static inline int io_rsrc_node_switch_start(struct io_ring_ctx *ctx)
+{
+       if (unlikely(io_alloc_cache_empty(&ctx->rsrc_node_cache)))
+               return __io_rsrc_node_switch_start(ctx);
+       return 0;
+}
+
 int io_register_files_update(struct io_ring_ctx *ctx, void __user *arg,
                             unsigned nr_args);
 int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,