performance regression due to 0bd5a1b3d60c "block: Fix corruption from broken RMW atomicity"
Kevin,
the fix
- 0bd5a1b3d60c ("block: Fix corruption from broken RMW atomicity") results in a pretty hefty performance regression for my nvme disk via virtio-blk and multiple iothreads.
I uses AI to analyze and summarize and the result was seem legit from what I can tell, so I paste this is verbatim.
I verified that 0bd5a1b3d60c is bad and 0bd5a1b3d60c^ is good.
## Description of problem
Since commit 0bd5a1b3d60c ("block: Fix corruption from broken RMW atomicity") and the follow-up cf4f672c11d6 ("block: Remove now redundant bdrv_wait_serialising_requests() calls"), tracked_request_begin() unconditionally calls bdrv_wait_serialising_requests_locked(). The bs->serialising_in_flight fast path that bdrv_wait_serialising_requests() used to provide is gone.
As a result, every request, including plain aligned reads on a setup that never has serialising requests, walks the complete bs->tracked_requests list while holding bs->reqs_lock. With a multiqueue virtio-blk device whose queues are mapped to several iothreads, all iothreads share that one list and lock. With N requests in flight, each request does an O(N) pointer chase through list nodes that live on other iothreads' coroutine stacks, so most nodes are remote cache lines, and it holds the lock while doing so.
The RMW race the commit fixes only exists with misaligned writes, e.g. 512-byte guest sectors on 4k host storage. The setup here is 512/512 (logical block size on both host and guest), so no request is ever serialising, but all requests still pay for the walk.
Effect: multiqueue throughput stops scaling. Adding queues and iothreads barely helps, no iothread reaches 100% CPU, and the host NVMe sees only about 40 of the 128 requests the guest keeps in flight.
## Steps to reproduce
1. Attach a fast host NVMe namespace as raw virtio-blk with num-queues=4
and an iothread-vq-mapping of one queue per iothread (4 iothreads),
aio=native, cache=none.
2. In the guest, run 4k random reads with one job per queue, e.g.
`fio --name=t --filename=/dev/vdb --direct=1 --ioengine=libaio --bs=4k --rw=randread --iodepth=32 --numjobs=4 --cpus_allowed=0,3,6,9 --cpus_allowed_policy=split --size=16G --offset_increment=16G --runtime=20 --time_based --group_reporting` (the CPU list puts one job on each blk-mq queue of a 12-vCPU guest).
3. Repeat with iodepth=64. Throughput goes down instead of up.
4. perf record -g on the host shows bdrv_find_conflicting_request() as
one of the top symbols in the iothreads, called via
blk_aio_read_entry -> bdrv_co_preadv_part -> tracked_request_begin ->
bdrv_wait_serialising_requests_locked.
## Additional information
### Measurements
4k random I/O, IOPS, same guest and config throughout (two runs where two values are shown):
| test | master 2026-11-05 | master + suggested fix below | distro 11.1.90 snapshot | |---|---|---|---| | randread, 4 jobs x 32 deep | 542k / 566k | 693k / 741k | 494k / 505k | | randwrite, 4 jobs x 32 deep | 533k / 534k | 700k / 707k | 536k / 538k | | randread, 4 jobs x 64 deep | 448k | 830k | 445k | | randread, 1 job x 128 deep | 339k | 368k | 333k | | randread, 1 job x 1 deep | 12.9k | 12.3k | 12.8k |
The same 4 jobs reach about 839k IOPS when run directly on the host NVMe, so with the fix the guest is close to bare metal at depth 64.
Other observations:
- **Profile:** before the fix, about 10% of iothread cycles are in bdrv_find_conflicting_request(). In annotated code, about 88% of those samples are on loading the next list node, and about 85% of tracked_request_begin()'s samples are on the shared list head.
- **Splitting the list confirms the cause.** Splitting the same NVMe into four dm-linear devices, attached as four separate virtio-blk disks (each with its own BlockDriverState, list and lock, same 4 iothreads, same 128 requests in flight), raises throughput from about 440k to 613k IOPS without any code change, and bdrv_find_conflicting_request() drops to about 1% of iothread cycles.
- **Not the usual suspects:** changing iothread poll-max-ns, host KVM halt_poll_ns or aio=io_uring vs native made no difference to throughput.
This was measured on s390x, but nothing in the affected code is architecture specific. I expect the same behaviour on other hosts with multiqueue virtio-blk/virtio-scsi and several iothreads.
### Suggested fix
Restore the fast path inside tracked_request_begin(): only call bdrv_wait_serialising_requests_locked() if bs->serialising_in_flight is non-zero, reading the counter while bs->reqs_lock is held (i.e. after the QLIST_INSERT_HEAD that is already done under the lock).
Why this keeps the race fixed:
- **Marking is atomic with respect to the lock.** A request is marked serialising (req->serialising = true plus the serialising_in_flight increment in tracked_request_set_serialising()) only while holding bs->reqs_lock.
- **So a zero counter means nothing can conflict.** If the new request sees the counter as 0 under the lock, no request currently in the list is serialising, and bdrv_find_conflicting_request() would return NULL anyway.
- **A later serialising request waits for us.** If a request becomes serialising after we dropped the lock, its own bdrv_wait_serialising_requests_locked() walks the list, finds our request (already inserted, waiting_for == NULL) and waits for it. That is the ownership semantics the RMW fix relies on.
- **The one remaining difference is harmless.** A serialising request may already have decremented the counter in tracked_request_end() but not yet left the list. It has finished its I/O, so not waiting for it is safe, and this matches the behaviour before 0bd5a1b3d60c.
With a local build containing exactly this conditional, the guest numbers in the "master + suggested fix" column above were measured.
Remaining limitation, not addressed by this fix: all iothreads still insert into and remove from one list under one mutex per BlockDriverState. At higher request rates that will become the next scaling limit for multiqueue devices.
### Fixes
- 0bd5a1b3d60c ("block: Fix corruption from broken RMW atomicity")
- cf4f672c11d6 ("block: Remove now redundant bdrv_wait_serialising_requests() calls")
Both were backported to stable-11.1 (v11.1.3) and stable-10.0 (v10.0.15), so these releases are affected as well.
Christian
Am 26.11.2026 um 16:43 hat Christian Borntraeger geschrieben:
Quoted 8 lines
the fix
-0bd5a1b3d60c("block: Fix corruption from broken RMW atomicity") results in a pretty hefty performance regression for my nvme disk via virtio-blk and multiple iothreads.I uses AI to analyze and summarize and the result was seem legit from what I can tell, so I paste this is verbatim.
I verified that0bd5a1b3d60cis bad and 0bd5a1b3d60c^ is good.
Do you see any difference after commit cf4f672c (the commit right after 0bd5a1b3d60c)? Some checks are temporarily duplicated, but I expected that after the second commit, there shouldn't be any visible difference.
In your use case, are serialising requests actually present?
Quoted 7 lines
## Description of problem
Since commit0bd5a1b3d60c("block: Fix corruption from broken RMW atomicity") and the follow-upcf4f672c11d6("block: Remove now redundantbdrv_wait_serialising_requests()calls"),tracked_request_begin()unconditionally callsbdrv_wait_serialising_requests_locked(). Thebs->serialising_in_flightfast path thatbdrv_wait_serialising_requests()used to provide is gone.
Yes, that's a good point, and we could simply add this condition to bdrv_wait_serialising_requests_locked() if the walk is expensive.
In fact, I suppose we could optimise even the case that does have serialising requests by keeping a separate list of serialising requests so that we don't have to iterate over all the non-serialising requests, too. Though maybe it's not expected to have both serialising and a lot of non-serialising requests at the same time on the same disk.
Anyway, can you try out if the below patch helps? (Only compile tested.) serialising_in_flight doesn't actually have to be atomic any more, but it's the simplest change we can make for 11.2.
Kevin
block/io.c +4 -0
@@ -703,6 +703,10 @@ bdrv_wait_serialising_requests_locked(BdrvTrackedRequest *self) {BdrvTrackedRequest *req; +if (!qatomic_read (&self->bs->serialising_in_flight)) { +return ; + } +while ((req =bdrv_find_conflicting_request (self))) {/* * If this request is the active owner of the data blocks it accesses,
Quoted 10 lines · Kevin Wolf
Am 26.11.2026 um 16:43 hat Christian Borntraeger geschrieben:
Quoted 8 lines
the fix
-0bd5a1b3d60c("block: Fix corruption from broken RMW atomicity") results in a pretty hefty performance regression for my nvme disk via virtio-blk and multiple iothreads.I uses AI to analyze and summarize and the result was seem legit from what I can tell, so I paste this is verbatim.
I verified that0bd5a1b3d60cis bad and 0bd5a1b3d60c^ is good.
Quoted 5 lines
Do you see any difference after commit
cf4f672c(the commit right after0bd5a1b3d60c)? Some checks are temporarily duplicated, but I expected that after the second commit, there shouldn't be any visible difference.In your use case, are serialising requests actually present?
I suspect the issue is that most of the time you *don't* have serialising requests, but still have to pay for bdrv_find_conflicting_request().
block/io.c bdrv_wait_serialising_requests_locked(BdrvTrackedRequest *self) · line 708
Quoted 3 lines
block/io.c +3
-0+if (!qatomic_read (&self->bs->serialising_in_flight)) { +return ; + }
I would put that in bdrv_find_conflicting_request instead, since it is more obvious there that the loop requires a serialising request, but yeah - if the above analysis is correct that would fix it.
Also, with much joy there is no need to use atomics anymore! tracked_request_set_serialising() and bdrv_find_conflicting_request() are called with reqs_lock taken, and tracked_request_end() takes it just below decrementing req->bs->serialising_in_flight.
(And if the patch is not needed, no one reads serialising_in_flight at all).
Paolo
Am 27.11.2026 um 12:33 hat Paolo Bonzini geschrieben:
Quoted 20 lines · Kevin Wolf
Quoted 10 lines
Am 26.11.2026 um 16:43 hat Christian Borntraeger geschrieben:
Quoted 8 lines
the fix
-0bd5a1b3d60c("block: Fix corruption from broken RMW atomicity") results in a pretty hefty performance regression for my nvme disk via virtio-blk and multiple iothreads.I uses AI to analyze and summarize and the result was seem legit from what I can tell, so I paste this is verbatim.
I verified that0bd5a1b3d60cis bad and 0bd5a1b3d60c^ is good.Quoted 5 lines
Do you see any difference after commit
cf4f672c(the commit right after0bd5a1b3d60c)? Some checks are temporarily duplicated, but I expected that after the second commit, there shouldn't be any visible difference.In your use case, are serialising requests actually present?
I suspect the issue is that most of the time you *don't* have serialising requests, but still have to pay for
bdrv_find_conflicting_request().
Quoted 7 lines
block/io.c bdrv_wait_serialising_requests_locked(BdrvTrackedRequest *self) · line 708
Quoted 3 lines
block/io.c +3
-0+if (!qatomic_read (&self->bs->serialising_in_flight)) { +return ; + }I would put that in
bdrv_find_conflicting_requestinstead, since it is more obvious there that the loop requires a serialising request, but yeah - if the above analysis is correct that would fix it.
Yeah, as long as nobody adds more code around the loop in bdrv_wait_serialising_requests_locked(), that does the same thing. Not sure which one I prefer.
By the way, while you're here, what do you think about the alternative idea I mentioned, keeping a separate list bs->serialising_requests? Then you wouldn't have to have a counter any more because just checking that the list is empty isn't any slower.
Quoted 4 lines
Also, with much joy there is no need to use atomics anymore!
tracked_request_set_serialising()andbdrv_find_conflicting_request()are called withreqs_locktaken, andtracked_request_end()takes it just below decrementingreq->bs->serialising_in_flight.
Yes, I mentioned that. I just wanted to keep the patch to test as simple as possible.
Kevin
Am 27.11.26 um 14:58 schrieb Kevin Wolf:
Quoted 38 lines
Am 27.11.2026 um 12:33 hat Paolo Bonzini geschrieben:
Quoted 20 lines · Kevin Wolf
Quoted 10 lines
Am 26.11.2026 um 16:43 hat Christian Borntraeger geschrieben:
Quoted 8 lines
the fix
-0bd5a1b3d60c("block: Fix corruption from broken RMW atomicity") results in a pretty hefty performance regression for my nvme disk via virtio-blk and multiple iothreads.I uses AI to analyze and summarize and the result was seem legit from what I can tell, so I paste this is verbatim.
I verified that0bd5a1b3d60cis bad and 0bd5a1b3d60c^ is good.Quoted 5 lines
Do you see any difference after commit
cf4f672c(the commit right after0bd5a1b3d60c)? Some checks are temporarily duplicated, but I expected that after the second commit, there shouldn't be any visible difference.In your use case, are serialising requests actually present?
I suspect the issue is that most of the time you *don't* have serialising requests, but still have to pay for
bdrv_find_conflicting_request().Quoted 7 lines
block/io.c bdrv_wait_serialising_requests_locked(BdrvTrackedRequest *self) · line 708
Quoted 3 lines
block/io.c +3
-0+if (!qatomic_read (&self->bs->serialising_in_flight)) { +return ; + }I would put that in
bdrv_find_conflicting_requestinstead, since it is more obvious there that the loop requires a serialising request, but yeah - if the above analysis is correct that would fix it.Yeah, as long as nobody adds more code around the loop in
bdrv_wait_serialising_requests_locked(), that does the same thing. Not sure which one I prefer.By the way, while you're here, what do you think about the alternative idea I mentioned, keeping a separate list
bs->serialising_requests? Then you wouldn't have to have a counter any more because just checking that the list is empty isn't any slower.
Quoted 7 lines
Quoted 4 lines
Also, with much joy there is no need to use atomics anymore!
tracked_request_set_serialising()andbdrv_find_conflicting_request()are called withreqs_locktaken, andtracked_request_end()takes it just below decrementingreq->bs->serialising_in_flight.Yes, I mentioned that. I just wanted to keep the patch to test as simple as possible.
Can we still get the gix into 11.2?
Am 27.11.26 um 11:36 schrieb Kevin Wolf:
Quoted 6 lines
Am 26.11.2026 um 16:43 hat Christian Borntraeger geschrieben:
Quoted 5 lines
the fix
-0bd5a1b3d60c("block: Fix corruption from broken RMW atomicity") results in a pretty hefty performance regression for my nvme disk via virtio-blk and multiple iothreads.
Quoted 7 lines
Quoted 3 lines
I uses AI to analyze and summarize and the result was seem legit from what I can tell, so I paste this is verbatim.
I verified that0bd5a1b3d60cis bad and 0bd5a1b3d60c^ is good.Do you see any difference after commit
cf4f672c(the commit right after0bd5a1b3d60c)? Some checks are temporarily duplicated, but I expected that after the second commit, there shouldn't be any visible difference.
master is/was slow so we found this. c74f672c was not measured alone but I guess it does not make a difference.
Quoted 2 lines
In your use case, are serialising requests actually present?
very likely not.
Quoted 30 lines
Quoted 8 lines
## Description of problem
Since commit0bd5a1b3d60c("block: Fix corruption from broken RMW atomicity") and the follow-upcf4f672c11d6("block: Remove now redundantbdrv_wait_serialising_requests()calls"),tracked_request_begin()unconditionally callsbdrv_wait_serialising_requests_locked(). Thebs->serialising_in_flightfast path thatbdrv_wait_serialising_requests()used to provide is gone.Yes, that's a good point, and we could simply add this condition to
bdrv_wait_serialising_requests_locked()if the walk is expensive.In fact, I suppose we could optimise even the case that does have serialising requests by keeping a separate list of serialising requests so that we don't have to iterate over all the non-serialising requests, too. Though maybe it's not expected to have both serialising and a lot of non-serialising requests at the same time on the same disk.
Anyway, can you try out if the below patch helps? (Only compile tested.)
serialising_in_flightdoesn't actually have to be atomic any more, but it's the simplest change we can make for 11.2.Kevin
block/io.c +0
-0
block/io.c bdrv_wait_serialising_requests_locked(BdrvTrackedRequest *self) · line 712
Quoted 10 lines
block/io.c +4
-0@@ -703,6 +703,10 @@ bdrv_wait_serialising_requests_locked(BdrvTrackedRequest *self) {BdrvTrackedRequest *req; +if (!qatomic_read (&self->bs->serialising_in_flight)) { +return ; + } +while ((req =bdrv_find_conflicting_request (self))) {/* * If this request is the active owner of the data blocks it accesses,
Yes, it fixes the problem.