aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2023-08-08 11:58:52 -0400
committerKevin Wolf <kwolf@redhat.com>2023-09-08 17:03:09 +0200
commitfa9185fcdfceeb1a02f61a003acd19509e146bde (patch)
tree13ca265e77ddfb14b193c0a4dd7cdb62649a469c /block.c
parent3480ce69a9c7ee956323c45269d21b6905488904 (diff)
downloadqemu-fa9185fcdfceeb1a02f61a003acd19509e146bde.zip
qemu-fa9185fcdfceeb1a02f61a003acd19509e146bde.tar.gz
qemu-fa9185fcdfceeb1a02f61a003acd19509e146bde.tar.bz2
block: change reqs_lock to QemuMutex
CoMutex has poor performance when lock contention is high. The tracked requests list is accessed frequently and performance suffers in QEMU multi-queue block layer scenarios. It is not necessary to use CoMutex for the requests lock. The lock is always released across coroutine yield operations. It is held for relatively short periods of time and it is not beneficial to yield when the lock is held by another coroutine. Change the lock type from CoMutex to QemuMutex to improve multi-queue block layer performance. fio randread bs=4k iodepth=64 with 4 IOThreads handling a virtio-blk device with 8 virtqueues improves from 254k to 517k IOPS (+203%). Full benchmark results and configuration details are available here: https://gitlab.com/stefanha/virt-playbooks/-/commit/980c40845d540e3669add1528739503c2e817b57 In the future we may wish to introduce thread-local tracked requests lists to avoid lock contention completely. That would be much more involved though. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-ID: <20230808155852.2745350-3-stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/block.c b/block.c
index 0af890f..b79b1ce 100644
--- a/block.c
+++ b/block.c
@@ -415,7 +415,7 @@ BlockDriverState *bdrv_new(void)
for (i = 0; i < BLOCK_OP_TYPE_MAX; i++) {
QLIST_INIT(&bs->op_blockers[i]);
}
- qemu_co_mutex_init(&bs->reqs_lock);
+ qemu_mutex_init(&bs->reqs_lock);
qemu_mutex_init(&bs->dirty_bitmap_mutex);
bs->refcnt = 1;
bs->aio_context = qemu_get_aio_context();
@@ -5476,6 +5476,8 @@ static void bdrv_delete(BlockDriverState *bs)
bdrv_close(bs);
+ qemu_mutex_destroy(&bs->reqs_lock);
+
g_free(bs);
}