Skip to content

Commit 07173c3

Browse files
Ming Leiaxboe
Ming Lei
authored andcommitted
block: enable multipage bvecs
This patch pulls the trigger for multi-page bvecs. Reviewed-by: Omar Sandoval <[email protected]> Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 6dc4f10 commit 07173c3

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

block/bio.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ EXPORT_SYMBOL(bio_add_pc_page);
753753
* @page: page to add
754754
* @len: length of the data to add
755755
* @off: offset of the data in @page
756+
* @same_page: if %true only merge if the new data is in the same physical
757+
* page as the last segment of the bio.
756758
*
757759
* Try to add the data at @page + @off to the last bvec of @bio. This is a
758760
* a useful optimisation for file systems with a block size smaller than the
@@ -761,19 +763,25 @@ EXPORT_SYMBOL(bio_add_pc_page);
761763
* Return %true on success or %false on failure.
762764
*/
763765
bool __bio_try_merge_page(struct bio *bio, struct page *page,
764-
unsigned int len, unsigned int off)
766+
unsigned int len, unsigned int off, bool same_page)
765767
{
766768
if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
767769
return false;
768770

769771
if (bio->bi_vcnt > 0) {
770772
struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
773+
phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) +
774+
bv->bv_offset + bv->bv_len - 1;
775+
phys_addr_t page_addr = page_to_phys(page);
771776

772-
if (page == bv->bv_page && off == bv->bv_offset + bv->bv_len) {
773-
bv->bv_len += len;
774-
bio->bi_iter.bi_size += len;
775-
return true;
776-
}
777+
if (vec_end_addr + 1 != page_addr + off)
778+
return false;
779+
if (same_page && (vec_end_addr & PAGE_MASK) != page_addr)
780+
return false;
781+
782+
bv->bv_len += len;
783+
bio->bi_iter.bi_size += len;
784+
return true;
777785
}
778786
return false;
779787
}
@@ -819,7 +827,7 @@ EXPORT_SYMBOL_GPL(__bio_add_page);
819827
int bio_add_page(struct bio *bio, struct page *page,
820828
unsigned int len, unsigned int offset)
821829
{
822-
if (!__bio_try_merge_page(bio, page, len, offset)) {
830+
if (!__bio_try_merge_page(bio, page, len, offset, false)) {
823831
if (bio_full(bio))
824832
return 0;
825833
__bio_add_page(bio, page, len, offset);

fs/iomap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
318318
*/
319319
sector = iomap_sector(iomap, pos);
320320
if (ctx->bio && bio_end_sector(ctx->bio) == sector) {
321-
if (__bio_try_merge_page(ctx->bio, page, plen, poff))
321+
if (__bio_try_merge_page(ctx->bio, page, plen, poff, true))
322322
goto done;
323323
is_contig = true;
324324
}
@@ -349,7 +349,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
349349
ctx->bio->bi_end_io = iomap_read_end_io;
350350
}
351351

352-
__bio_add_page(ctx->bio, page, plen, poff);
352+
bio_add_page(ctx->bio, page, plen, poff);
353353
done:
354354
/*
355355
* Move the caller beyond our range so that it keeps making progress.

fs/xfs/xfs_aops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,12 @@ xfs_add_to_ioend(
616616
bdev, sector);
617617
}
618618

619-
if (!__bio_try_merge_page(wpc->ioend->io_bio, page, len, poff)) {
619+
if (!__bio_try_merge_page(wpc->ioend->io_bio, page, len, poff, true)) {
620620
if (iop)
621621
atomic_inc(&iop->write_count);
622622
if (bio_full(wpc->ioend->io_bio))
623623
xfs_chain_bio(wpc->ioend, wbc, bdev, sector);
624-
__bio_add_page(wpc->ioend->io_bio, page, len, poff);
624+
bio_add_page(wpc->ioend->io_bio, page, len, poff);
625625
}
626626

627627
wpc->ioend->io_size += len;

include/linux/bio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
441441
extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
442442
unsigned int, unsigned int);
443443
bool __bio_try_merge_page(struct bio *bio, struct page *page,
444-
unsigned int len, unsigned int off);
444+
unsigned int len, unsigned int off, bool same_page);
445445
void __bio_add_page(struct bio *bio, struct page *page,
446446
unsigned int len, unsigned int off);
447447
int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter);

0 commit comments

Comments
 (0)