From: Caleb Sander Mateos <csander@purestorage.com>
To: Ming Lei <ming.lei@redhat.com>
Cc: huang-jl <huang-jl@deepseek.com>,
axboe@kernel.dk, io-uring@vger.kernel.org,
nj.shetty@samsung.com
Subject: Re: [PATCH v6.20] io_uring/rsrc: refactor io_import_kbuf() to use single loop
Date: Mon, 22 Dec 2025 14:56:02 -0500 [thread overview]
Message-ID: <CADUfDZr8vQ9AQSONNmQVyS-BwV1T_MxfGcAWWHwQ=Ci15gMYFg@mail.gmail.com> (raw)
In-Reply-To: <aUNmrSVkZEMk7xmF@fedora>
On Wed, Dec 17, 2025 at 9:28 PM Ming Lei <ming.lei@redhat.com> wrote:
>
> On Thu, Dec 18, 2025 at 09:42:43AM +0800, Ming Lei wrote:
> > On Wed, Dec 17, 2025 at 11:16:47PM +0800, huang-jl wrote:
> > > The code looks correct to me.
> > >
> > > > This simplifies the logic
> > >
> > > I'm not an expert in Linux development, but from my perspective, the
> > > original version seems simpler and more readable. The semantics of
> > > iov_iter_advance() are clear and well-understood.
> > >
> > > That said, I understand the appeal of merging them into a single loop.
> > >
> > > > and avoids the overhead of iov_iter_advance()
> > >
> > > Could you clarify what overhead you mean? If it's the function call
> > > overhead, I think the compiler would inline it anyway. The actual
> > > iteration work seems equivalent between both approaches.
> >
> > iov_iter_advance() is global function, and it can't be inline.
> >
> > Also single loop is more readable, cause ->iov_offset can be ignored easily.
> >
> > In theory, re-calculating nr_segs isn't necessary, it is just for avoiding
> > potential split, however not get idea how it is triggered. Nitesh didn't
> > mention the exact reason:
> >
> > https://lkml.org/lkml/2025/4/16/351
> >
> > I will look at the reason and see if it can be avoided.
>
> The reason is in both bio_iov_bvec_set() and bio_may_need_split().
nr_segs is not just a performance optimization, it's part of the
struct iov_iter API and used by iov_iter_extract_bvec_pages(), as
huang-jl pointed out. I don't think it's a good idea to assume that
nr_segs isn't going to be used and doesn't need to be calculated
correctly.
I think this patch is a definite improvement as it reduces the number
of assumptions about the internal structure of a bvec iov_iter. The
remaining assignment to iter->iov_offset is unfortunate, but I don't
see a great way around it.
My only suggestion would be to separate out a "find first bvec" loop
and a "find last bvec" loop to make the loop body less branchy.
Something like this:
const struct bio_vec *bvec = imu->bvec, bvec_start;
size_t remaining;
unsigned bvec_avail;
while (offset >= bvec->bv_len) {
offset -= bvec->bv_len;
bvec++;
}
bvec_avail = bvec->bv_len - offset;
bvec_start = bvec;
remaining = len;
while (remaining > bvec_avail) {
remaining -= bvec_avail;
bvec++;
bvec_avail = bvec->bv_len;
}
iov_iter_bvec(iter, ddir, start_bvec, bvec - start_bvec + 1, len);
iter->iov_offset = offset;
Best,
Caleb
>
> ->bi_vcnt doesn't make sense for cloned bio, and shouldn't be used as multiple
> segment hint.
>
> However, it also shows bio_split_rw() is too heavy.
>
>
> Thanks,
> Ming
>
next prev parent reply other threads:[~2025-12-22 19:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 12:31 [PATCH v6.20] io_uring/rsrc: refactor io_import_kbuf() to use single loop Ming Lei
2025-12-17 15:16 ` 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 [this message]
2025-12-23 2:30 ` Ming Lei
2025-12-23 19:56 ` Caleb Sander Mateos
2025-12-23 22:45 ` Ming Lei
2025-12-30 18:28 ` Caleb Sander Mateos
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='CADUfDZr8vQ9AQSONNmQVyS-BwV1T_MxfGcAWWHwQ=Ci15gMYFg@mail.gmail.com' \
--to=csander@purestorage.com \
--cc=axboe@kernel.dk \
--cc=huang-jl@deepseek.com \
--cc=io-uring@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=nj.shetty@samsung.com \
/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