On Wed, May 18, 2022 at 07:08:11PM -0700, Eric Biggers wrote: > On Wed, May 18, 2022 at 07:59:36PM -0600, Keith Busch wrote: > > I'm aware that spanning pages can cause bad splits on the bi_max_vecs > > condition, but I believe it's well handled here. Unless I'm terribly confused, > > which is certainly possible, I think you may have missed this part of the > > patch: > > > > @@ -1223,6 +1224,8 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) > > pages += entries_left * (PAGE_PTRS_PER_BVEC - 1); > > > > size = iov_iter_get_pages(iter, pages, LONG_MAX, nr_pages, &offset); > > + if (size > 0) > > + size = ALIGN_DOWN(size, queue_logical_block_size(q)); > > if (unlikely(size <= 0)) > > return size ? size : -EFAULT; > > > > That makes the total length of each "batch" of pages be a multiple of the > logical block size, but individual logical blocks within that batch can still be > divided into multiple bvecs in the loop just below it: I understand that, but the existing code conservatively assumes all pages are physically discontiguous and wouldn't have requested more pages if it didn't have enough bvecs for each of them: unsigned short nr_pages = bio->bi_max_vecs - bio->bi_vcnt; So with the segment alignment guarantee, and ensured available bvec space, the created bio will always be a logical block size multiple. If we need to split it later due to some other constraint, we'll only split on a logical block size, even if its in the middle of a bvec. > for (left = size, i = 0; left > 0; left -= len, i++) { > struct page *page = pages[i]; > > len = min_t(size_t, PAGE_SIZE - offset, left); > > if (__bio_try_merge_page(bio, page, len, offset, &same_page)) { > if (same_page) > put_page(page); > } else { > if (WARN_ON_ONCE(bio_full(bio, len))) { > bio_put_pages(pages + i, left, offset); > return -EINVAL; > } > __bio_add_page(bio, page, len, offset); > } > offset = 0; > } > > - Eric