Skip to contentSkip to conversation

block: remove the same_page output argument to bvec_try_merge_page

PATCH Applied Christoph Hellwig 2 participants 2 messages May 12, 2025 – May 13, 2025 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: remove the same_page output argument to bvec_try_merge_page

bvec_try_merge_page currently returns if the added page fragment is within the same page as the last page in the last current bio_vec.

This information is used by __bio_iov_iter_get_pages so that we always have a single folio pin per page even when the page is split over multiple __bio_iov_iter_get_pages calls.

Threading this through the entire lowlevel add page to bio logic is annoying and inefficient and leads to less code sharing than otherwise possible. Instead add code to __bio_iov_iter_get_pages that checks if the bio_vecs did not change and thus a merge into the last segment must have happened, and if there is an offset into the page for the currently added fragment, because if yes we must have already had a previous fragment of the same page in the last bio_vec. While this is still a bit ugly, it keeps the logic in the one place that needs it and allows for more code sharing.

---
 block/bio-integrity.c |  4 +---
 block/bio.c           | 55 ++++++++++++++++++-------------------------
 block/blk.h           |  3 +--
 3 files changed, 25 insertions(+), 37 deletions(-)
block/bio-integrity.c +1 -3
index 43ef6bd06c85..cb94e9be26dc 100644
@@ -127,10 +127,8 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
 
 	if (bip->bip_vcnt > 0) {
 		struct bio_vec *bv = &bip->bip_vec[bip->bip_vcnt - 1];
-		bool same_page = false;
 
-		if (bvec_try_merge_hw_page(q, bv, page, len, offset,
-					   &same_page)) {
+		if (bvec_try_merge_hw_page(q, bv, page, len, offset)) {
 			bip->bip_iter.bi_size += len;
 			return len;
 		}
block/bio.c +23 -32

109 lines not on this page · raw message

block/blk.h +1 -2
index 665b3d1fb504..eb0fccbfdea6 100644
@@ -103,8 +103,7 @@ struct bio_vec *bvec_alloc(mempool_t *pool, unsigned short *nr_vecs,
 void bvec_free(mempool_t *pool, struct bio_vec *bv, unsigned short nr_vecs);
 
 bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
-		struct page *page, unsigned len, unsigned offset,
-		bool *same_page);
+		struct page *page, unsigned len, unsigned offset);
 
 static inline bool biovec_phys_mergeable(struct request_queue *q,
 		struct bio_vec *vec1, struct bio_vec *vec2)
Signature · 1 line
2.47.2
maintainer Applied
#1 lore raw
Quoted 8 lines · Christoph Hellwig

bvec_try_merge_page currently returns if the added page fragment is within the same page as the last page in the last current bio_vec.

This information is used by __bio_iov_iter_get_pages so that we always have a single folio pin per page even when the page is split over multiple __bio_iov_iter_get_pages calls.

[...]

Applied, thanks!

[1/1] block: remove the same_page output argument to bvec_try_merge_page

      commit: 77fd359b6dfdba58f476d5c17097bab024af9467

Best regards,

Signature · 1 line
Jens Axboe