]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
io_uring: only initialize io_kiocb rsrc_nodes when needed
authorJens Axboe <axboe@kernel.dk>
Sat, 26 Oct 2024 16:46:10 +0000 (10:46 -0600)
committerJens Axboe <axboe@kernel.dk>
Sat, 2 Nov 2024 21:44:30 +0000 (15:44 -0600)
Add the empty node initializing to the preinit part of the io_kiocb
allocation, and reset them if they have been used.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/io_uring.c
io_uring/rsrc.h

index 9282d5fa45d321c1f8cee202fafbac68eac6d56a..60c947114fa39e0ae24d8dcbeb6c72316e09041e 100644 (file)
@@ -947,6 +947,8 @@ void io_req_defer_failed(struct io_kiocb *req, s32 res)
 static void io_preinit_req(struct io_kiocb *req, struct io_ring_ctx *ctx)
 {
        req->ctx = ctx;
+       req->rsrc_nodes[IORING_RSRC_FILE] = rsrc_empty_node;
+       req->rsrc_nodes[IORING_RSRC_BUFFER] = rsrc_empty_node;
        req->link = NULL;
        req->async_data = NULL;
        /* not necessary, but safer to zero */
@@ -2032,8 +2034,6 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
        req->flags = (__force io_req_flags_t) sqe_flags;
        req->cqe.user_data = READ_ONCE(sqe->user_data);
        req->file = NULL;
-       req->rsrc_nodes[IORING_RSRC_FILE] = rsrc_empty_node;
-       req->rsrc_nodes[IORING_RSRC_BUFFER] = rsrc_empty_node;
        req->task = current;
        req->cancel_seq_set = false;
 
index 323c3e78b864a00f8f9cda5f2885652070764360..48f712488f6b2fca4c6944fe6482eaa8bed10b6b 100644 (file)
@@ -81,8 +81,14 @@ static inline void io_put_rsrc_node(struct io_rsrc_node *node)
 
 static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
 {
-       io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_FILE]);
-       io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_BUFFER]);
+       if (req->rsrc_nodes[IORING_RSRC_FILE] != rsrc_empty_node) {
+               io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_FILE]);
+               req->rsrc_nodes[IORING_RSRC_FILE] = rsrc_empty_node;
+       }
+       if (req->rsrc_nodes[IORING_RSRC_BUFFER] != rsrc_empty_node) {
+               io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_BUFFER]);
+               req->rsrc_nodes[IORING_RSRC_BUFFER] = rsrc_empty_node;
+       }
 }
 
 static inline void io_req_assign_rsrc_node(struct io_kiocb *req,