block: Check for gaps on front and back merges

We are checking for gaps to previous bio_vec, which can
only detect back merges gaps. Moreover, at the point where
we check for a gap, we don't know if we will attempt a back
or a front merge. Thus, check for gap to prev in a back merge
attempt and check for a gap to next in a front merge attempt.

Signed-off-by: Jens Axboe <axboe@fb.com>
[sagig: Minor rename change]
Signed-off-by: Sagi Grimberg <sagig@mellanox.com>

+26 -13
+6 -13
block/blk-merge.c
··· 438 438 int ll_back_merge_fn(struct request_queue *q, struct request *req, 439 439 struct bio *bio) 440 440 { 441 + if (req_gap_back_merge(req, bio)) 442 + return 0; 441 443 if (blk_rq_sectors(req) + bio_sectors(bio) > 442 444 blk_rq_get_max_sectors(req)) { 443 445 req->cmd_flags |= REQ_NOMERGE; ··· 458 456 int ll_front_merge_fn(struct request_queue *q, struct request *req, 459 457 struct bio *bio) 460 458 { 459 + 460 + if (req_gap_front_merge(req, bio)) 461 + return 0; 461 462 if (blk_rq_sectors(req) + bio_sectors(bio) > 462 463 blk_rq_get_max_sectors(req)) { 463 464 req->cmd_flags |= REQ_NOMERGE; ··· 487 482 return !q->mq_ops && req->special; 488 483 } 489 484 490 - static int req_gap_to_prev(struct request *req, struct bio *next) 491 - { 492 - struct bio *prev = req->biotail; 493 - 494 - return bvec_gap_to_prev(req->q, &prev->bi_io_vec[prev->bi_vcnt - 1], 495 - next->bi_io_vec[0].bv_offset); 496 - } 497 - 498 485 static int ll_merge_requests_fn(struct request_queue *q, struct request *req, 499 486 struct request *next) 500 487 { ··· 501 504 if (req_no_special_merge(req) || req_no_special_merge(next)) 502 505 return 0; 503 506 504 - if (req_gap_to_prev(req, next->bio)) 507 + if (req_gap_back_merge(req, next->bio)) 505 508 return 0; 506 509 507 510 /* ··· 707 710 /* must be using the same buffer */ 708 711 if (rq->cmd_flags & REQ_WRITE_SAME && 709 712 !blk_write_same_mergeable(rq->bio, bio)) 710 - return false; 711 - 712 - /* Only check gaps if the bio carries data */ 713 - if (bio_has_data(bio) && req_gap_to_prev(rq, bio)) 714 713 return false; 715 714 716 715 return true;
+20
include/linux/blkdev.h
··· 1368 1368 ((bprv->bv_offset + bprv->bv_len) & queue_virt_boundary(q)); 1369 1369 } 1370 1370 1371 + static inline bool bio_will_gap(struct request_queue *q, struct bio *prev, 1372 + struct bio *next) 1373 + { 1374 + if (!bio_has_data(prev)) 1375 + return false; 1376 + 1377 + return bvec_gap_to_prev(q, &prev->bi_io_vec[prev->bi_vcnt - 1], 1378 + next->bi_io_vec[0].bv_offset); 1379 + } 1380 + 1381 + static inline bool req_gap_back_merge(struct request *req, struct bio *bio) 1382 + { 1383 + return bio_will_gap(req->q, req->biotail, bio); 1384 + } 1385 + 1386 + static inline bool req_gap_front_merge(struct request *req, struct bio *bio) 1387 + { 1388 + return bio_will_gap(req->q, bio, req->bio); 1389 + } 1390 + 1371 1391 struct work_struct; 1372 1392 int kblockd_schedule_work(struct work_struct *work); 1373 1393 int kblockd_schedule_delayed_work(struct delayed_work *dwork, unsigned long delay);