Skip to content

Commit fa53228

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: avoid blk_bio_segment_split for small I/O operations
__blk_queue_split() adds significant overhead for small I/O operations. Add a shortcut to avoid it for cases where we know we never need to split. Based on a patch from Ming Lei. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d2c9be8 commit fa53228

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎block/blk-merge.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
293293
void __blk_queue_split(struct request_queue *q, struct bio **bio,
294294
unsigned int *nr_segs)
295295
{
296-
struct bio *split;
296+
struct bio *split = NULL;
297297

298298
switch (bio_op(*bio)) {
299299
case REQ_OP_DISCARD:
@@ -309,6 +309,20 @@ void __blk_queue_split(struct request_queue *q, struct bio **bio,
309309
nr_segs);
310310
break;
311311
default:
312+
/*
313+
* All drivers must accept single-segments bios that are <=
314+
* PAGE_SIZE. This is a quick and dirty check that relies on
315+
* the fact that bi_io_vec[0] is always valid if a bio has data.
316+
* The check might lead to occasional false negatives when bios
317+
* are cloned, but compared to the performance impact of cloned
318+
* bios themselves the loop below doesn't matter anyway.
319+
*/
320+
if (!q->limits.chunk_sectors &&
321+
(*bio)->bi_vcnt == 1 &&
322+
(*bio)->bi_io_vec[0].bv_len <= PAGE_SIZE) {
323+
*nr_segs = 1;
324+
break;
325+
}
312326
split = blk_bio_segment_split(q, *bio, &q->bio_split, nr_segs);
313327
break;
314328
}

0 commit comments

Comments
 (0)