From: Sean Anderson <seanga2@gmail.com>
To: Hannes Reinecke <hare@suse.de>, Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org
Cc: Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
linux-mtd@lists.infradead.org,
Zhihao Cheng <chengzhihao1@huawei.com>
Subject: Re: bio segment constraints
Date: Tue, 8 Apr 2025 09:57:50 -0400 [thread overview]
Message-ID: <25e201d2-aa80-1f1c-12fd-3b3f9c774e59@gmail.com> (raw)
In-Reply-To: <7b8c4805-a91f-4455-a021-e5d8b6078d8b@suse.de>
On 4/8/25 02:10, Hannes Reinecke wrote:
> On 4/7/25 16:14, Sean Anderson wrote:
>> On 4/7/25 03:10, Hannes Reinecke wrote:
>>> On 4/6/25 21:40, Sean Anderson wrote:
>>>> Hi all,
>>>>
>>>> I'm not really sure what guarantees the block layer makes regarding the
>>>> segments in a bio as part of a request submitted to a block driver. As
>>>> far as I can tell this is not documented anywhere. In particular,
>>>>
>>>> - Is bv_len aligned to SECTOR_SIZE?
>>>
>>> The block layer always uses a 512 byte sector size, so yes.
>>>
>>>> - To logical_sector_size?
>>>
>>> Not necessarily. Bvecs are a consecutive list of byte ranges which
>>> make up the data portion of a bio.
>>> The logical sector size is a property of the request queue, which is
>>> applied when a request is formed from one or several bios.
>>> For the request the overall length need to be a multiple of the logical
>>> sector size, but not necessarily the individual bios.
>>
>> Oh, so this is worse than I thought. So if you care about e.g. only submitting I/O in units of logical_block_size, you have to combine
> > segments across the entire request.>
> Well, yes, and no.
> You might be seeing a request with several bios, each having small
> bvecs. But in the driver you will want to use an iov iterator or map
> it into a sg list via blk_rq_map_sg(), and then iterate over that
> for submission.
>
> [ .. ]
>>>> - Can I somehow request to only get segments with bv_len aligned to
>>>> logical_sector_size? Or do I need to do my own coalescing and bounce
>>>> buffering for that?
>>>>
>>>
>>> The driver surely can. You should be able to set 'max_segment_size' to
>>> the logical block size, and that should give you what you want.
>>
>> But couldn't I get segments smaller than that? max_segment_size seems like
>> it would only restrict the maximum size, leaving the possibility open for
>> smaller segments.
>>
> As mentioned: individual segments might. The overall request still will adhere to the logical block size setting (ie it will never be smaller than the logical block size).
>
> Maybe have a look at drivers/mtd/ubi/block.c. There the driver will
> map the request onto a scatterlist, and then iterate over the sg entries
> to read in the data.
>
> Note: mapping onto a scatterlist will coalesce adjacent bvecs, so on the
> scatterlist you will find only contiguous segments which adhere to the
> logical block size linmitations.
How can this happen? From above, you could have a bvec where it contains only
one sector. So it will always be discontiguous in terms of the logical block size.
I've looked at ubiblock, and that only works for that driver because it's read-only.
The MTD API allows you to read unaligned buffers (although it's inefficient since
you may re-read the same page multiple times), but for writes the data must be
aligned to the page size.
I think the only way to solve this is to create a (mtd-)page-sized buffer and bounce
the incoming data in if the bvec is shorter (or if it's in high memory).
--Sean
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2025-04-08 14:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-06 19:40 bio segment constraints Sean Anderson
2025-04-07 7:07 ` Christoph Hellwig
2025-04-07 13:46 ` Keith Busch
2025-04-07 13:59 ` Christoph Hellwig
2025-04-07 15:52 ` Bart Van Assche
2025-04-07 13:59 ` Sean Anderson
2025-04-07 14:12 ` Christoph Hellwig
2025-04-07 7:10 ` Hannes Reinecke
2025-04-07 14:14 ` Sean Anderson
2025-04-08 6:10 ` Hannes Reinecke
2025-04-08 13:57 ` Sean Anderson [this message]
2025-04-08 14:33 ` Keith Busch
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=25e201d2-aa80-1f1c-12fd-3b3f9c774e59@gmail.com \
--to=seanga2@gmail.com \
--cc=axboe@kernel.dk \
--cc=chengzhihao1@huawei.com \
--cc=hare@suse.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.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