]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
io_uring: remove io_preinit_req()
authorPavel Begunkov <asml.silence@gmail.com>
Tue, 6 May 2025 12:31:07 +0000 (13:31 +0100)
committerJens Axboe <axboe@kernel.dk>
Tue, 6 May 2025 16:11:23 +0000 (10:11 -0600)
Apart from setting ->ctx, io_preinit_req() zeroes a bunch of fields of a
request, from which only ->file_node is mandatory. Remove the function
and zero the entire request on first allocation. With that, we also need
to initialise ->ctx every time, which might be a good thing for
performance as now we're likely overwriting the entire cache line, and
so it can write combined and avoid RMW.

Suggested-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/ba5485dc913f1e275862ce88f5169d4ac4a33836.1746533807.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/io_uring.c
io_uring/notif.c

index 703251f6f4d810139de4b4ed3f65e0a494fe2aac..3d20f3b63443c66c2dcaa534d0bebb067cb49097 100644 (file)
@@ -927,22 +927,6 @@ void io_req_defer_failed(struct io_kiocb *req, s32 res)
        io_req_complete_defer(req);
 }
 
-/*
- * Don't initialise the fields below on every allocation, but do that in
- * advance and keep them valid across allocations.
- */
-static void io_preinit_req(struct io_kiocb *req, struct io_ring_ctx *ctx)
-{
-       req->ctx = ctx;
-       req->buf_node = NULL;
-       req->file_node = NULL;
-       req->link = NULL;
-       req->async_data = NULL;
-       /* not necessary, but safer to zero */
-       memset(&req->cqe, 0, sizeof(req->cqe));
-       memset(&req->big_cqe, 0, sizeof(req->big_cqe));
-}
-
 /*
  * A request might get retired back into the request caches even before opcode
  * handlers and io_issue_sqe() are done with it, e.g. inline completion path.
@@ -952,7 +936,7 @@ static void io_preinit_req(struct io_kiocb *req, struct io_ring_ctx *ctx)
 __cold bool __io_alloc_req_refill(struct io_ring_ctx *ctx)
        __must_hold(&ctx->uring_lock)
 {
-       gfp_t gfp = GFP_KERNEL | __GFP_NOWARN;
+       gfp_t gfp = GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO;
        void *reqs[IO_REQ_ALLOC_BATCH];
        int ret;
 
@@ -973,7 +957,6 @@ __cold bool __io_alloc_req_refill(struct io_ring_ctx *ctx)
        while (ret--) {
                struct io_kiocb *req = reqs[ret];
 
-               io_preinit_req(req, ctx);
                io_req_add_to_cache(req, ctx);
        }
        return true;
@@ -2049,7 +2032,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
        int personality;
        u8 opcode;
 
-       /* req is partially pre-initialised, see io_preinit_req() */
+       req->ctx = ctx;
        req->opcode = opcode = READ_ONCE(sqe->opcode);
        /* same numerical values with corresponding REQ_F_*, safe to copy */
        sqe_flags = READ_ONCE(sqe->flags);
index 7bd92538dccbc7e87742603f2c4b7caa606fe056..9a6f6e92d742428bb9d7c30c8b788f19ddab1501 100644 (file)
@@ -112,6 +112,7 @@ struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx)
 
        if (unlikely(!io_alloc_req(ctx, &notif)))
                return NULL;
+       notif->ctx = ctx;
        notif->opcode = IORING_OP_NOP;
        notif->flags = 0;
        notif->file = NULL;