mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 02:17:36 -04:00
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>
This commit is contained in:
@@ -545,7 +545,7 @@ static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
|
||||
if (!blk_cgroup_mergeable(req, bio))
|
||||
goto no_merge;
|
||||
|
||||
if (blk_integrity_merge_bio(req->q, req, bio) == false)
|
||||
if (unlikely(!blk_integrity_merge_bio(req->q, req, bio)))
|
||||
goto no_merge;
|
||||
|
||||
/* 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,
|
||||
if (!blk_cgroup_mergeable(req, next->bio))
|
||||
return 0;
|
||||
|
||||
if (blk_integrity_merge_rq(q, req, next) == false)
|
||||
if (unlikely(!blk_integrity_merge_rq(q, req, next)))
|
||||
return 0;
|
||||
|
||||
if (!bio_crypt_ctx_merge_rq(req, next))
|
||||
@@ -903,7 +903,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
|
||||
|
||||
if (!blk_cgroup_mergeable(rq, bio))
|
||||
return false;
|
||||
if (blk_integrity_merge_bio(rq->q, rq, bio) == false)
|
||||
if (unlikely(!blk_integrity_merge_bio(rq->q, rq, bio)))
|
||||
return false;
|
||||
if (!bio_crypt_rq_ctx_compatible(rq, bio))
|
||||
return false;
|
||||
@@ -913,7 +913,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
|
||||
return false;
|
||||
if (rq->bio->bi_ioprio != bio->bi_ioprio)
|
||||
return false;
|
||||
if (blk_atomic_write_mergeable_rq_bio(rq, bio) == false)
|
||||
if (unlikely(!blk_atomic_write_mergeable_rq_bio(rq, bio)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user