From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 8/8] io_uring: inline io_read()'s iovec freeing
Date: Tue, 2 Feb 2021 00:21:46 +0000 [thread overview]
Message-ID: <66e116c8982cf36b3774ec52a31ab29d975e6902.1612223954.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
io_read() has not the simpliest control flow with a lot of jumps and
it's hard to read. One of those is a out_free: label, which frees iovec.
However, from the middle of io_read() iovec is NULL'ed and so
kfree(iovec) is no-op, it leaves us with two place where we can inline
it and further clean up the code.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 31 +++++++++++++------------------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 3e648c0e6b8d..17a3736661c6 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3530,14 +3530,18 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
}
ret = rw_verify_area(READ, req->file, io_kiocb_ppos(kiocb), io_size);
- if (unlikely(ret))
- goto out_free;
+ if (unlikely(ret)) {
+ kfree(iovec);
+ return ret;
+ }
ret = io_iter_do_read(req, iter);
if (ret == -EIOCBQUEUED) {
- ret = 0;
- goto out_free;
+ /* it's faster to check here then delegate to kfree */
+ if (iovec)
+ kfree(iovec);
+ return 0;
} else if (ret == -EAGAIN) {
/* IOPOLL retry should happen for io-wq threads */
if (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL))
@@ -3562,8 +3566,6 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
return ret2;
rw = req->async_data;
- /* it's copied and will be cleaned with ->io */
- iovec = NULL;
/* now use our persistent iterator, if we aren't already */
iter = &rw->iter;
retry:
@@ -3582,21 +3584,14 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
* do, then just retry at the new offset.
*/
ret = io_iter_do_read(req, iter);
- if (ret == -EIOCBQUEUED) {
- ret = 0;
- goto out_free;
- } else if (ret > 0 && ret < io_size) {
- /* we got some bytes, but not all. retry. */
+ if (ret == -EIOCBQUEUED)
+ return 0;
+ /* we got some bytes, but not all. retry. */
+ if (ret > 0 && ret < io_size)
goto retry;
- }
done:
kiocb_done(kiocb, ret, cs);
- ret = 0;
-out_free:
- /* it's reportedly faster than delegating the null check to kfree() */
- if (iovec)
- kfree(iovec);
- return ret;
+ return 0;
}
static int io_write_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
--
2.24.0
next prev parent reply other threads:[~2021-02-02 0:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-02 0:21 [PATCH 0/8] a second pack of 5.12 cleanups Pavel Begunkov
2021-02-02 0:21 ` [PATCH 1/8] io_uring: deduplicate core cancellations sequence Pavel Begunkov
2021-02-02 0:21 ` [PATCH 2/8] io_uring: refactor scheduling in io_cqring_wait Pavel Begunkov
2021-02-02 0:21 ` [PATCH 3/8] io_uring: refactor io_cqring_wait Pavel Begunkov
2021-02-02 0:21 ` [PATCH 4/8] io_uring: refactor io_read for unsupported nowait Pavel Begunkov
2021-02-02 0:21 ` [PATCH 5/8] io_uring: further simplify do_read error parsing Pavel Begunkov
2021-02-02 0:21 ` [PATCH 6/8] io_uring: let io_setup_async_rw take care of iovec Pavel Begunkov
2021-02-02 0:21 ` [PATCH 7/8] io_uring: don't forget to adjust io_size Pavel Begunkov
2021-02-02 0:21 ` Pavel Begunkov [this message]
2021-02-04 13:52 ` [PATCH 0/8] a second pack of 5.12 cleanups Pavel Begunkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=66e116c8982cf36b3774ec52a31ab29d975e6902.1612223954.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox