[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250825074606.GE20853@lst.de>
Date: Mon, 25 Aug 2025 09:46:06 +0200
From: Christoph Hellwig <hch@....de>
To: Keith Busch <kbusch@...a.com>
Cc: linux-block@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, snitzer@...nel.org, axboe@...nel.dk,
dw@...idwei.uk, brauner@...nel.org, hch@....de,
martin.petersen@...cle.com, djwong@...nel.org,
linux-xfs@...r.kernel.org, viro@...iv.linux.org.uk,
Keith Busch <kbusch@...nel.org>
Subject: Re: [PATCHv3 3/8] block: align the bio after building it
On Tue, Aug 19, 2025 at 09:49:17AM -0700, Keith Busch wrote:
> +/*
> + * 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)
I think the name is a bit too generic, as the function is very
specific to the __bio_iov_iter_get_pages-path only releasing of
pages, and also only aligns down. Maybe name it
bio_iov_iter_align_down or something like that?
> + 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;
> + } else {
> + bio_release_page(bio, bv->bv_page);
> + bio->bi_vcnt--;
> + nbytes -= bv->bv_len;
> + }
> + }
Minor nitpicks on the loop: it could be turned into a do { } while ()
loop, because nbytes is already checked above. And the condition that
sets nbytes to 0 could just break out of the loo.
> +
> + if (!bio->bi_iter.bi_size)
> + return -EFAULT;
And as bi_size doesn't change in the loop, this should probably move
above the loop.
Powered by blists - more mailing lists