Skip to content

Commit 22ada80

Browse files
snitmaxboe
authored andcommitted
block: use lcm_not_zero() when stacking chunk_sectors
Like 'io_opt', blk_stack_limits() should stack 'chunk_sectors' using lcm_not_zero() rather than min_not_zero() -- otherwise the final 'chunk_sectors' could result in sub-optimal alignment of IO to component devices in the IO stack. Also, if 'chunk_sectors' isn't a multiple of 'physical_block_size' then it is a bug in the driver and the device should be flagged as 'misaligned'. Reviewed-by: Ming Lei <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Signed-off-by: Mike Snitzer <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 0385971 commit 22ada80

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

block/blk-settings.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
534534

535535
t->io_min = max(t->io_min, b->io_min);
536536
t->io_opt = lcm_not_zero(t->io_opt, b->io_opt);
537+
t->chunk_sectors = lcm_not_zero(t->chunk_sectors, b->chunk_sectors);
537538

538539
/* Physical block size a multiple of the logical block size? */
539540
if (t->physical_block_size & (t->logical_block_size - 1)) {
@@ -556,6 +557,13 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
556557
ret = -1;
557558
}
558559

560+
/* chunk_sectors a multiple of the physical block size? */
561+
if ((t->chunk_sectors << 9) & (t->physical_block_size - 1)) {
562+
t->chunk_sectors = 0;
563+
t->misaligned = 1;
564+
ret = -1;
565+
}
566+
559567
t->raid_partial_stripes_expensive =
560568
max(t->raid_partial_stripes_expensive,
561569
b->raid_partial_stripes_expensive);
@@ -594,10 +602,6 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
594602
t->discard_granularity;
595603
}
596604

597-
if (b->chunk_sectors)
598-
t->chunk_sectors = min_not_zero(t->chunk_sectors,
599-
b->chunk_sectors);
600-
601605
t->zoned = max(t->zoned, b->zoned);
602606
return ret;
603607
}

0 commit comments

Comments
 (0)