Skip to content

Commit 3dccdae

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: merge BIOVEC_SEG_BOUNDARY into biovec_phys_mergeable
These two checks should always be performed together, so merge them into a single helper. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 0e25339 commit 3dccdae

5 files changed

Lines changed: 17 additions & 48 deletions

File tree

‎block/bio.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,7 @@ int bio_add_pc_page(struct request_queue *q, struct bio *bio, struct page
731731
}
732732

733733
/* If we may be able to merge these biovecs, force a recount */
734-
if (bio->bi_vcnt > 1 &&
735-
biovec_phys_mergeable(bvec - 1, bvec) &&
736-
BIOVEC_SEG_BOUNDARY(q, bvec - 1, bvec))
734+
if (bio->bi_vcnt > 1 && biovec_phys_mergeable(q, bvec - 1, bvec))
737735
bio_clear_flag(bio, BIO_SEG_VALID);
738736

739737
done:

‎block/blk-integrity.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ int blk_rq_count_integrity_sg(struct request_queue *q, struct bio *bio)
4949
bio_for_each_integrity_vec(iv, bio, iter) {
5050

5151
if (prev) {
52-
if (!biovec_phys_mergeable(&ivprv, &iv))
52+
if (!biovec_phys_mergeable(q, &ivprv, &iv))
5353
goto new_segment;
54-
55-
if (!BIOVEC_SEG_BOUNDARY(q, &ivprv, &iv))
56-
goto new_segment;
57-
5854
if (seg_size + iv.bv_len > queue_max_segment_size(q))
5955
goto new_segment;
6056

@@ -95,12 +91,8 @@ int blk_rq_map_integrity_sg(struct request_queue *q, struct bio *bio,
9591
bio_for_each_integrity_vec(iv, bio, iter) {
9692

9793
if (prev) {
98-
if (!biovec_phys_mergeable(&ivprv, &iv))
94+
if (!biovec_phys_mergeable(q, &ivprv, &iv))
9995
goto new_segment;
100-
101-
if (!BIOVEC_SEG_BOUNDARY(q, &ivprv, &iv))
102-
goto new_segment;
103-
10496
if (sg->length + iv.bv_len > queue_max_segment_size(q))
10597
goto new_segment;
10698

‎block/blk-merge.c‎

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ static inline bool bios_segs_mergeable(struct request_queue *q,
2121
struct bio *prev, struct bio_vec *prev_last_bv,
2222
struct bio_vec *next_first_bv)
2323
{
24-
if (!biovec_phys_mergeable(prev_last_bv, next_first_bv))
25-
return false;
26-
if (!BIOVEC_SEG_BOUNDARY(q, prev_last_bv, next_first_bv))
24+
if (!biovec_phys_mergeable(q, prev_last_bv, next_first_bv))
2725
return false;
2826
if (prev->bi_seg_back_size + next_first_bv->bv_len >
2927
queue_max_segment_size(q))
@@ -199,9 +197,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
199197
if (bvprvp && blk_queue_cluster(q)) {
200198
if (seg_size + bv.bv_len > queue_max_segment_size(q))
201199
goto new_segment;
202-
if (!biovec_phys_mergeable(bvprvp, &bv))
203-
goto new_segment;
204-
if (!BIOVEC_SEG_BOUNDARY(q, bvprvp, &bv))
200+
if (!biovec_phys_mergeable(q, bvprvp, &bv))
205201
goto new_segment;
206202

207203
seg_size += bv.bv_len;
@@ -332,9 +328,7 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
332328
if (seg_size + bv.bv_len
333329
> queue_max_segment_size(q))
334330
goto new_segment;
335-
if (!biovec_phys_mergeable(&bvprv, &bv))
336-
goto new_segment;
337-
if (!BIOVEC_SEG_BOUNDARY(q, &bvprv, &bv))
331+
if (!biovec_phys_mergeable(q, &bvprv, &bv))
338332
goto new_segment;
339333

340334
seg_size += bv.bv_len;
@@ -414,17 +408,7 @@ static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
414408
bio_get_last_bvec(bio, &end_bv);
415409
bio_get_first_bvec(nxt, &nxt_bv);
416410

417-
if (!biovec_phys_mergeable(&end_bv, &nxt_bv))
418-
return 0;
419-
420-
/*
421-
* bio and nxt are contiguous in memory; check if the queue allows
422-
* these two to be merged into one
423-
*/
424-
if (BIOVEC_SEG_BOUNDARY(q, &end_bv, &nxt_bv))
425-
return 1;
426-
427-
return 0;
411+
return biovec_phys_mergeable(q, &end_bv, &nxt_bv);
428412
}
429413

430414
static inline void
@@ -438,10 +422,7 @@ __blk_segment_map_sg(struct request_queue *q, struct bio_vec *bvec,
438422
if (*sg && *cluster) {
439423
if ((*sg)->length + nbytes > queue_max_segment_size(q))
440424
goto new_segment;
441-
442-
if (!biovec_phys_mergeable(bvprv, bvec))
443-
goto new_segment;
444-
if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bvec))
425+
if (!biovec_phys_mergeable(q, bvprv, bvec))
445426
goto new_segment;
446427

447428
(*sg)->length += nbytes;

‎block/blk.h‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,19 @@ static inline void blk_queue_enter_live(struct request_queue *q)
153153
#define ARCH_BIOVEC_PHYS_MERGEABLE(vec1, vec2) true
154154
#endif
155155

156-
static inline bool biovec_phys_mergeable(const struct bio_vec *vec1,
157-
const struct bio_vec *vec2)
156+
static inline bool biovec_phys_mergeable(struct request_queue *q,
157+
struct bio_vec *vec1, struct bio_vec *vec2)
158158
{
159-
if (bvec_to_phys(vec1) + vec1->bv_len != bvec_to_phys(vec2))
159+
unsigned long mask = queue_segment_boundary(q);
160+
phys_addr_t addr1 = bvec_to_phys(vec1);
161+
phys_addr_t addr2 = bvec_to_phys(vec2);
162+
163+
if (addr1 + vec1->bv_len != addr2)
160164
return false;
161165
if (!ARCH_BIOVEC_PHYS_MERGEABLE(vec1, vec2))
162166
return false;
167+
if ((addr1 | mask) != ((addr2 + vec2->bv_len - 1) | mask))
168+
return false;
163169
return true;
164170
}
165171

‎include/linux/bio.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,6 @@ static inline bool bio_full(struct bio *bio)
137137
*/
138138
#define bvec_to_phys(bv) (page_to_phys((bv)->bv_page) + (unsigned long) (bv)->bv_offset)
139139

140-
/*
141-
* merge helpers etc
142-
*/
143-
#define __BIO_SEG_BOUNDARY(addr1, addr2, mask) \
144-
(((addr1) | (mask)) == (((addr2) - 1) | (mask)))
145-
#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \
146-
__BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, queue_segment_boundary((q)))
147-
148140
/*
149141
* drivers should _never_ use the all version - the bio may have been split
150142
* before it got to the driver and the driver won't own all of it

0 commit comments

Comments
 (0)