summaryrefslogtreecommitdiffstats
path: root/drivers/block/loop.c
diff options
context:
space:
mode:
authorShaohua Li <shli@fb.com>2017-09-01 01:09:46 -0400
committerJens Axboe <axboe@kernel.dk>2017-09-01 10:44:34 -0400
commit40326d8a33d5b70039849d233975b63c733d94a2 (patch)
tree8fcd492241c391279b3957fed2979c1d70aaa1e5 /drivers/block/loop.c
parent54bb0ade6627a183c211345761ec46e4bf0048fe (diff)
block/loop: allow request merge for directio mode
Currently loop disables merge. While it makes sense for buffer IO mode, directio mode can benefit from request merge. Without merge, loop could send small size IO to underlayer disk and harm performance. Reviewed-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Shaohua Li <shli@fb.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/block/loop.c')
-rw-r--r--drivers/block/loop.c66
1 files changed, 51 insertions, 15 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 9eff4d3ab1f3..3a35121f8a6f 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -213,10 +213,13 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
213 */ 213 */
214 blk_mq_freeze_queue(lo->lo_queue); 214 blk_mq_freeze_queue(lo->lo_queue);
215 lo->use_dio = use_dio; 215 lo->use_dio = use_dio;
216 if (use_dio) 216 if (use_dio) {
217 queue_flag_clear_unlocked(QUEUE_FLAG_NOMERGES, lo->lo_queue);
217 lo->lo_flags |= LO_FLAGS_DIRECT_IO; 218 lo->lo_flags |= LO_FLAGS_DIRECT_IO;
218 else 219 } else {
220 queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, lo->lo_queue);
219 lo->lo_flags &= ~LO_FLAGS_DIRECT_IO; 221 lo->lo_flags &= ~LO_FLAGS_DIRECT_IO;
222 }
220 blk_mq_unfreeze_queue(lo->lo_queue); 223 blk_mq_unfreeze_queue(lo->lo_queue);
221} 224}
222 225
@@ -464,6 +467,8 @@ static void lo_rw_aio_complete(struct kiocb *iocb, long ret, long ret2)
464{ 467{
465 struct loop_cmd *cmd = container_of(iocb, struct loop_cmd, iocb); 468 struct loop_cmd *cmd = container_of(iocb, struct loop_cmd, iocb);
466 469
470 kfree(cmd->bvec);
471 cmd->bvec = NULL;
467 cmd->ret = ret; 472 cmd->ret = ret;
468 blk_mq_complete_request(cmd->rq); 473 blk_mq_complete_request(cmd->rq);
469} 474}
@@ -473,22 +478,50 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
473{ 478{
474 struct iov_iter iter; 479 struct iov_iter iter;
475 struct bio_vec *bvec; 480 struct bio_vec *bvec;
476 struct bio *bio = cmd->rq->bio; 481 struct request *rq = cmd->rq;
482 struct bio *bio = rq->bio;
477 struct file *file = lo->lo_backing_file; 483 struct file *file = lo->lo_backing_file;
484 unsigned int offset;
485 int segments = 0;
478 int ret; 486 int ret;
479 487
480 /* nomerge for loop request queue */ 488 if (rq->bio != rq->biotail) {
481 WARN_ON(cmd->rq->bio != cmd->rq->biotail); 489 struct req_iterator iter;
490 struct bio_vec tmp;
491
492 __rq_for_each_bio(bio, rq)
493 segments += bio_segments(bio);
494 bvec = kmalloc(sizeof(struct bio_vec) * segments, GFP_NOIO);
495 if (!bvec)
496 return -EIO;
497 cmd->bvec = bvec;
498
499 /*
500 * The bios of the request may be started from the middle of
501 * the 'bvec' because of bio splitting, so we can't directly
502 * copy bio->bi_iov_vec to new bvec. The rq_for_each_segment
503 * API will take care of all details for us.
504 */
505 rq_for_each_segment(tmp, rq, iter) {
506 *bvec = tmp;
507 bvec++;
508 }
509 bvec = cmd->bvec;
510 offset = 0;
511 } else {
512 /*
513 * Same here, this bio may be started from the middle of the
514 * 'bvec' because of bio splitting, so offset from the bvec
515 * must be passed to iov iterator
516 */
517 offset = bio->bi_iter.bi_bvec_done;
518 bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
519 segments = bio_segments(bio);
520 }
482 521
483 bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
484 iov_iter_bvec(&iter, ITER_BVEC | rw, bvec, 522 iov_iter_bvec(&iter, ITER_BVEC | rw, bvec,
485 bio_segments(bio), blk_rq_bytes(cmd->rq)); 523 segments, blk_rq_bytes(rq));
486 /* 524 iter.iov_offset = offset;
487 * This bio may be started from the middle of the 'bvec'
488 * because of bio splitting, so offset from the bvec must
489 * be passed to iov iterator
490 */
491 iter.iov_offset = bio->bi_iter.bi_bvec_done;
492 525
493 cmd->iocb.ki_pos = pos; 526 cmd->iocb.ki_pos = pos;
494 cmd->iocb.ki_filp = file; 527 cmd->iocb.ki_filp = file;
@@ -1737,9 +1770,12 @@ static int loop_add(struct loop_device **l, int i)
1737 blk_queue_physical_block_size(lo->lo_queue, PAGE_SIZE); 1770 blk_queue_physical_block_size(lo->lo_queue, PAGE_SIZE);
1738 1771
1739 blk_queue_max_hw_sectors(lo->lo_queue, BLK_DEF_MAX_SECTORS); 1772 blk_queue_max_hw_sectors(lo->lo_queue, BLK_DEF_MAX_SECTORS);
1773
1740 /* 1774 /*
1741 * It doesn't make sense to enable merge because the I/O 1775 * By default, we do buffer IO, so it doesn't make sense to enable
1742 * submitted to backing file is handled page by page. 1776 * merge because the I/O submitted to backing file is handled page by
1777 * page. For directio mode, merge does help to dispatch bigger request
1778 * to underlayer disk. We will enable merge once directio is enabled.
1743 */ 1779 */
1744 queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, lo->lo_queue); 1780 queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, lo->lo_queue);
1745 1781