Re: [PATCH] block: optimize I/O merge hot path with unlikely() hints
From: Christoph Hellwig
Date: Tue Jun 09 2026 - 03:39:05 EST
On Sat, Jun 06, 2026 at 10:42:18AM +0800, Steven Feng wrote:
> 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.
Umm, these are not failures. Just conditions to not merge because
of this, and not merging, both because of these conditions and others,
it the most common case for most workloads.
With your patch the object file size of blk-merge.o increases slightly
for me on x86_64:
text data bss dec hex filename
12299 577 0 12876 324c block/blk-merge.o.old
12331 577 0 12908 326c block/blk-merge.o
and looking at the assembly this is due to worse code generation
because it now splits different error returns.
What kind of optimization are you attempting and how did you measure
the results of this "optimizatіon"?