Skip to content

Commit 60dc5ea

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: take chunk_sectors into account in bio_split_write_zeroes
For zoned devices, write zeroes must be split at the zone boundary which is represented as chunk_sectors. For other uses like the internally RAIDed NVMe devices it is probably at least useful. Enhance get_max_io_size to know about write zeroes and use it in bio_split_write_zeroes. Also add a comment about the seemingly nonsensical zero max_write_zeroes limit. Fixes: 885fa13 ("block: implement splitting of REQ_OP_WRITE_ZEROES bios") Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 4cf58d9 commit 60dc5ea

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

block/blk-merge.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,6 @@ struct bio *bio_split_discard(struct bio *bio, const struct queue_limits *lim,
171171
return bio_submit_split(bio, split_sectors);
172172
}
173173

174-
struct bio *bio_split_write_zeroes(struct bio *bio,
175-
const struct queue_limits *lim, unsigned *nsegs)
176-
{
177-
*nsegs = 0;
178-
if (!lim->max_write_zeroes_sectors)
179-
return bio;
180-
if (bio_sectors(bio) <= lim->max_write_zeroes_sectors)
181-
return bio;
182-
return bio_submit_split(bio, lim->max_write_zeroes_sectors);
183-
}
184-
185174
static inline unsigned int blk_boundary_sectors(const struct queue_limits *lim,
186175
bool is_atomic)
187176
{
@@ -216,7 +205,9 @@ static inline unsigned get_max_io_size(struct bio *bio,
216205
* We ignore lim->max_sectors for atomic writes because it may less
217206
* than the actual bio size, which we cannot tolerate.
218207
*/
219-
if (is_atomic)
208+
if (bio_op(bio) == REQ_OP_WRITE_ZEROES)
209+
max_sectors = lim->max_write_zeroes_sectors;
210+
else if (is_atomic)
220211
max_sectors = lim->atomic_write_max_sectors;
221212
else
222213
max_sectors = lim->max_sectors;
@@ -403,6 +394,26 @@ struct bio *bio_split_zone_append(struct bio *bio,
403394
return bio_submit_split(bio, split_sectors);
404395
}
405396

397+
struct bio *bio_split_write_zeroes(struct bio *bio,
398+
const struct queue_limits *lim, unsigned *nsegs)
399+
{
400+
unsigned int max_sectors = get_max_io_size(bio, lim);
401+
402+
*nsegs = 0;
403+
404+
/*
405+
* An unset limit should normally not happen, as bio submission is keyed
406+
* off having a non-zero limit. But SCSI can clear the limit in the
407+
* I/O completion handler, and we can race and see this. Splitting to a
408+
* zero limit obviously doesn't make sense, so band-aid it here.
409+
*/
410+
if (!max_sectors)
411+
return bio;
412+
if (bio_sectors(bio) <= max_sectors)
413+
return bio;
414+
return bio_submit_split(bio, max_sectors);
415+
}
416+
406417
/**
407418
* bio_split_to_limits - split a bio to fit the queue limits
408419
* @bio: bio to be split

0 commit comments

Comments
 (0)