Re: [PATCHv3 3/8] block: align the bio after building it

From: Damien Le Moal
Date: Wed Aug 20 2025 - 03:10:21 EST


On 8/20/25 1:49 AM, Keith Busch wrote:
> From: Keith Busch <kbusch@xxxxxxxxxx>
>
> Instead of ensuring each vector is block size aligned while constructing
> the bio, just ensure the entire size is aligned after it's built. This
> makes getting bio pages more flexible to accepting device valid io
> vectors that would otherwise get rejected by alignment checks.
>
> Signed-off-by: Keith Busch <kbusch@xxxxxxxxxx>

[...]

> +/*
> + * Aligns the bio size to the len_align_mask, releasing any excessive bio vecs
> + * that __bio_iov_iter_get_pages may have inserted and reverts that length for
> + * the next iteration.
> + */
> +static int bio_align(struct bio *bio, struct iov_iter *iter,
> + unsigned len_align_mask)
> +{
> + size_t nbytes = bio->bi_iter.bi_size & len_align_mask;
> +
> + if (!nbytes)
> + return 0;
> +
> + iov_iter_revert(iter, nbytes);
> + bio->bi_iter.bi_size -= nbytes;
> + while (nbytes) {
> + struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
> +
> + if (nbytes < bv->bv_len) {
> + bv->bv_len -= nbytes;
> + nbytes = 0;

Nit: remove the "nbytes = 0" and do a break here ?

> + } else {
> + bio_release_page(bio, bv->bv_page);
> + bio->bi_vcnt--;
> + nbytes -= bv->bv_len;
> + }
> + }
> +
> + if (!bio->bi_iter.bi_size)
> + return -EFAULT;
> + return 0;
> +}
> +



--
Damien Le Moal
Western Digital Research