From: Andreas Hindborg <a.hindborg@kernel.org>
To: "John Garry" <john.g.garry@oracle.com>
Cc: "Jens Axboe" <axboe@kernel.dk>,
"Oliver Mangold" <oliver.mangold@pm.me>,
<linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] block: set bi_vcnt when cloning bio
Date: Tue, 18 Feb 2025 19:20:57 +0100 [thread overview]
Message-ID: <874j0rf71y.fsf@kernel.org> (raw)
In-Reply-To: <464bc3f5-aef2-4e6b-b7cb-035077d1e3f4@oracle.com> (John Garry's message of "Tue, 18 Feb 2025 17:12:47 +0000")
"John Garry" <john.g.garry@oracle.com> writes:
> On 18/02/2025 11:40, Andreas Hindborg wrote:
>> "John Garry" <john.g.garry@oracle.com> writes:
>>
>>> On 15/02/2025 10:58, Andreas Hindborg wrote:
>>>> When cloning a bio, the `bio.bi_vcnt` field is not cloned. This is a
>>>> problem if users want to perform bounds checks on the `bio.bi_io_vec`
>>>> field.
>>>
>>> Is this fixing a potential problem? Or fixing a real issue?
>>
>> It is fixing a problem I ran into in rnull, the rust null block
>> implementation. When running with debug assertions enabled, a bound
>> check on `bi_io_vec` fails for split bio, because `bio_vcnt` becomes
>> zero in the cloned bio.
>>
>> I can work around this by not using a slice type to represent
>> `bi_io_vec` in rust, not a big deal.
>>
>> But I am genuinely curious if there is a reason for not setting
>> `bi_vcnt` during a clone.
>
> I think that it came from commit 59d276fe0 (with the addition of
> bio_clone_fast()), where we assume that the cloned bio is not having the
> bio_vec touched and so does not need to know bi_vcnt (or bi_max_vecs).
> And it is inefficient to needlessly set bi_vcnt then.
I see. That is a few days ago. I am quite confident that for modern
hardware and workloads, this assignment will not have any measurable
impact on performance.
Can we add it back?
I understand if you would prefer not to, since it is not strictly
necessary. But in that case, I would suggest patching the documentation
of `struct bio` something like this:
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -255,7 +255,8 @@ struct bio {
struct bio_integrity_payload *bi_integrity; /* data integrity */
#endif
- unsigned short bi_vcnt; /* how many bio_vec's */
+ unsigned short bi_vcnt; /* how many bio_vec's. Not valid if this bio is
+ a clone (flagged BIO_CLONED). */
/*
* Everything starting with bi_max_vecs will be preserved by bio_reset()
Best regards,
Andreas Hindborg
next prev parent reply other threads:[~2025-02-18 18:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-15 10:58 [PATCH] block: set bi_vcnt when cloning bio Andreas Hindborg
2025-02-18 10:40 ` John Garry
2025-02-18 11:40 ` Andreas Hindborg
2025-02-18 17:12 ` John Garry
2025-02-18 18:20 ` Andreas Hindborg [this message]
2025-02-18 22:21 ` Bart Van Assche
2025-02-19 14:19 ` John Garry
2025-02-20 6:11 ` Christoph Hellwig
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=874j0rf71y.fsf@kernel.org \
--to=a.hindborg@kernel.org \
--cc=axboe@kernel.dk \
--cc=john.g.garry@oracle.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oliver.mangold@pm.me \
/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