public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCHSET for-next 0/5] Various minor cleanups
@ 2026-03-17 20:35 Jens Axboe
  2026-03-17 20:35 ` [PATCH 1/5] io_uring/kbuf: use 'ctx' consistently Jens Axboe
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Jens Axboe @ 2026-03-17 20:35 UTC (permalink / raw)
  To: io-uring

Hi,

Nothing major in here, basically just being consistent with using
variables that are already cached. Depending on arch/compiler, these
also save a reload of a variable. I see different results on arm64 and
x86-64, but I think the cleanups stand by themselves either way.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] io_uring/kbuf: use 'ctx' consistently
  2026-03-17 20:35 [PATCHSET for-next 0/5] Various minor cleanups Jens Axboe
@ 2026-03-17 20:35 ` Jens Axboe
  2026-03-17 20:35 ` [PATCH 2/5] io_uring/poll: cache req->apoll_events Jens Axboe
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2026-03-17 20:35 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

There's already a local ctx variable, yet the ring lock and unlock
helpers use req->ctx. use ctx consistently.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/kbuf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index 26813b0f1dfd..ff81f32d8032 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -225,7 +225,7 @@ struct io_br_sel io_buffer_select(struct io_kiocb *req, size_t *len,
 	struct io_br_sel sel = { };
 	struct io_buffer_list *bl;
 
-	io_ring_submit_lock(req->ctx, issue_flags);
+	io_ring_submit_lock(ctx, issue_flags);
 
 	bl = io_buffer_get_list(ctx, buf_group);
 	if (likely(bl)) {
@@ -234,7 +234,7 @@ struct io_br_sel io_buffer_select(struct io_kiocb *req, size_t *len,
 		else
 			sel.addr = io_provided_buffer_select(req, len, bl);
 	}
-	io_ring_submit_unlock(req->ctx, issue_flags);
+	io_ring_submit_unlock(ctx, issue_flags);
 	return sel;
 }
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] io_uring/poll: cache req->apoll_events
  2026-03-17 20:35 [PATCHSET for-next 0/5] Various minor cleanups Jens Axboe
  2026-03-17 20:35 ` [PATCH 1/5] io_uring/kbuf: use 'ctx' consistently Jens Axboe
@ 2026-03-17 20:35 ` Jens Axboe
  2026-03-17 20:35 ` [PATCH 3/5] io_uring/net: use 'ctx' consistently Jens Axboe
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2026-03-17 20:35 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

Avoid a potential reload of ->apoll_events post vfs_poll() by caching it
in a local variable.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/poll.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/io_uring/poll.c b/io_uring/poll.c
index b671b84657d9..4175e63b9edf 100644
--- a/io_uring/poll.c
+++ b/io_uring/poll.c
@@ -276,8 +276,10 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
 
 		/* the mask was stashed in __io_poll_execute */
 		if (!req->cqe.res) {
-			struct poll_table_struct pt = { ._key = req->apoll_events };
-			req->cqe.res = vfs_poll(req->file, &pt) & req->apoll_events;
+			__poll_t events = req->apoll_events;
+			struct poll_table_struct pt = { ._key = events };
+
+			req->cqe.res = vfs_poll(req->file, &pt) & events;
 			/*
 			 * We got woken with a mask, but someone else got to
 			 * it first. The above vfs_poll() doesn't add us back
@@ -286,7 +288,7 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
 			 */
 			if (unlikely(!req->cqe.res)) {
 				/* Multishot armed need not reissue */
-				if (!(req->apoll_events & EPOLLONESHOT))
+				if (!(events & EPOLLONESHOT))
 					continue;
 				return IOU_POLL_REISSUE;
 			}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] io_uring/net: use 'ctx' consistently
  2026-03-17 20:35 [PATCHSET for-next 0/5] Various minor cleanups Jens Axboe
  2026-03-17 20:35 ` [PATCH 1/5] io_uring/kbuf: use 'ctx' consistently Jens Axboe
  2026-03-17 20:35 ` [PATCH 2/5] io_uring/poll: cache req->apoll_events Jens Axboe
@ 2026-03-17 20:35 ` Jens Axboe
  2026-03-17 20:35 ` [PATCH 4/5] io_uring/rw: use cached file rather than req->file Jens Axboe
  2026-03-17 20:35 ` [PATCH 5/5] io_uring: avoid req->ctx reload in io_req_put_rsrc_nodes() Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2026-03-17 20:35 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

There's already a local ctx variable, use it for the io_is_compat()
check as well.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/io_uring/net.c b/io_uring/net.c
index 3f9d08b78c21..b3f73883a24c 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1375,7 +1375,7 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	if (zc->msg_flags & MSG_DONTWAIT)
 		req->flags |= REQ_F_NOWAIT;
 
-	if (io_is_compat(req->ctx))
+	if (io_is_compat(ctx))
 		zc->msg_flags |= MSG_CMSG_COMPAT;
 
 	iomsg = io_msg_alloc_async(req);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] io_uring/rw: use cached file rather than req->file
  2026-03-17 20:35 [PATCHSET for-next 0/5] Various minor cleanups Jens Axboe
                   ` (2 preceding siblings ...)
  2026-03-17 20:35 ` [PATCH 3/5] io_uring/net: use 'ctx' consistently Jens Axboe
@ 2026-03-17 20:35 ` Jens Axboe
  2026-03-17 20:35 ` [PATCH 5/5] io_uring: avoid req->ctx reload in io_req_put_rsrc_nodes() Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2026-03-17 20:35 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

In io_rw_init_file(), req->file is cached in file, yet the former is
still being used when checking for O_DIRECT. As this is post setting
the kiocb flags, the compiler has to reload req->file. Just use the
locally cached file instead.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/rw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/io_uring/rw.c b/io_uring/rw.c
index 3bdb9914e673..046f76a71b9c 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -900,7 +900,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
 		 * We have a union of meta fields with wpq used for buffered-io
 		 * in io_async_rw, so fail it here.
 		 */
-		if (!(req->file->f_flags & O_DIRECT))
+		if (!(file->f_flags & O_DIRECT))
 			return -EOPNOTSUPP;
 		kiocb->ki_flags |= IOCB_HAS_METADATA;
 		kiocb->private = &io->meta;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] io_uring: avoid req->ctx reload in io_req_put_rsrc_nodes()
  2026-03-17 20:35 [PATCHSET for-next 0/5] Various minor cleanups Jens Axboe
                   ` (3 preceding siblings ...)
  2026-03-17 20:35 ` [PATCH 4/5] io_uring/rw: use cached file rather than req->file Jens Axboe
@ 2026-03-17 20:35 ` Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2026-03-17 20:35 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

Cache 'ctx' to avoid it needing to get potentially reloaded.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/io_uring.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index d703f0a8b315..6eaa21e09469 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1073,12 +1073,14 @@ void io_queue_next(struct io_kiocb *req)
 
 static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
 {
+	struct io_ring_ctx *ctx = req->ctx;
+
 	if (req->file_node) {
-		io_put_rsrc_node(req->ctx, req->file_node);
+		io_put_rsrc_node(ctx, req->file_node);
 		req->file_node = NULL;
 	}
 	if (req->flags & REQ_F_BUF_NODE)
-		io_put_rsrc_node(req->ctx, req->buf_node);
+		io_put_rsrc_node(ctx, req->buf_node);
 }
 
 static void io_free_batch_list(struct io_ring_ctx *ctx,
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-17 20:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17 20:35 [PATCHSET for-next 0/5] Various minor cleanups Jens Axboe
2026-03-17 20:35 ` [PATCH 1/5] io_uring/kbuf: use 'ctx' consistently Jens Axboe
2026-03-17 20:35 ` [PATCH 2/5] io_uring/poll: cache req->apoll_events Jens Axboe
2026-03-17 20:35 ` [PATCH 3/5] io_uring/net: use 'ctx' consistently Jens Axboe
2026-03-17 20:35 ` [PATCH 4/5] io_uring/rw: use cached file rather than req->file Jens Axboe
2026-03-17 20:35 ` [PATCH 5/5] io_uring: avoid req->ctx reload in io_req_put_rsrc_nodes() Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox