Skip to content

Commit 1251580

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: don't use bio_split_rw on misc operations
bio_split_rw is designed to split read and write bios with a payload. Currently it is called by __bio_split_to_limits for all operations not explicitly list, which works because bio_may_need_split explicitly checks for bi_vcnt == 1 and thus skips the bypass if there is no payload and bio_for_each_bvec loop will never execute it's body if bi_size is 0. But all this is hard to understand, fragile and wasted pointless cycles. Switch __bio_split_to_limits to only call bio_split_rw for READ and WRITE command and don't attempt any kind split for operation that do not require splitting. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Tested-by: Hans Holmberg <[email protected]> Reviewed-by: Hans Holmberg <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 1e8a7f6 commit 1251580

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

block/blk.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ static inline struct bio *__bio_split_to_limits(struct bio *bio,
372372
const struct queue_limits *lim, unsigned int *nr_segs)
373373
{
374374
switch (bio_op(bio)) {
375-
default:
375+
case REQ_OP_READ:
376+
case REQ_OP_WRITE:
376377
if (bio_may_need_split(bio, lim))
377378
return bio_split_rw(bio, lim, nr_segs);
378379
*nr_segs = 1;
@@ -384,6 +385,10 @@ static inline struct bio *__bio_split_to_limits(struct bio *bio,
384385
return bio_split_discard(bio, lim, nr_segs);
385386
case REQ_OP_WRITE_ZEROES:
386387
return bio_split_write_zeroes(bio, lim, nr_segs);
388+
default:
389+
/* other operations can't be split */
390+
*nr_segs = 0;
391+
return bio;
387392
}
388393
}
389394

0 commit comments

Comments
 (0)