* performance regression due to 0bd5a1b3d60c "block: Fix corruption from broken RMW atomicity"
@ 2026-11-26 15:43 Christian Borntraeger
2026-11-27 10:36 ` Kevin Wolf
0 siblings, 1 reply; 6+ messages in thread
From: Christian Borntraeger @ 2026-11-26 15:43 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-block, qemu-s390x, qemu-devel
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: performance regression due to 0bd5a1b3d60c "block: Fix corruption from broken RMW atomicity"
2026-11-26 15:43 performance regression due to 0bd5a1b3d60c "block: Fix corruption from broken RMW atomicity" Christian Borntraeger
@ 2026-11-27 10:36 ` Kevin Wolf
2026-11-27 11:33 ` Paolo Bonzini
2026-11-27 11:33 ` Christian Borntraeger
0 siblings, 2 replies; 6+ messages in thread
From: Kevin Wolf @ 2026-11-27 10:36 UTC (permalink / raw)
To: Christian Borntraeger; +Cc: qemu-block, qemu-s390x, qemu-devel
Am 26.11.2026 um 16:43 hat Christian Borntraeger geschrieben:
> 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.
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?
> ## 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.
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
diff --git a/block/io.c b/block/io.c
index e4568d4d244..5e2734e540a 100644
--- a/block/io.c
+++ b/block/io.c
@@ -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,
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: performance regression due to 0bd5a1b3d60c "block: Fix corruption from broken RMW atomicity"
2026-11-27 10:36 ` Kevin Wolf
@ 2026-11-27 11:33 ` Paolo Bonzini
2026-11-27 13:58 ` Kevin Wolf
2026-11-27 11:33 ` Christian Borntraeger
1 sibling, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2026-11-27 11:33 UTC (permalink / raw)
To: qemu-devel, Kevin Wolf; +Cc: Christian Borntraeger, qemu-block, qemu-s390x
On Fri, 27 Nov 2026 11:36:31 +0100, Kevin Wolf wrote:
> Am 26.11.2026 um 16:43 hat Christian Borntraeger geschrieben:
>> 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.
>
> 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?
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().
> + 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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: performance regression due to 0bd5a1b3d60c "block: Fix corruption from broken RMW atomicity"
2026-11-27 11:33 ` Paolo Bonzini
@ 2026-11-27 13:58 ` Kevin Wolf
2026-11-30 9:32 ` Christian Borntraeger
0 siblings, 1 reply; 6+ messages in thread
From: Kevin Wolf @ 2026-11-27 13:58 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel, Christian Borntraeger, qemu-block, qemu-s390x
Am 27.11.2026 um 12:33 hat Paolo Bonzini geschrieben:
> On Fri, 27 Nov 2026 11:36:31 +0100, Kevin Wolf wrote:
> > Am 26.11.2026 um 16:43 hat Christian Borntraeger geschrieben:
> >> 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.
> >
> > 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?
>
> 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().
>
> > + 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.
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.
> 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.
Yes, I mentioned that. I just wanted to keep the patch to test as simple
as possible.
Kevin
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: performance regression due to 0bd5a1b3d60c "block: Fix corruption from broken RMW atomicity"
2026-11-27 13:58 ` Kevin Wolf
@ 2026-11-30 9:32 ` Christian Borntraeger
0 siblings, 0 replies; 6+ messages in thread
From: Christian Borntraeger @ 2026-11-30 9:32 UTC (permalink / raw)
To: Kevin Wolf, Paolo Bonzini; +Cc: qemu-devel, qemu-block, qemu-s390x
Am 27.11.26 um 14:58 schrieb Kevin Wolf:
> Am 27.11.2026 um 12:33 hat Paolo Bonzini geschrieben:
>> On Fri, 27 Nov 2026 11:36:31 +0100, Kevin Wolf wrote:
>>> Am 26.11.2026 um 16:43 hat Christian Borntraeger geschrieben:
>>>> 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.
>>>
>>> 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?
>>
>> 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().
>>
>>> + 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.
>
> 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.
>
>> 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.
>
> 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?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: performance regression due to 0bd5a1b3d60c "block: Fix corruption from broken RMW atomicity"
2026-11-27 10:36 ` Kevin Wolf
2026-11-27 11:33 ` Paolo Bonzini
@ 2026-11-27 11:33 ` Christian Borntraeger
1 sibling, 0 replies; 6+ messages in thread
From: Christian Borntraeger @ 2026-11-27 11:33 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-block, qemu-s390x, qemu-devel
Am 27.11.26 um 11:36 schrieb Kevin Wolf:
> Am 26.11.2026 um 16:43 hat Christian Borntraeger geschrieben:
>> 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.
>
> 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.
master is/was slow so we found this. c74f672c was not measured alone
but I guess it does not make a difference.
>
> In your use case, are serialising requests actually present?
very likely not.
>
>> ## 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.
>
> 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
>
>
> diff --git a/block/io.c b/block/io.c
> index e4568d4d244..5e2734e540a 100644
> --- a/block/io.c
> +++ b/block/io.c
> @@ -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.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-30 9:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 15:43 performance regression due to 0bd5a1b3d60c "block: Fix corruption from broken RMW atomicity" Christian Borntraeger
2026-11-27 10:36 ` Kevin Wolf
2026-11-27 11:33 ` Paolo Bonzini
2026-11-27 13:58 ` Kevin Wolf
2026-11-30 9:32 ` Christian Borntraeger
2026-11-27 11:33 ` Christian Borntraeger
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.