block/bfq: skip expensive merge lookups if contended
authorJens Axboe <axboe@kernel.dk>
Sat, 20 Jan 2024 21:58:37 +0000 (14:58 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 1 Apr 2024 22:03:34 +0000 (16:03 -0600)
commit0ef1d08d705d725e36a45b5d29c0c58622851d5b
treefa08decee497adace2e63e9c49141b73c7c94c61
parent8e496c90ce39ca1a54fd94c80b9da79d35db0f23
block/bfq: skip expensive merge lookups if contended

We do several stages of merging in the block layer - the most likely one
to work is also the cheap one, merging direct in the per-task plug when
IO is submitted. Getting merges outside of that is a lot less likely,
but IO schedulers may still maintain internal data structures to
facilitate merge lookups outside of the plug.

Make BFQ skip expensive merge lookups if the queue lock or bfqd lock is
already contended. The likelihood of getting a merge here is not very
high, hence it should not be a problem skipping the attempt in the also
unlikely event that either the queue or bfqd are already contended.

Perf diff shows the difference between a random read/write workload
with 4 threads doing IO, with expensive merges turned on and off:

    31.70%    +54.80%  [kernel.kallsyms]  [k] queued_spin_lock_slowpath

where we almost triple the lock contention (~32% -> ~87%) by attempting
these expensive merges, and performance drops from 1630K to 1050K IOPS.
At the same time, sys time drops from 37% to 14%.

Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bfq-iosched.c