aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Busch <keith.busch@intel.com>2015-08-19 17:24:05 -0400
committerJens Axboe <axboe@fb.com>2015-08-19 17:26:02 -0400
commit03100aada96f0645bbcb89aea24c01f02d0ef1fa (patch)
treeba909d035a188206b101ae633f925e18d749f7cc
parentd2be537c3ba3568acd79cd178327b842e60d035e (diff)
block: Replace SG_GAPS with new queue limits mask
The SG_GAPS queue flag caused checks for bio vector alignment against PAGE_SIZE, but the device may have different constraints. This patch adds a queue limits so a driver with such constraints can set to allow requests that would have been unnecessarily split. The new gaps check takes the request_queue as a parameter to simplify the logic around invoking this function. This new limit makes the queue flag redundant, so removing it and all usage. Device-mappers will inherit the correct settings through blk_stack_limits(). Signed-off-by: Keith Busch <keith.busch@intel.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--block/bio.c3
-rw-r--r--block/blk-merge.c23
-rw-r--r--block/blk-settings.c14
-rw-r--r--drivers/block/nvme-core.c2
-rw-r--r--drivers/md/dm-table.c13
-rw-r--r--include/linux/bio.h9
-rw-r--r--include/linux/blkdev.h21
7 files changed, 43 insertions, 42 deletions
diff --git a/block/bio.c b/block/bio.c
index 425d6d4a2f7a..b1f198f9a317 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -742,8 +742,7 @@ int bio_add_pc_page(struct request_queue *q, struct bio *bio, struct page
742 * If the queue doesn't support SG gaps and adding this 742 * If the queue doesn't support SG gaps and adding this
743 * offset would create a gap, disallow it. 743 * offset would create a gap, disallow it.
744 */ 744 */
745 if (q->queue_flags & (1 << QUEUE_FLAG_SG_GAPS) && 745 if (bvec_gap_to_prev(q, prev, offset))
746 bvec_gap_to_prev(prev, offset))
747 return 0; 746 return 0;
748 } 747 }
749 748
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 0027def35f5a..0e0d9fd01c40 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -82,8 +82,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
82 * If the queue doesn't support SG gaps and adding this 82 * If the queue doesn't support SG gaps and adding this
83 * offset would create a gap, disallow it. 83 * offset would create a gap, disallow it.
84 */ 84 */
85 if (q->queue_flags & (1 << QUEUE_FLAG_SG_GAPS) && 85 if (prev && bvec_gap_to_prev(q, &bvprv, bv.bv_offset))
86 prev && bvec_gap_to_prev(&bvprv, bv.bv_offset))
87 goto split; 86 goto split;
88 87
89 if (prev && blk_queue_cluster(q)) { 88 if (prev && blk_queue_cluster(q)) {
@@ -484,12 +483,12 @@ static bool req_no_special_merge(struct request *req)
484 return !q->mq_ops && req->special; 483 return !q->mq_ops && req->special;
485} 484}
486 485
487static int req_gap_to_prev(struct request *req, struct request *next) 486static int req_gap_to_prev(struct request *req, struct bio *next)
488{ 487{
489 struct bio *prev = req->biotail; 488 struct bio *prev = req->biotail;
490 489
491 return bvec_gap_to_prev(&prev->bi_io_vec[prev->bi_vcnt - 1], 490 return bvec_gap_to_prev(req->q, &prev->bi_io_vec[prev->bi_vcnt - 1],
492 next->bio->bi_io_vec[0].bv_offset); 491 next->bi_io_vec[1].bv_offset);
493} 492}
494 493
495static int ll_merge_requests_fn(struct request_queue *q, struct request *req, 494static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
@@ -506,8 +505,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
506 if (req_no_special_merge(req) || req_no_special_merge(next)) 505 if (req_no_special_merge(req) || req_no_special_merge(next))
507 return 0; 506 return 0;
508 507
509 if (test_bit(QUEUE_FLAG_SG_GAPS, &q->queue_flags) && 508 if (req_gap_to_prev(req, next->bio))
510 req_gap_to_prev(req, next))
511 return 0; 509 return 0;
512 510
513 /* 511 /*
@@ -692,8 +690,6 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
692 690
693bool blk_rq_merge_ok(struct request *rq, struct bio *bio) 691bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
694{ 692{
695 struct request_queue *q = rq->q;
696
697 if (!rq_mergeable(rq) || !bio_mergeable(bio)) 693 if (!rq_mergeable(rq) || !bio_mergeable(bio))
698 return false; 694 return false;
699 695
@@ -718,13 +714,8 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
718 return false; 714 return false;
719 715
720 /* Only check gaps if the bio carries data */ 716 /* Only check gaps if the bio carries data */
721 if (q->queue_flags & (1 << QUEUE_FLAG_SG_GAPS) && bio_has_data(bio)) { 717 if (bio_has_data(bio) && req_gap_to_prev(rq, bio))
722 struct bio_vec *bprev; 718 return false;
723
724 bprev = &rq->biotail->bi_io_vec[rq->biotail->bi_vcnt - 1];
725 if (bvec_gap_to_prev(bprev, bio->bi_io_vec[0].bv_offset))
726 return false;
727 }
728 719
729 return true; 720 return true;
730} 721}
diff --git a/block/blk-settings.c b/block/blk-settings.c
index d27b4e272356..f96c72116931 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -89,6 +89,7 @@ void blk_set_default_limits(struct queue_limits *lim)
89 lim->max_segments = BLK_MAX_SEGMENTS; 89 lim->max_segments = BLK_MAX_SEGMENTS;
90 lim->max_integrity_segments = 0; 90 lim->max_integrity_segments = 0;
91 lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK; 91 lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
92 lim->virt_boundary_mask = 0;
92 lim->max_segment_size = BLK_MAX_SEGMENT_SIZE; 93 lim->max_segment_size = BLK_MAX_SEGMENT_SIZE;
93 lim->max_sectors = lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS; 94 lim->max_sectors = lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS;
94 lim->chunk_sectors = 0; 95 lim->chunk_sectors = 0;
@@ -532,6 +533,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
532 533
533 t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask, 534 t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask,
534 b->seg_boundary_mask); 535 b->seg_boundary_mask);
536 t->virt_boundary_mask = min_not_zero(t->virt_boundary_mask,
537 b->virt_boundary_mask);
535 538
536 t->max_segments = min_not_zero(t->max_segments, b->max_segments); 539 t->max_segments = min_not_zero(t->max_segments, b->max_segments);
537 t->max_integrity_segments = min_not_zero(t->max_integrity_segments, 540 t->max_integrity_segments = min_not_zero(t->max_integrity_segments,
@@ -772,6 +775,17 @@ void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask)
772EXPORT_SYMBOL(blk_queue_segment_boundary); 775EXPORT_SYMBOL(blk_queue_segment_boundary);
773 776
774/** 777/**
778 * blk_queue_virt_boundary - set boundary rules for bio merging
779 * @q: the request queue for the device
780 * @mask: the memory boundary mask
781 **/
782void blk_queue_virt_boundary(struct request_queue *q, unsigned long mask)
783{
784 q->limits.virt_boundary_mask = mask;
785}
786EXPORT_SYMBOL(blk_queue_virt_boundary);
787
788/**
775 * blk_queue_dma_alignment - set dma length and memory alignment 789 * blk_queue_dma_alignment - set dma length and memory alignment
776 * @q: the request queue for the device 790 * @q: the request queue for the device
777 * @mask: alignment mask 791 * @mask: alignment mask
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index d844ec4a2b85..2f694d78da55 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -2067,7 +2067,6 @@ static void nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid)
2067 goto out_free_ns; 2067 goto out_free_ns;
2068 queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, ns->queue); 2068 queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, ns->queue);
2069 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, ns->queue); 2069 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, ns->queue);
2070 queue_flag_set_unlocked(QUEUE_FLAG_SG_GAPS, ns->queue);
2071 ns->dev = dev; 2070 ns->dev = dev;
2072 ns->queue->queuedata = ns; 2071 ns->queue->queuedata = ns;
2073 2072
@@ -2087,6 +2086,7 @@ static void nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid)
2087 blk_queue_chunk_sectors(ns->queue, dev->stripe_size >> 9); 2086 blk_queue_chunk_sectors(ns->queue, dev->stripe_size >> 9);
2088 if (dev->vwc & NVME_CTRL_VWC_PRESENT) 2087 if (dev->vwc & NVME_CTRL_VWC_PRESENT)
2089 blk_queue_flush(ns->queue, REQ_FLUSH | REQ_FUA); 2088 blk_queue_flush(ns->queue, REQ_FLUSH | REQ_FUA);
2089 blk_queue_virt_boundary(ns->queue, dev->page_size - 1);
2090 2090
2091 disk->major = nvme_major; 2091 disk->major = nvme_major;
2092 disk->first_minor = 0; 2092 disk->first_minor = 0;
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index afb4ad3dfeb3..e76ed003769e 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -1380,14 +1380,6 @@ static int queue_supports_sg_merge(struct dm_target *ti, struct dm_dev *dev,
1380 return q && !test_bit(QUEUE_FLAG_NO_SG_MERGE, &q->queue_flags); 1380 return q && !test_bit(QUEUE_FLAG_NO_SG_MERGE, &q->queue_flags);
1381} 1381}
1382 1382
1383static int queue_supports_sg_gaps(struct dm_target *ti, struct dm_dev *dev,
1384 sector_t start, sector_t len, void *data)
1385{
1386 struct request_queue *q = bdev_get_queue(dev->bdev);
1387
1388 return q && !test_bit(QUEUE_FLAG_SG_GAPS, &q->queue_flags);
1389}
1390
1391static bool dm_table_all_devices_attribute(struct dm_table *t, 1383static bool dm_table_all_devices_attribute(struct dm_table *t,
1392 iterate_devices_callout_fn func) 1384 iterate_devices_callout_fn func)
1393{ 1385{
@@ -1508,11 +1500,6 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
1508 else 1500 else
1509 queue_flag_set_unlocked(QUEUE_FLAG_NO_SG_MERGE, q); 1501 queue_flag_set_unlocked(QUEUE_FLAG_NO_SG_MERGE, q);
1510 1502
1511 if (dm_table_all_devices_attribute(t, queue_supports_sg_gaps))
1512 queue_flag_clear_unlocked(QUEUE_FLAG_SG_GAPS, q);
1513 else
1514 queue_flag_set_unlocked(QUEUE_FLAG_SG_GAPS, q);
1515
1516 dm_table_set_integrity(t); 1503 dm_table_set_integrity(t);
1517 1504
1518 /* 1505 /*
diff --git a/include/linux/bio.h b/include/linux/bio.h
index ad7217458812..b9b6e046b52e 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -187,15 +187,6 @@ static inline void *bio_data(struct bio *bio)
187 __BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, queue_segment_boundary((q))) 187 __BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, queue_segment_boundary((q)))
188 188
189/* 189/*
190 * Check if adding a bio_vec after bprv with offset would create a gap in
191 * the SG list. Most drivers don't care about this, but some do.
192 */
193static inline bool bvec_gap_to_prev(struct bio_vec *bprv, unsigned int offset)
194{
195 return offset || ((bprv->bv_offset + bprv->bv_len) & (PAGE_SIZE - 1));
196}
197
198/*
199 * drivers should _never_ use the all version - the bio may have been split 190 * drivers should _never_ use the all version - the bio may have been split
200 * before it got to the driver and the driver won't own all of it 191 * before it got to the driver and the driver won't own all of it
201 */ 192 */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index e427debc7008..a622f270f09e 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -250,6 +250,7 @@ struct blk_queue_tag {
250struct queue_limits { 250struct queue_limits {
251 unsigned long bounce_pfn; 251 unsigned long bounce_pfn;
252 unsigned long seg_boundary_mask; 252 unsigned long seg_boundary_mask;
253 unsigned long virt_boundary_mask;
253 254
254 unsigned int max_hw_sectors; 255 unsigned int max_hw_sectors;
255 unsigned int chunk_sectors; 256 unsigned int chunk_sectors;
@@ -479,7 +480,6 @@ struct request_queue {
479#define QUEUE_FLAG_DEAD 19 /* queue tear-down finished */ 480#define QUEUE_FLAG_DEAD 19 /* queue tear-down finished */
480#define QUEUE_FLAG_INIT_DONE 20 /* queue is initialized */ 481#define QUEUE_FLAG_INIT_DONE 20 /* queue is initialized */
481#define QUEUE_FLAG_NO_SG_MERGE 21 /* don't attempt to merge SG segments*/ 482#define QUEUE_FLAG_NO_SG_MERGE 21 /* don't attempt to merge SG segments*/
482#define QUEUE_FLAG_SG_GAPS 22 /* queue doesn't support SG gaps */
483 483
484#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ 484#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
485 (1 << QUEUE_FLAG_STACKABLE) | \ 485 (1 << QUEUE_FLAG_STACKABLE) | \
@@ -981,6 +981,7 @@ extern int blk_queue_dma_drain(struct request_queue *q,
981 void *buf, unsigned int size); 981 void *buf, unsigned int size);
982extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn); 982extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn);
983extern void blk_queue_segment_boundary(struct request_queue *, unsigned long); 983extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
984extern void blk_queue_virt_boundary(struct request_queue *, unsigned long);
984extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn); 985extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn);
985extern void blk_queue_unprep_rq(struct request_queue *, unprep_rq_fn *ufn); 986extern void blk_queue_unprep_rq(struct request_queue *, unprep_rq_fn *ufn);
986extern void blk_queue_dma_alignment(struct request_queue *, int); 987extern void blk_queue_dma_alignment(struct request_queue *, int);
@@ -1149,6 +1150,11 @@ static inline unsigned long queue_segment_boundary(struct request_queue *q)
1149 return q->limits.seg_boundary_mask; 1150 return q->limits.seg_boundary_mask;
1150} 1151}
1151 1152
1153static inline unsigned long queue_virt_boundary(struct request_queue *q)
1154{
1155 return q->limits.virt_boundary_mask;
1156}
1157
1152static inline unsigned int queue_max_sectors(struct request_queue *q) 1158static inline unsigned int queue_max_sectors(struct request_queue *q)
1153{ 1159{
1154 return q->limits.max_sectors; 1160 return q->limits.max_sectors;
@@ -1349,6 +1355,19 @@ static inline void put_dev_sector(Sector p)
1349 page_cache_release(p.v); 1355 page_cache_release(p.v);
1350} 1356}
1351 1357
1358/*
1359 * Check if adding a bio_vec after bprv with offset would create a gap in
1360 * the SG list. Most drivers don't care about this, but some do.
1361 */
1362static inline bool bvec_gap_to_prev(struct request_queue *q,
1363 struct bio_vec *bprv, unsigned int offset)
1364{
1365 if (!queue_virt_boundary(q))
1366 return false;
1367 return offset ||
1368 ((bprv->bv_offset + bprv->bv_len) & queue_virt_boundary(q));
1369}
1370
1352struct work_struct; 1371struct work_struct;
1353int kblockd_schedule_work(struct work_struct *work); 1372int kblockd_schedule_work(struct work_struct *work);
1354int kblockd_schedule_delayed_work(struct delayed_work *dwork, unsigned long delay); 1373int kblockd_schedule_delayed_work(struct delayed_work *dwork, unsigned long delay);