Skip to content

Commit 7ed4aab

Browse files
yuta-sakataaxboe
authored andcommitted
block: optimize I/O merge hot path with unlikely() hints
Remove redundant '== false' comparisons and add unlikely() branch prediction hints in block I/O merge path functions. These functions (ll_new_hw_segment, ll_merge_requests_fn, and blk_rq_merge_ok) are executed on every I/O request merge attempt, making them critical hot paths. Data integrity check failures are rare events, so marking these conditions as unlikely() helps the CPU optimize the common case by improving branch prediction. Changes: - Replace 'func() == false' with 'unlikely(!func())' for better code style and branch prediction This micro-optimization reduces branch misprediction penalties in high-frequency I/O merge paths. Signed-off-by: Steven Feng <steven@joint-cloud.com> Link: https://patch.msgid.link/tencent_79B652BD0CC23E093F27914380F161E7E505@qq.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 5ef1b01 commit 7ed4aab

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

block/blk-merge.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
545545
if (!blk_cgroup_mergeable(req, bio))
546546
goto no_merge;
547547

548-
if (blk_integrity_merge_bio(req->q, req, bio) == false)
548+
if (unlikely(!blk_integrity_merge_bio(req->q, req, bio)))
549549
goto no_merge;
550550

551551
/* discard request merge won't add new segment */
@@ -647,7 +647,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
647647
if (!blk_cgroup_mergeable(req, next->bio))
648648
return 0;
649649

650-
if (blk_integrity_merge_rq(q, req, next) == false)
650+
if (unlikely(!blk_integrity_merge_rq(q, req, next)))
651651
return 0;
652652

653653
if (!bio_crypt_ctx_merge_rq(req, next))
@@ -903,7 +903,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
903903

904904
if (!blk_cgroup_mergeable(rq, bio))
905905
return false;
906-
if (blk_integrity_merge_bio(rq->q, rq, bio) == false)
906+
if (unlikely(!blk_integrity_merge_bio(rq->q, rq, bio)))
907907
return false;
908908
if (!bio_crypt_rq_ctx_compatible(rq, bio))
909909
return false;
@@ -913,7 +913,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
913913
return false;
914914
if (rq->bio->bi_ioprio != bio->bi_ioprio)
915915
return false;
916-
if (blk_atomic_write_mergeable_rq_bio(rq, bio) == false)
916+
if (unlikely(!blk_atomic_write_mergeable_rq_bio(rq, bio)))
917917
return false;
918918

919919
return true;

0 commit comments

Comments
 (0)