From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, io-uring@vger.kernel.org
Cc: Ming Lei <ming.lei@redhat.com>, huang-jl <huang-jl@deepseek.com>,
Caleb Sander Mateos <csander@purestorage.com>
Subject: [PATCH v6.20] io_uring/rsrc: refactor io_import_kbuf() to use single loop
Date: Wed, 17 Dec 2025 20:31:56 +0800 [thread overview]
Message-ID: <20251217123156.1100620-1-ming.lei@redhat.com> (raw)
Replace the iov_iter_advance() call and the separate loop for
calculating nr_segs with a single unified loop that iterates over
bvecs to determine the starting position, iov_offset, and nr_segs.
This simplifies the logic and avoids the overhead of iov_iter_advance().
Cc: huang-jl <huang-jl@deepseek.com>
Cc: Caleb Sander Mateos <csander@purestorage.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
io_uring/rsrc.c | 38 ++++++++++++++++++++++++++++----------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index a63474b331bf..f7ee146d5330 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -1051,20 +1051,38 @@ static int validate_fixed_range(u64 buf_addr, size_t len,
static int io_import_kbuf(int ddir, struct iov_iter *iter,
struct io_mapped_ubuf *imu, size_t len, size_t offset)
{
- size_t count = len + offset;
-
- iov_iter_bvec(iter, ddir, imu->bvec, imu->nr_bvecs, count);
- iov_iter_advance(iter, offset);
+ const struct bio_vec *bvec = imu->bvec;
+ size_t iov_offset = 0;
+ unsigned int nr_segs = 0;
+ size_t remaining = len;
+ unsigned int i;
- if (count < imu->len) {
- const struct bio_vec *bvec = iter->bvec;
+ /* Single loop to calculate starting bvec, iov_offset, and nr_segs */
+ for (i = 0; i < imu->nr_bvecs; i++, bvec++) {
+ size_t bvec_avail;
- while (len > bvec->bv_len) {
- len -= bvec->bv_len;
- bvec++;
+ /* Skip offset bytes to find starting position */
+ if (offset > 0) {
+ if (offset >= bvec->bv_len) {
+ offset -= bvec->bv_len;
+ continue;
+ }
+ iov_offset = offset;
+ bvec_avail = bvec->bv_len - offset;
+ offset = 0;
+ } else {
+ bvec_avail = bvec->bv_len;
}
- iter->nr_segs = 1 + bvec - iter->bvec;
+
+ /* Count bvecs for len bytes */
+ nr_segs++;
+ if (remaining <= bvec_avail)
+ break;
+ remaining -= bvec_avail;
}
+
+ iov_iter_bvec(iter, ddir, bvec - nr_segs + 1, nr_segs, len);
+ iter->iov_offset = iov_offset;
return 0;
}
--
2.47.1
next reply other threads:[~2025-12-17 12:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 12:31 Ming Lei [this message]
2025-12-17 15:16 ` [PATCH v6.20] io_uring/rsrc: refactor io_import_kbuf() to use single loop huang-jl
2025-12-18 1:42 ` Ming Lei
2025-12-18 2:27 ` Ming Lei
2025-12-18 3:19 ` huang-jl
2025-12-22 19:56 ` Caleb Sander Mateos
2025-12-23 2:30 ` Ming Lei
2025-12-23 19:56 ` Caleb Sander Mateos
2025-12-23 22:45 ` Ming Lei
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=20251217123156.1100620-1-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.com \
--cc=huang-jl@deepseek.com \
--cc=io-uring@vger.kernel.org \
/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