bio integrity's bvec is same with the normal bvec, and it is pretty straight-forward to enable multi-page bvec for bio integrity because bio_for_each_integrity_vec() is based on for_each_bvec() which can handle multi-page bvec well. The integrity buffer can't be very big, for example, the max sectors for one bio is 2560, one sector may take at most 8bytes for integrity info, so the max size of integrity buffer is just 20k(<=5 pages). So not like normal multi-page bvec convertion, this patch doesn't switch blk_rq_map_integrity_sg() to iterate over multi-page bvec. Cc: Martin K . Petersen <martin.petersen@xxxxxxxxxx>, Cc: Christoph Hellwig <hch@xxxxxx>, Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx> --- block/bio-integrity.c | 18 ++++++++++++------ block/bio.c | 25 ------------------------- block/blk.h | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 1b633a3526d4..ba9d145315ed 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -143,18 +143,24 @@ int bio_integrity_add_page(struct bio *bio, struct page *page, return 0; } - iv = bip->bip_vec + bip->bip_vcnt; + if (bip->bip_vcnt) { + iv = bip->bip_vec + bip->bip_vcnt - 1; - if (bip->bip_vcnt && - bvec_gap_to_prev(bio->bi_disk->queue, - &bip->bip_vec[bip->bip_vcnt - 1], offset)) - return 0; + if (bvec_gap_to_prev(bio->bi_disk->queue, iv, offset)) + return 0; + if (page_is_mergeable(iv, page, len, offset, false)) { + iv->bv_len += len; + goto done; + } + } + + iv = bip->bip_vec + bip->bip_vcnt; iv->bv_page = page; iv->bv_len = len; iv->bv_offset = offset; bip->bip_vcnt++; - + done: return len; } EXPORT_SYMBOL(bio_integrity_add_page); diff --git a/block/bio.c b/block/bio.c index c81ed2dfee53..89d1aa119a33 100644 --- a/block/bio.c +++ b/block/bio.c @@ -647,31 +647,6 @@ struct bio *bio_clone_fast(struct bio *bio, gfp_t gfp_mask, struct bio_set *bs) } EXPORT_SYMBOL(bio_clone_fast); -static inline bool page_is_mergeable(const struct bio_vec *bv, - struct page *page, unsigned int len, unsigned int off, - bool same_page) -{ - phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) + - bv->bv_offset + bv->bv_len - 1; - phys_addr_t page_addr = page_to_phys(page); - - if (vec_end_addr + 1 != page_addr + off) - return false; - if (xen_domain() && !xen_biovec_phys_mergeable(bv, page)) - return false; - - if ((vec_end_addr & PAGE_MASK) != page_addr) { - if (same_page) - return false; - if (pfn_to_page(PFN_DOWN(vec_end_addr)) + 1 != page) - return false; - } - - WARN_ON_ONCE(same_page && (len + off) > PAGE_SIZE); - - return true; -} - /* * Check if the @page can be added to the current segment(@bv), and make * sure to call it only if page_is_mergeable(@bv, @page) is true diff --git a/block/blk.h b/block/blk.h index e27fd1512e4b..1df54fa04edf 100644 --- a/block/blk.h +++ b/block/blk.h @@ -324,4 +324,30 @@ void blk_queue_free_zone_bitmaps(struct request_queue *q); static inline void blk_queue_free_zone_bitmaps(struct request_queue *q) {} #endif +static inline bool page_is_mergeable(const struct bio_vec *bv, + struct page *page, unsigned int len, unsigned int off, + bool same_page) +{ + phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) + + bv->bv_offset + bv->bv_len - 1; + phys_addr_t page_addr = page_to_phys(page); + + if (vec_end_addr + 1 != page_addr + off) + return false; + if (xen_domain() && !xen_biovec_phys_mergeable(bv, page)) + return false; + + if ((vec_end_addr & PAGE_MASK) != page_addr) { + if (same_page) + return false; + if (pfn_to_page(PFN_DOWN(vec_end_addr)) + 1 != page) + return false; + } + + WARN_ON_ONCE(same_page && (len + off) > PAGE_SIZE); + + return true; +} + + #endif /* BLK_INTERNAL_H */ -- 2.9.5