Skip to content

Commit abd45c1

Browse files
committed
block: handle fast path of bio splitting inline
The fast path is no splitting needed. Separate the handling into a check part we can inline, and an out-of-line handling path if we do need to split. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 09ce874 commit abd45c1

3 files changed

Lines changed: 35 additions & 21 deletions

File tree

‎block/blk-merge.c‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
324324

325325
/**
326326
* __blk_queue_split - split a bio and submit the second half
327+
* @q: [in] request_queue new bio is being queued at
327328
* @bio: [in, out] bio to be split
328329
* @nr_segs: [out] number of segments in the first bio
329330
*
@@ -334,9 +335,9 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
334335
* of the caller to ensure that q->bio_split is only released after processing
335336
* of the split bio has finished.
336337
*/
337-
void __blk_queue_split(struct bio **bio, unsigned int *nr_segs)
338+
void __blk_queue_split(struct request_queue *q, struct bio **bio,
339+
unsigned int *nr_segs)
338340
{
339-
struct request_queue *q = (*bio)->bi_bdev->bd_disk->queue;
340341
struct bio *split = NULL;
341342

342343
switch (bio_op(*bio)) {
@@ -353,21 +354,6 @@ void __blk_queue_split(struct bio **bio, unsigned int *nr_segs)
353354
nr_segs);
354355
break;
355356
default:
356-
/*
357-
* All drivers must accept single-segments bios that are <=
358-
* PAGE_SIZE. This is a quick and dirty check that relies on
359-
* the fact that bi_io_vec[0] is always valid if a bio has data.
360-
* The check might lead to occasional false negatives when bios
361-
* are cloned, but compared to the performance impact of cloned
362-
* bios themselves the loop below doesn't matter anyway.
363-
*/
364-
if (!q->limits.chunk_sectors &&
365-
(*bio)->bi_vcnt == 1 &&
366-
((*bio)->bi_io_vec[0].bv_len +
367-
(*bio)->bi_io_vec[0].bv_offset) <= PAGE_SIZE) {
368-
*nr_segs = 1;
369-
break;
370-
}
371357
split = blk_bio_segment_split(q, *bio, &q->bio_split, nr_segs);
372358
break;
373359
}
@@ -397,9 +383,11 @@ void __blk_queue_split(struct bio **bio, unsigned int *nr_segs)
397383
*/
398384
void blk_queue_split(struct bio **bio)
399385
{
386+
struct request_queue *q = (*bio)->bi_bdev->bd_disk->queue;
400387
unsigned int nr_segs;
401388

402-
__blk_queue_split(bio, &nr_segs);
389+
if (blk_may_split(q, *bio))
390+
__blk_queue_split(q, bio, &nr_segs);
403391
}
404392
EXPORT_SYMBOL(blk_queue_split);
405393

‎block/blk-mq.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,11 +2259,12 @@ void blk_mq_submit_bio(struct bio *bio)
22592259
struct request *rq;
22602260
struct blk_plug *plug;
22612261
struct request *same_queue_rq = NULL;
2262-
unsigned int nr_segs;
2262+
unsigned int nr_segs = 1;
22632263
blk_status_t ret;
22642264

22652265
blk_queue_bounce(q, &bio);
2266-
__blk_queue_split(&bio, &nr_segs);
2266+
if (blk_may_split(q, bio))
2267+
__blk_queue_split(q, &bio, &nr_segs);
22672268

22682269
if (!bio_integrity_prep(bio))
22692270
goto queue_exit;

‎block/blk.h‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,32 @@ ssize_t part_timeout_show(struct device *, struct device_attribute *, char *);
266266
ssize_t part_timeout_store(struct device *, struct device_attribute *,
267267
const char *, size_t);
268268

269-
void __blk_queue_split(struct bio **bio, unsigned int *nr_segs);
269+
static inline bool blk_may_split(struct request_queue *q, struct bio *bio)
270+
{
271+
switch (bio_op(bio)) {
272+
case REQ_OP_DISCARD:
273+
case REQ_OP_SECURE_ERASE:
274+
case REQ_OP_WRITE_ZEROES:
275+
case REQ_OP_WRITE_SAME:
276+
return true; /* non-trivial splitting decisions */
277+
default:
278+
break;
279+
}
280+
281+
/*
282+
* All drivers must accept single-segments bios that are <= PAGE_SIZE.
283+
* This is a quick and dirty check that relies on the fact that
284+
* bi_io_vec[0] is always valid if a bio has data. The check might
285+
* lead to occasional false negatives when bios are cloned, but compared
286+
* to the performance impact of cloned bios themselves the loop below
287+
* doesn't matter anyway.
288+
*/
289+
return q->limits.chunk_sectors || bio->bi_vcnt != 1 ||
290+
bio->bi_io_vec->bv_len + bio->bi_io_vec->bv_offset > PAGE_SIZE;
291+
}
292+
293+
void __blk_queue_split(struct request_queue *q, struct bio **bio,
294+
unsigned int *nr_segs);
270295
int ll_back_merge_fn(struct request *req, struct bio *bio,
271296
unsigned int nr_segs);
272297
bool blk_attempt_req_merge(struct request_queue *q, struct request *rq,

0 commit comments

Comments
 (0)