block/io: skip conflict scan when no serialising requests exist
PATCH 1/1 block/io: skip conflict scan when no serialising requests exist
bdrv_find_conflicting_request() always linearly scans the tracked_requests list looking for overlapping serialising requests. However, BlockDriverState already maintains a serialising_in_flight atomic counter that is incremented/decremented as serialising requests are created/destroyed.
When the counter is zero there are no serialising requests in the list and the scan is guaranteed to find nothing, so return NULL immediately. This complements the existing fast path in bdrv_wait_serialising_requests() which checks the same counter before acquiring reqs_lock.
No functional change.
--- block/io.c | 9 +++++++++ 1 file changed, 9 insertions(+)
block/io.c +9 -0
@@ -649,6 +649,15 @@ bdrv_find_conflicting_request(BdrvTrackedRequest *self) {BdrvTrackedRequest *req; +/* +* Fast path: if there are no serialising requests in flight, there +* can be no conflicts. This mirrors the check in +* bdrv_wait_serialising_requests(). +*/ +if (!qatomic_read (&self->bs->serialising_in_flight)) { +return NULL ; + } + QLIST_FOREACH(req, &self->bs->tracked_requests, list) {if (req == self || (!req->serialising && !self->serialising)) {continue ;
Signature · 1 line
2.50.1 (Apple Git-155)
Am 29.05.2026 um 05:12 hat Bin Guo geschrieben:
Quoted 25 lines
bdrv_find_conflicting_request()always linearly scans thetracked_requestslist looking for overlapping serialising requests. However, BlockDriverState already maintains aserialising_in_flightatomic counter that is incremented/decremented as serialising requests are created/destroyed.When the counter is zero there are no serialising requests in the list and the scan is guaranteed to find nothing, so return NULL immediately. This complements the existing fast path in
bdrv_wait_serialising_requests()which checks the same counter before acquiringreqs_lock.No functional change.
Signed-off-by Bin Guo <[email protected]>--- block/io.c | 9 +++++++++ 1 file changed, 9 insertions(+)block/io.c +0
-0@@ -649,6 +649,15 @@ bdrv_find_conflicting_request(BdrvTrackedRequest *self) {
block/io.c bdrv_find_conflicting_request(BdrvTrackedRequest *self) · line 659
Quoted 10 lines
block/io.c +8
-0BdrvTrackedRequest *req; +/* +* Fast path: if there are no serialising requests in flight, there +* can be no conflicts. This mirrors the check in +* bdrv_wait_serialising_requests(). +*/ +if (!qatomic_read (&self->bs->serialising_in_flight)) { +return NULL ; + }
Isn't this dead code? You get the following callers:
- bdrv_wait_serialising_requests_locked
- bdrv_wait_serialising_requests: Already has the check, as you mention in the commit message
- bdrv_make_request_serialising: tracked_request_set_serialising()
increases bs->serialising_in_flight
- bdrv_co_write_req_prepare: tracked_request_set_serialising() again
I think the only way this could trigger if you hit the minimal race window in bdrv_wait_serialising_requests() between the identical check and taking the lock.
Kevin