Skip to content

Commit 3ee16db

Browse files
committed
dm: fix IO splitting
Commit 882ec4e ("dm table: stack 'chunk_sectors' limit to account for target-specific splitting") caused a couple regressions: 1) Using lcm_not_zero() when stacking chunk_sectors was a bug because chunk_sectors must reflect the most limited of all devices in the IO stack. 2) DM targets that set max_io_len but that do _not_ provide an .iterate_devices method no longer had there IO split properly. And commit 5091cde ("dm: change max_io_len() to use blk_max_size_offset()") also caused a regression where DM no longer supported varied (per target) IO splitting. The implication being the potential for severely reduced performance for IO stacks that use a DM target like dm-cache to hide performance limitations of a slower device (e.g. one that requires 4K IO splitting). Coming full circle: Fix all these issues by discontinuing stacking chunk_sectors up using ti->max_io_len in dm_calculate_queue_limits(), add optional chunk_sectors override argument to blk_max_size_offset() and update DM's max_io_len() to pass ti->max_io_len to its blk_max_size_offset() call. Passing in an optional chunk_sectors override to blk_max_size_offset() allows for code reuse of block's centralized calculation for max IO size based on provided offset and split boundary. Fixes: 882ec4e ("dm table: stack 'chunk_sectors' limit to account for target-specific splitting") Fixes: 5091cde ("dm: change max_io_len() to use blk_max_size_offset()") Cc: stable@vger.kernel.org Reported-by: John Dorminy <jdorminy@redhat.com> Reported-by: Bruce Johnston <bjohnsto@redhat.com> Reported-by: Kirill Tkhai <ktkhai@virtuozzo.com> Reviewed-by: John Dorminy <jdorminy@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Reviewed-by: Jens Axboe <axboe@kernel.dk>
1 parent 857c4c0 commit 3ee16db

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

block/blk-merge.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q,
144144
static inline unsigned get_max_io_size(struct request_queue *q,
145145
struct bio *bio)
146146
{
147-
unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector);
147+
unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector, 0);
148148
unsigned max_sectors = sectors;
149149
unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT;
150150
unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT;

drivers/md/dm-table.c

-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <linux/mutex.h>
1919
#include <linux/delay.h>
2020
#include <linux/atomic.h>
21-
#include <linux/lcm.h>
2221
#include <linux/blk-mq.h>
2322
#include <linux/mount.h>
2423
#include <linux/dax.h>
@@ -1449,10 +1448,6 @@ int dm_calculate_queue_limits(struct dm_table *table,
14491448
zone_sectors = ti_limits.chunk_sectors;
14501449
}
14511450

1452-
/* Stack chunk_sectors if target-specific splitting is required */
1453-
if (ti->max_io_len)
1454-
ti_limits.chunk_sectors = lcm_not_zero(ti->max_io_len,
1455-
ti_limits.chunk_sectors);
14561451
/* Set I/O hints portion of queue limits */
14571452
if (ti->type->io_hints)
14581453
ti->type->io_hints(ti, &ti_limits);

drivers/md/dm.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -1039,15 +1039,18 @@ static sector_t max_io_len(struct dm_target *ti, sector_t sector)
10391039
sector_t max_len;
10401040

10411041
/*
1042-
* Does the target need to split even further?
1043-
* - q->limits.chunk_sectors reflects ti->max_io_len so
1044-
* blk_max_size_offset() provides required splitting.
1045-
* - blk_max_size_offset() also respects q->limits.max_sectors
1042+
* Does the target need to split IO even further?
1043+
* - varied (per target) IO splitting is a tenet of DM; this
1044+
* explains why stacked chunk_sectors based splitting via
1045+
* blk_max_size_offset() isn't possible here. So pass in
1046+
* ti->max_io_len to override stacked chunk_sectors.
10461047
*/
1047-
max_len = blk_max_size_offset(ti->table->md->queue,
1048-
target_offset);
1049-
if (len > max_len)
1050-
len = max_len;
1048+
if (ti->max_io_len) {
1049+
max_len = blk_max_size_offset(ti->table->md->queue,
1050+
target_offset, ti->max_io_len);
1051+
if (len > max_len)
1052+
len = max_len;
1053+
}
10511054

10521055
return len;
10531056
}

include/linux/blkdev.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -1073,11 +1073,12 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
10731073
* file system requests.
10741074
*/
10751075
static inline unsigned int blk_max_size_offset(struct request_queue *q,
1076-
sector_t offset)
1076+
sector_t offset,
1077+
unsigned int chunk_sectors)
10771078
{
1078-
unsigned int chunk_sectors = q->limits.chunk_sectors;
1079-
1080-
if (!chunk_sectors)
1079+
if (!chunk_sectors && q->limits.chunk_sectors)
1080+
chunk_sectors = q->limits.chunk_sectors;
1081+
else
10811082
return q->limits.max_sectors;
10821083

10831084
if (likely(is_power_of_2(chunk_sectors)))
@@ -1101,7 +1102,7 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
11011102
req_op(rq) == REQ_OP_SECURE_ERASE)
11021103
return blk_queue_get_max_sectors(q, req_op(rq));
11031104

1104-
return min(blk_max_size_offset(q, offset),
1105+
return min(blk_max_size_offset(q, offset, 0),
11051106
blk_queue_get_max_sectors(q, req_op(rq)));
11061107
}
11071108

0 commit comments

Comments
 (0)