Various minor cleanups
Jens Axboe
maintainercover Various minor cleanups
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.
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerPATCH 1/5 io_uring/kbuf: use 'ctx' consistently
There's already a local ctx variable, yet the ring lock and unlock helpers use req->ctx. use ctx consistently.
--- io_uring/kbuf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
io_uring/kbuf.c +2 -2
@@ -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; }
Signature · 1 line
2.53.0
Jens Axboe
maintainerPATCH 2/5 io_uring/poll: cache req->apoll_events
In reply to Jens AxboeAvoid a potential reload of ->apoll_events post vfs_poll() by caching it in a local variable.
--- io_uring/poll.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
io_uring/poll.c +5 -3
@@ -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 ; }
Signature · 1 line
2.53.0
Jens Axboe
maintainerPATCH 3/5 io_uring/net: use 'ctx' consistently
In reply to Jens AxboeThere's already a local ctx variable, use it for the io_is_compat() check as well.
--- io_uring/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/net.c +1 -1
@@ -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);
Signature · 1 line
2.53.0
Jens Axboe
maintainerPATCH 4/5 io_uring/rw: use cached file rather than req->file
In reply to Jens AxboeIn 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.
--- io_uring/rw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/rw.c +1 -1
@@ -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;
Signature · 1 line
2.53.0
Jens Axboe
maintainerPATCH 5/5 io_uring: avoid req->ctx reload in io_req_put_rsrc_nodes()
In reply to Jens AxboeCache 'ctx' to avoid it needing to get potentially reloaded.
--- io_uring/io_uring.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
io_uring/io_uring.c +4 -2
@@ -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,
Signature · 1 line
2.53.0