virtio-pci: enable blk and scsi multi-queue by default
v5 cover virtio-pci: enable blk and scsi multi-queue by default
v4:
* Sorry for the long delay. I considered replacing this series with a simpler approach. Real hardware ships with a fixed number of queues (e.g. 128). The equivalent can be done in QEMU too. That way we don't need to magically size num_queues. In the end I decided against this approach because the Linux virtio_blk.ko and virtio_scsi.ko guest drivers unconditionally initialized all available queues until recently (it was written with num_queues=num_vcpus in mind). It doesn't make sense for a 1 CPU guest to bring up 128 virtqueues (waste of resources and possibly weird performance effects with blk-mq).
* Honor maximum number of MSI-X vectors and virtqueues [Daniel Berrange]
* Update commit descriptions to mention maximum MSI-X vector and virtqueue caps [Raphael]
v3:
* Introduce virtio_pci_optimal_num_queues() helper to enforce VIRTIO_QUEUE_MAX in one place
* Use VIRTIO_SCSI_VQ_NUM_FIXED constant in all cases [Cornelia]
* Update hw/core/machine.c compat properties for QEMU 5.0 [Michael]
v3:
* Add new performance results that demonstrate the scalability
* Mention that this is PCI-specific [Cornelia]
v2:
* Let the virtio-DEVICE-pci device select num-queues because the optimal multi-queue configuration may differ between virtio-pci, virtio-mmio, and virtio-ccw [Cornelia]
Enabling multi-queue on virtio-pci storage devices improves performance on SMP guests because the completion interrupt is handled on the vCPU that submitted the I/O request. This avoids IPIs inside the guest.
Note that performance is unchanged in these cases:
1. Uniprocessor guests. They don't have IPIs.
2. Application threads might be scheduled on the sole vCPU that handles completion interrupts purely by chance. (This is one reason why benchmark results can vary noticably between runs.)
3. Users may bind the application to the vCPU that handles completion interrupts.
Set the number of queues to the number of vCPUs by default on virtio-blk and virtio-scsi PCI devices. Older machine types continue to default to 1 queue for live migration compatibility.
Random read performance:
IOPS
q=1 78k
q=32 104k +33%
Boot time:
Duration
q=1 51s
q=32 1m41s +98%
Guest configuration: 32 vCPUs, 101 virtio-blk-pci disks
Previously measured results on a 4 vCPU guest were also positive but showed a smaller 1-4% performance improvement. They are no longer valid because significant event loop optimizations have been merged.
Stefan Hajnoczi (5):
virtio-pci: add virtio_pci_optimal_num_queues() helper
virtio-scsi: introduce a constant for fixed virtqueues
virtio-scsi: default num_queues to -smp N
virtio-blk: default num_queues to -smp N
vhost-user-blk: default num_queues to -smp N
hw/virtio/virtio-pci.h | 9 +++++++++ include/hw/virtio/vhost-user-blk.h | 2 ++ include/hw/virtio/virtio-blk.h | 2 ++ include/hw/virtio/virtio-scsi.h | 5 +++++ hw/block/vhost-user-blk.c | 6 +++++- hw/block/virtio-blk.c | 6 +++++- hw/core/machine.c | 5 +++++ hw/scsi/vhost-scsi.c | 3 ++- hw/scsi/vhost-user-scsi.c | 5 +++-- hw/scsi/virtio-scsi.c | 13 ++++++++---- hw/virtio/vhost-scsi-pci.c | 9 +++++++-- hw/virtio/vhost-user-blk-pci.c | 4 ++++ hw/virtio/vhost-user-scsi-pci.c | 9 +++++++-- hw/virtio/virtio-blk-pci.c | 7 ++++++- hw/virtio/virtio-pci.c | 32 ++++++++++++++++++++++++++++++ hw/virtio/virtio-scsi-pci.c | 9 +++++++-- 16 files changed, 110 insertions(+), 16 deletions(-)
Signature · 1 line
2.26.2
PATCH v5 1/5 virtio-pci: add virtio_pci_optimal_num_queues() helper
Multi-queue devices achieve the best performance when each vCPU has a dedicated queue. This ensures that virtqueue used notifications are handled on the same vCPU that submitted virtqueue buffers. When another vCPU handles the the notification an IPI will be necessary to wake the submission vCPU and this incurs a performance overhead.
Provide a helper function that virtio-pci devices will use in later patches to automatically select the optimal number of queues.
The function handles guests with large numbers of CPUs by limiting the number of queues to fit within the following constraints:
1. The maximum number of MSI-X vectors.
2. The maximum number of virtqueues.
--- hw/virtio/virtio-pci.h | 9 +++++++++ hw/virtio/virtio-pci.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
hw/virtio/virtio-pci.h +9 -0
@@ -243,4 +243,13 @@ typedef struct VirtioPCIDeviceTypeInfo {/* Register virtio-pci type(s). @t must be static. */ void virtio_pci_types_register (const VirtioPCIDeviceTypeInfo *t); +/** +* virtio_pci_optimal_num_queues: +* @fixed_queues: number of queues that are always present +* +* Returns: The optimal number of queues for a multi-queue device, excluding +* @fixed_queues. +*/ +unsigned virtio_pci_optimal_num_queues (unsigned fixed_queues); +#endif
hw/virtio/virtio-pci.c +32 -0
@@ -19,6 +19,7 @@#include "exec/memop.h" #include "standard-headers/linux/virtio_pci.h" +#include "hw/boards.h" #include "hw/virtio/virtio.h" #include "migration/qemu-file-types.h" #include "hw/pci/pci.h"
@@ -2028,6 +2029,37 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)g_free (base_name); } +unsigned virtio_pci_optimal_num_queues (unsigned fixed_queues) +{ +/* +* 1:1 vq to vCPU mapping is ideal because the same vCPU that submitted +* virtqueue buffers can handle their completion. When a different vCPU +* handles completion it may need to IPI the vCPU that submitted the +* request and this adds overhead. +* +* Virtqueues consume guest RAM and MSI-X vectors. This is wasteful in +* guests with very many vCPUs and a device that is only used by a few +* vCPUs. Unfortunately optimizing that case requires manual pinning inside +* the guest, so those users might as well manually set the number of +* queues. There is no upper limit that can be applied automatically and +* doing so arbitrarily would result in a sudden performance drop once the +* threshold number of vCPUs is exceeded. +*/ +unsigned num_queues = current_machine->smp.cpus; + +/* +* The maximum number of MSI-X vectors is PCI_MSIX_FLAGS_QSIZE + 1, but the +* config change interrupt and the fixed virtqueues must be taken into +* account too. +*/ + num_queues =MIN (num_queues,PCI_MSIX_FLAGS_QSIZE - fixed_queues); + +/* +* There is a limit to how many virtqueues a device can have. +*/ +return MIN (num_queues,VIRTIO_QUEUE_MAX - fixed_queues); +} +/* virtio-pci-bus */ static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
Signature · 1 line
2.26.2
Re: [PATCH v5 1/5] virtio-pci: add virtio_pci_optimal_num_queues() helper
Quoted 14 lines · On Mon, 6 Jul 2020 14:56:46 +0100 Stefan Hajnoczi <[email protected]> wrote:
Multi-queue devices achieve the best performance when each vCPU has a dedicated queue. This ensures that virtqueue used notifications are handled on the same vCPU that submitted virtqueue buffers. When another vCPU handles the the notification an IPI will be necessary to wake the submission vCPU and this incurs a performance overhead.
Provide a helper function that virtio-pci devices will use in later patches to automatically select the optimal number of queues.
The function handles guests with large numbers of CPUs by limiting the number of queues to fit within the following constraints:
1. The maximum number of MSI-X vectors.
2. The maximum number of virtqueues.
Quoted 5 lines
Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/virtio/virtio-pci.h | 9 +++++++++ hw/virtio/virtio-pci.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
I guess this should honour all relevant limits now.
PATCH v5 2/5 virtio-scsi: introduce a constant for fixed virtqueues
In reply to Stefan HajnocziThe event and control virtqueues are always present, regardless of the multi-queue configuration. Define a constant so that virtqueue number calculations are easier to read.
--- include/hw/virtio/virtio-scsi.h | 3 +++ hw/scsi/vhost-user-scsi.c | 2 +- hw/scsi/virtio-scsi.c | 7 ++++--- hw/virtio/vhost-scsi-pci.c | 3 ++- hw/virtio/vhost-user-scsi-pci.c | 3 ++- hw/virtio/virtio-scsi-pci.c | 3 ++- 6 files changed, 14 insertions(+), 7 deletions(-)
include/hw/virtio/virtio-scsi.h +3 -0
@@ -36,6 +36,9 @@#define VIRTIO_SCSI_MAX_TARGET 255#define VIRTIO_SCSI_MAX_LUN 16383 +/* Number of virtqueues that are always present */ +#define VIRTIO_SCSI_VQ_NUM_FIXED 2 +typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq ;typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp ;typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq ;
hw/scsi/vhost-user-scsi.c +1 -1
@@ -114,7 +114,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) goto free_virtio; } - vsc->dev.nvqs =2 + vs->conf.num_queues; + vsc->dev.nvqs =VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; vsc->dev.vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs); vsc->dev.vq_index =0 ; vsc->dev.backend_features =0 ;
hw/scsi/virtio-scsi.c +4 -3
@@ -191,7 +191,7 @@ static void virtio_scsi_save_request(QEMUFile *f, SCSIRequest *sreq)VirtIOSCSIReq *req = sreq->hba_private;VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (req->dev);VirtIODevice *vdev =VIRTIO_DEVICE (req->dev); -uint32_t n =virtio_get_queue_index (req->vq) -2 ; +uint32_t n =virtio_get_queue_index (req->vq) -VIRTIO_SCSI_VQ_NUM_FIXED ;assert (n < vs->conf.num_queues);qemu_put_be32s (f, &n);
@@ -892,10 +892,11 @@ void virtio_scsi_common_realize(DeviceState *dev, sizeof(VirtIOSCSIConfig));if (s->conf.num_queues ==0 || - s->conf.num_queues >VIRTIO_QUEUE_MAX -2 ) { + s->conf.num_queues >VIRTIO_QUEUE_MAX -VIRTIO_SCSI_VQ_NUM_FIXED ) {error_setg (errp,"Invalid number of queues (= %" PRIu32"), " "must be a positive integer less than %d." , - s->conf.num_queues,VIRTIO_QUEUE_MAX -2 ); + s->conf.num_queues, +VIRTIO_QUEUE_MAX -VIRTIO_SCSI_VQ_NUM_FIXED );virtio_cleanup (vdev);return ; }
hw/virtio/vhost-scsi-pci.c +2 -1
@@ -50,7 +50,8 @@ static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues +3 ; + vpci_dev->nvectors = vs->conf.num_queues + +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);
hw/virtio/vhost-user-scsi-pci.c +2 -1
@@ -56,7 +56,8 @@ static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues +3 ; + vpci_dev->nvectors = vs->conf.num_queues + +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);
hw/virtio/virtio-scsi-pci.c +2 -1
@@ -51,7 +51,8 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)char *bus_name;if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues +3 ; + vpci_dev->nvectors = vs->conf.num_queues + +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }/*
Signature · 1 line
2.26.2
PATCH v5 3/5 virtio-scsi: default num_queues to -smp N
In reply to Stefan HajnocziAutomatically size the number of virtio-scsi-pci, vhost-scsi-pci, and vhost-user-scsi-pci request virtqueues to match the number of vCPUs. Other transports continue to default to 1 request virtqueue.
A 1:1 virtqueue:vCPU mapping ensures that completion interrupts are handled on the same vCPU that submitted the request. No IPI is necessary to complete an I/O request and performance is improved. The maximum number of MSI-X vectors and virtqueues limit are respected.
--- include/hw/virtio/virtio-scsi.h | 2 ++ hw/core/machine.c | 3 +++ hw/scsi/vhost-scsi.c | 3 ++- hw/scsi/vhost-user-scsi.c | 3 ++- hw/scsi/virtio-scsi.c | 6 +++++- hw/virtio/vhost-scsi-pci.c | 10 +++++++--- hw/virtio/vhost-user-scsi-pci.c | 10 +++++++--- hw/virtio/virtio-scsi-pci.c | 10 +++++++--- 8 files changed, 35 insertions(+), 12 deletions(-)
include/hw/virtio/virtio-scsi.h +2 -0
@@ -39,6 +39,8 @@/* Number of virtqueues that are always present */ #define VIRTIO_SCSI_VQ_NUM_FIXED 2 +#define VIRTIO_SCSI_AUTO_NUM_QUEUES UINT32_MAX +typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq ;typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp ;typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq ;
hw/core/machine.c +3 -0
@@ -29,7 +29,10 @@#include "migration/vmstate.h" GlobalProperty hw_compat_5_0[] = { + {"vhost-scsi" ,"num_queues" ,"1" }, + {"vhost-user-scsi" ,"num_queues" ,"1" }, {"virtio-balloon-device" ,"page-poison" ,"false" }, + {"virtio-scsi-device" ,"num_queues" ,"1" }, {"vmport" ,"x-read-set-eax" ,"off" }, {"vmport" ,"x-signal-unsupported-cmd" ,"off" }, {"vmport" ,"x-report-vmx-type" ,"off" },
hw/scsi/vhost-scsi.c +2 -1
@@ -272,7 +272,8 @@ static Property vhost_scsi_properties[] = {DEFINE_PROP_STRING ("vhostfd" , VirtIOSCSICommon, conf.vhostfd),DEFINE_PROP_STRING ("wwpn" , VirtIOSCSICommon, conf.wwpn),DEFINE_PROP_UINT32 ("boot_tpgt" , VirtIOSCSICommon, conf.boot_tpgt,0 ), -DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSICommon, conf.num_queues,1 ), +DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSICommon, conf.num_queues, +VIRTIO_SCSI_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("virtqueue_size" , VirtIOSCSICommon, conf.virtqueue_size,128 ), DEFINE_PROP_BOOL("seg_max_adjust", VirtIOSCSICommon, conf.seg_max_adjust,
hw/scsi/vhost-user-scsi.c +2 -1
@@ -162,7 +162,8 @@ static void vhost_user_scsi_unrealize(DeviceState *dev)static Property vhost_user_scsi_properties[] = {DEFINE_PROP_CHR ("chardev" , VirtIOSCSICommon, conf.chardev),DEFINE_PROP_UINT32 ("boot_tpgt" , VirtIOSCSICommon, conf.boot_tpgt,0 ), -DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSICommon, conf.num_queues,1 ), +DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSICommon, conf.num_queues, +VIRTIO_SCSI_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("virtqueue_size" , VirtIOSCSICommon, conf.virtqueue_size,128 ), DEFINE_PROP_UINT32("max_sectors", VirtIOSCSICommon, conf.max_sectors,
hw/scsi/virtio-scsi.c +5 -1
@@ -891,6 +891,9 @@ void virtio_scsi_common_realize(DeviceState *dev,virtio_init (vdev,"virtio-scsi" ,VIRTIO_ID_SCSI ,sizeof (VirtIOSCSIConfig)); +if (s->conf.num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + s->conf.num_queues =1 ; + }if (s->conf.num_queues ==0 || s->conf.num_queues >VIRTIO_QUEUE_MAX -VIRTIO_SCSI_VQ_NUM_FIXED ) { error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
@@ -964,7 +967,8 @@ static void virtio_scsi_device_unrealize(DeviceState *dev) }static Property virtio_scsi_properties[] = { -DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSI, parent_obj.conf.num_queues,1 ), +DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSI, parent_obj.conf.num_queues, +VIRTIO_SCSI_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("virtqueue_size" , VirtIOSCSI, parent_obj.conf.virtqueue_size,256 ), DEFINE_PROP_BOOL("seg_max_adjust", VirtIOSCSI,
hw/virtio/vhost-scsi-pci.c +7 -3
@@ -47,11 +47,15 @@ static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VHostSCSIPCI *dev =VHOST_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.parent_obj.conf; + +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + }if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);
hw/virtio/vhost-user-scsi-pci.c +7 -3
@@ -53,11 +53,15 @@ static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VHostUserSCSIPCI *dev =VHOST_USER_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.parent_obj.conf; + +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + }if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);
hw/virtio/virtio-scsi-pci.c +7 -3
@@ -46,13 +46,17 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VirtIOSCSIPCI *dev =VIRTIO_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);DeviceState *proxy =DEVICE (vpci_dev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.conf;char *bus_name; +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + } +if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }/*
Signature · 1 line
2.26.2
Re: [PATCH v5 3/5] virtio-scsi: default num_queues to -smp N
On Mon, 6 Jul 2020 14:56:48 +0100
Stefan Hajnoczi <[email protected]> wrote:
Maybe mention 'pci' in the subject as well?
Quoted 20 lines
Automatically size the number of virtio-scsi-pci, vhost-scsi-pci, and vhost-user-scsi-pci request virtqueues to match the number of vCPUs. Other transports continue to default to 1 request virtqueue.
A 1:1 virtqueue:vCPU mapping ensures that completion interrupts are handled on the same vCPU that submitted the request. No IPI is necessary to complete an I/O request and performance is improved. The maximum number of MSI-X vectors and virtqueues limit are respected.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/virtio/virtio-scsi.h | 2 ++ hw/core/machine.c | 3 +++ hw/scsi/vhost-scsi.c | 3 ++- hw/scsi/vhost-user-scsi.c | 3 ++- hw/scsi/virtio-scsi.c | 6 +++++- hw/virtio/vhost-scsi-pci.c | 10 +++++++--- hw/virtio/vhost-user-scsi-pci.c | 10 +++++++--- hw/virtio/virtio-scsi-pci.c | 10 +++++++--- 8 files changed, 35 insertions(+), 12 deletions(-)
(...)
Quoted 15 lines
hw/virtio/virtio-scsi-pci.c +3
-1@@ -46,13 +46,17 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VirtIOSCSIPCI *dev =VIRTIO_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);DeviceState *proxy =DEVICE (vpci_dev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.conf;char *bus_name; +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues =
hw/virtio/virtio-scsi-pci.c static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) · line 62
Quoted 10 lines
hw/virtio/virtio-scsi-pci.c +4
-2+virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + } +if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }/*
One corner case where the setup may end up being a bit odd is a situation where nvectors was specified, but num_queues was not, and the device suddenly ends up with more queues than vectors. But I don't see a reason why you would want to specify nvectors but not num_queues in a real word scenario, so I think we can ignore that corner case.
Re: [PATCH v5 3/5] virtio-scsi: default num_queues to -smp N
Quoted 4 lines · Cornelia Huck
On Mon, 6 Jul 2020 14:56:48 +0100
Stefan Hajnoczi <[email protected]> wrote:Maybe mention 'pci' in the subject as well?
Actually splitting up the patch is hard due to the nvectors dependency on num_queues. I will leave it as a single patch and rewrite the commit message.
Stefan
Re: [PATCH v5 3/5] virtio-scsi: default num_queues to -smp N
In reply to Cornelia HuckQuoted 4 lines · Cornelia Huck
On Mon, 6 Jul 2020 14:56:48 +0100
Stefan Hajnoczi <[email protected]> wrote:Maybe mention 'pci' in the subject as well?
I think this patch does too many things. I'll split up the generic and PCI parts so that the commit message is more accurate.
Quoted 47 lines
Quoted 20 lines
Automatically size the number of virtio-scsi-pci, vhost-scsi-pci, and vhost-user-scsi-pci request virtqueues to match the number of vCPUs. Other transports continue to default to 1 request virtqueue.
A 1:1 virtqueue:vCPU mapping ensures that completion interrupts are handled on the same vCPU that submitted the request. No IPI is necessary to complete an I/O request and performance is improved. The maximum number of MSI-X vectors and virtqueues limit are respected.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/virtio/virtio-scsi.h | 2 ++ hw/core/machine.c | 3 +++ hw/scsi/vhost-scsi.c | 3 ++- hw/scsi/vhost-user-scsi.c | 3 ++- hw/scsi/virtio-scsi.c | 6 +++++- hw/virtio/vhost-scsi-pci.c | 10 +++++++--- hw/virtio/vhost-user-scsi-pci.c | 10 +++++++--- hw/virtio/virtio-scsi-pci.c | 10 +++++++--- 8 files changed, 35 insertions(+), 12 deletions(-)(...)
Quoted 24 lines
hw/virtio/virtio-scsi-pci.c +7
-3@@ -46,13 +46,17 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VirtIOSCSIPCI *dev =VIRTIO_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);DeviceState *proxy =DEVICE (vpci_dev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.conf;char *bus_name; +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + } +if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }
Quoted 7 lines
hw/virtio/virtio-scsi-pci.c static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) · line 62
Quoted 1 line
hw/virtio/virtio-scsi-pci.c +0
-0/* One corner case where the setup may end up being a bit odd is a situation where nvectors was specified, but
num_queueswas not, and the device suddenly ends up with more queues than vectors. But I don't see a reason why you would want to specify nvectors but notnum_queuesin a real word scenario, so I think we can ignore that corner case.
I agree, I've ignored that case. Other options include printing a warning or even an error when num_queues disagrees with nvectors.
Quoted 1 line
Reviewed-by Cornelia Huck <[email protected]>
Re: [PATCH v5 3/5] virtio-scsi: default num_queues to -smp N
Quoted 36 lines · On Wed, 8 Jul 2020 14:05:26 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 27 lines · Cornelia Huck
Quoted 24 lines · On Mon, 6 Jul 2020 14:56:48 +0100 Stefan Hajnoczi <[email protected]> wrote:
hw/virtio/virtio-scsi-pci.c +7
-3@@ -46,13 +46,17 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VirtIOSCSIPCI *dev =VIRTIO_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);DeviceState *proxy =DEVICE (vpci_dev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.conf;char *bus_name; +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + } +if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }Quoted 7 lines
hw/virtio/virtio-scsi-pci.c static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) · line 62
Quoted 1 line
hw/virtio/virtio-scsi-pci.c +0
-0/* One corner case where the setup may end up being a bit odd is a situation where nvectors was specified, but
num_queueswas not, and the device suddenly ends up with more queues than vectors. But I don't see a reason why you would want to specify nvectors but notnum_queuesin a real word scenario, so I think we can ignore that corner case.
Quoted 2 lines
I agree, I've ignored that case. Other options include printing a warning or even an error when
num_queuesdisagrees with nvectors.
I think an error would be too harsh, but a warning sounds useful.
Re: [PATCH v5 3/5] virtio-scsi: default num_queues to -smp N
Quoted 39 lines · Cornelia Huck
Quoted 36 lines · On Wed, 8 Jul 2020 14:05:26 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 34 lines · Cornelia Huck
Quoted 15 lines · On Mon, 6 Jul 2020 14:56:48 +0100 Stefan Hajnoczi <[email protected]> wrote:
hw/virtio/virtio-scsi-pci.c +3
-1@@ -46,13 +46,17 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VirtIOSCSIPCI *dev =VIRTIO_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);DeviceState *proxy =DEVICE (vpci_dev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.conf;char *bus_name; +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues =hw/virtio/virtio-scsi-pci.c static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) · line 62
Quoted 10 lines
hw/virtio/virtio-scsi-pci.c +4
-2+virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + } +if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }/* One corner case where the setup may end up being a bit odd is a situation where nvectors was specified, but
num_queueswas not, and the device suddenly ends up with more queues than vectors. But I don't see a reason why you would want to specify nvectors but notnum_queuesin a real word scenario, so I think we can ignore that corner case.
Quoted 4 lines
Quoted 2 lines
I agree, I've ignored that case. Other options include printing a warning or even an error when
num_queuesdisagrees with nvectors.I think an error would be too harsh, but a warning sounds useful.
I'll send this as a separate patch because at least virtio-serial is also affected.
Stefan
PATCH v5 4/5 virtio-blk: default num_queues to -smp N
In reply to Stefan HajnocziAutomatically size the number of virtio-blk-pci request virtqueues to match the number of vCPUs. Other transports continue to default to 1 request virtqueue.
A 1:1 virtqueue:vCPU mapping ensures that completion interrupts are handled on the same vCPU that submitted the request. No IPI is necessary to complete an I/O request and performance is improved. The maximum number of MSI-X vectors and virtqueues limit are respected.
Performance improves from 78k to 104k IOPS on a 32 vCPU guest with 101 virtio-blk-pci devices (ioengine=libaio, iodepth=1, bs=4k, rw=randread with NVMe storage).
--- include/hw/virtio/virtio-blk.h | 2 ++ hw/block/virtio-blk.c | 6 +++++- hw/core/machine.c | 1 + hw/virtio/virtio-blk-pci.c | 7 ++++++- 4 files changed, 14 insertions(+), 2 deletions(-)
include/hw/virtio/virtio-blk.h +2 -0
@@ -30,6 +30,8 @@ struct virtio_blk_inhdrunsigned char status; }; +#define VIRTIO_BLK_AUTO_NUM_QUEUES UINT16_MAX +struct VirtIOBlkConf {BlockConf conf;
hw/block/virtio-blk.c +5 -1
@@ -1147,6 +1147,9 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)error_setg (errp,"Device needs media, but drive is empty" );return ; } +if (conf->num_queues ==VIRTIO_BLK_AUTO_NUM_QUEUES ) { + conf->num_queues =1 ; + }if (!conf->num_queues) {error_setg (errp,"num-queues property must be larger than 0" );return ;
@@ -1281,7 +1284,8 @@ static Property virtio_blk_properties[] = {#endif DEFINE_PROP_BIT ("request-merging" , VirtIOBlock, conf.request_merging,0 , true), -DEFINE_PROP_UINT16 ("num-queues" , VirtIOBlock, conf.num_queues,1 ), +DEFINE_PROP_UINT16 ("num-queues" , VirtIOBlock, conf.num_queues, +VIRTIO_BLK_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT16 ("queue-size" , VirtIOBlock, conf.queue_size,256 ),DEFINE_PROP_BOOL ("seg-max-adjust" , VirtIOBlock, conf.seg_max_adjust, true), DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD,
hw/core/machine.c +1 -0
@@ -32,6 +32,7 @@ GlobalProperty hw_compat_5_0[] = { { "vhost-scsi", "num_queues", "1"}, { "vhost-user-scsi", "num_queues", "1"}, { "virtio-balloon-device", "page-poison", "false" }, + { "virtio-blk-device", "num-queues", "1"}, { "virtio-scsi-device", "num_queues", "1"}, { "vmport", "x-read-set-eax", "off" }, { "vmport", "x-signal-unsupported-cmd", "off" },
hw/virtio/virtio-blk-pci.c +6 -1
@@ -50,9 +50,14 @@ static void virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VirtIOBlkPCI *dev =VIRTIO_BLK_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); +VirtIOBlkConf *conf = &dev->vdev.conf; + +if (conf->num_queues ==VIRTIO_BLK_AUTO_NUM_QUEUES ) { + conf->num_queues =virtio_pci_optimal_num_queues (0 ); + }if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = dev->vdev.conf.num_queues +1 ; + vpci_dev->nvectors = conf->num_queues +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);
Signature · 1 line
2.26.2
PATCH v5 5/5 vhost-user-blk: default num_queues to -smp N
In reply to Stefan HajnocziAutomatically size the number of request virtqueues to match the number of vCPUs. This ensures that completion interrupts are handled on the same vCPU that submitted the request. No IPI is necessary to complete an I/O request and performance is improved. The maximum number of MSI-X vectors and virtqueues limit are respected.
--- include/hw/virtio/vhost-user-blk.h | 2 ++ hw/block/vhost-user-blk.c | 6 +++++- hw/core/machine.c | 1 + hw/virtio/vhost-user-blk-pci.c | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-)
include/hw/virtio/vhost-user-blk.h +2 -0
@@ -25,6 +25,8 @@#define VHOST_USER_BLK (obj) \ OBJECT_CHECK(VHostUserBlk, (obj), TYPE_VHOST_USER_BLK) +#define VHOST_USER_BLK_AUTO_NUM_QUEUES UINT16_MAX + typedef struct VHostUserBlk { VirtIODevice parent_obj; CharBackend chardev;
hw/block/vhost-user-blk.c +5 -1
@@ -420,6 +420,9 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)return ; } +if (s->num_queues ==VHOST_USER_BLK_AUTO_NUM_QUEUES ) { + s->num_queues =1 ; + }if (!s->num_queues || s->num_queues >VIRTIO_QUEUE_MAX ) {error_setg (errp,"vhost-user-blk: invalid number of IO queues" );return ;
@@ -531,7 +534,8 @@ static const VMStateDescription vmstate_vhost_user_blk = {static Property vhost_user_blk_properties[] = {DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), -DEFINE_PROP_UINT16 ("num-queues" , VHostUserBlk, num_queues,1 ), +DEFINE_PROP_UINT16 ("num-queues" , VHostUserBlk, num_queues, +VHOST_USER_BLK_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("queue-size" , VHostUserBlk, queue_size,128 ),DEFINE_PROP_BIT ("config-wce" , VHostUserBlk, config_wce,0 , true),DEFINE_PROP_END_OF_LIST (),
hw/core/machine.c +1 -0
@@ -30,6 +30,7 @@GlobalProperty hw_compat_5_0[] = { {"vhost-scsi" ,"num_queues" ,"1" }, + {"vhost-user-blk" ,"num-queues" ,"1" }, {"vhost-user-scsi" ,"num_queues" ,"1" }, {"virtio-balloon-device" ,"page-poison" ,"false" }, {"virtio-blk-device" ,"num-queues" ,"1" },
hw/virtio/vhost-user-blk-pci.c +4 -0
@@ -54,6 +54,10 @@ static void vhost_user_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)VHostUserBlkPCI *dev =VHOST_USER_BLK_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); +if (dev->vdev.num_queues ==VHOST_USER_BLK_AUTO_NUM_QUEUES ) { + dev->vdev.num_queues =virtio_pci_optimal_num_queues (0 ); + } +if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { vpci_dev->nvectors = dev->vdev.num_queues +1 ; }
Signature · 1 line
2.26.2
Re: [PATCH v5 5/5] vhost-user-blk: default num_queues to -smp N
Quoted 34 lines · Stefan Hajnoczi
Automatically size the number of request virtqueues to match the number of vCPUs. This ensures that completion interrupts are handled on the same vCPU that submitted the request. No IPI is necessary to complete an I/O request and performance is improved. The maximum number of MSI-X vectors and virtqueues limit are respected.
Signed-off-by Stefan Hajnoczi <[email protected]>Reviewed-by Cornelia Huck <[email protected]>--- include/hw/virtio/vhost-user-blk.h | 2 ++ hw/block/vhost-user-blk.c | 6 +++++- hw/core/machine.c | 1 + hw/virtio/vhost-user-blk-pci.c | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-)include/hw/virtio/vhost-user-blk.h +2
-0@@ -25,6 +25,8 @@#define VHOST_USER_BLK (obj) \ OBJECT_CHECK(VHostUserBlk, (obj), TYPE_VHOST_USER_BLK) +#define VHOST_USER_BLK_AUTO_NUM_QUEUES UINT16_MAX + typedef struct VHostUserBlk { VirtIODevice parent_obj; CharBackend chardev;hw/block/vhost-user-blk.c +0
-0
hw/block/vhost-user-blk.c static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) · line 425
Quoted 6 lines
hw/block/vhost-user-blk.c +3
-0@@ -420,6 +420,9 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)return ; } +if (s->num_queues ==VHOST_USER_BLK_AUTO_NUM_QUEUES ) { + s->num_queues =1 ; + }
What is this check for? Is it just a backstop to ensure that num_queues is set to 1 if vhost-user-blk-pci doesn't update it?
Quoted 43 lines
hw/block/vhost-user-blk.c +2
-1if (!s->num_queues || s->num_queues >VIRTIO_QUEUE_MAX ) {error_setg (errp,"vhost-user-blk: invalid number of IO queues" );return ;@@ -531,7 +534,8 @@ static const VMStateDescription vmstate_vhost_user_blk = {static Property vhost_user_blk_properties[] = {DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), -DEFINE_PROP_UINT16 ("num-queues" , VHostUserBlk, num_queues,1 ), +DEFINE_PROP_UINT16 ("num-queues" , VHostUserBlk, num_queues, +VHOST_USER_BLK_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("queue-size" , VHostUserBlk, queue_size,128 ),DEFINE_PROP_BIT ("config-wce" , VHostUserBlk, config_wce,0 , true),DEFINE_PROP_END_OF_LIST (),hw/core/machine.c +1
-0@@ -30,6 +30,7 @@GlobalProperty hw_compat_5_0[] = { {"vhost-scsi" ,"num_queues" ,"1" }, + {"vhost-user-blk" ,"num-queues" ,"1" }, {"vhost-user-scsi" ,"num_queues" ,"1" }, {"virtio-balloon-device" ,"page-poison" ,"false" }, {"virtio-blk-device" ,"num-queues" ,"1" },hw/virtio/vhost-user-blk-pci.c +4
-1@@ -54,6 +54,10 @@ static void vhost_user_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)VHostUserBlkPCI *dev =VHOST_USER_BLK_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); +if (dev->vdev.num_queues ==VHOST_USER_BLK_AUTO_NUM_QUEUES ) { + dev->vdev.num_queues =virtio_pci_optimal_num_queues (0 ); + } +if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { vpci_dev->nvectors = dev->vdev.num_queues +1 ; } --2.26.2
Re: [PATCH v5 5/5] vhost-user-blk: default num_queues to -smp N
Quoted 9 lines · Raphael Norwitz
Quoted 8 lines · Stefan Hajnoczi
hw/block/vhost-user-blk.c +0
-0@@ -420,6 +420,9 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)return ; }
Quoted 6 lines
hw/block/vhost-user-blk.c static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) · line 425
Quoted 3 lines
hw/block/vhost-user-blk.c +3
-0+if (s->num_queues ==VHOST_USER_BLK_AUTO_NUM_QUEUES ) { + s->num_queues =1 ; + }What is this check for? Is it just a backstop to ensure that
num_queuesis set to 1 if vhost-user-blk-pci doesn't update it?
For the non-PCI VIRTIO transports that do not handle num_queues == VHOST_USER_BLK_AUTO_NUM_QUEUES themselves.
Stefan
Raphael Norwitz
Reviewed-byRe: [PATCH v5 5/5] vhost-user-blk: default num_queues to -smp N
Quoted 18 lines · Stefan Hajnoczi
Quoted 9 lines · Raphael Norwitz
Quoted 8 lines · Stefan Hajnoczi
hw/block/vhost-user-blk.c +0
-0@@ -420,6 +420,9 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)return ; }Quoted 6 lines
hw/block/vhost-user-blk.c static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) · line 425
Quoted 3 lines
hw/block/vhost-user-blk.c +3
-0+if (s->num_queues ==VHOST_USER_BLK_AUTO_NUM_QUEUES ) { + s->num_queues =1 ; + }What is this check for? Is it just a backstop to ensure that
num_queuesis set to 1 if vhost-user-blk-pci doesn't update it?
Quoted 3 lines
For the non-PCI VIRTIO transports that do not handle
num_queues==VHOST_USER_BLK_AUTO_NUM_QUEUESthemselves.
Got it. Looks good then.
Quoted 1 line
Stefan
Quoted 52 lines · Stefan Hajnoczi
v4:
* Sorry for the long delay. I considered replacing this series with a simpler approach. Real hardware ships with a fixed number of queues (e.g. 128). The equivalent can be done in QEMU too. That way we don't need to magically sizenum_queues. In the end I decided against this approach because the Linux virtio_blk.ko and virtio_scsi.ko guest drivers unconditionally initialized all available queues until recently (it was written with num_queues=num_vcpus in mind). It doesn't make sense for a 1 CPU guest to bring up 128 virtqueues (waste of resources and possibly weird performance effects with blk-mq).
* Honor maximum number of MSI-X vectors and virtqueues [Daniel Berrange]
* Update commit descriptions to mention maximum MSI-X vector and virtqueue caps [Raphael]
v3:
* Introducevirtio_pci_optimal_num_queues()helper to enforceVIRTIO_QUEUE_MAXin one place
* UseVIRTIO_SCSI_VQ_NUM_FIXEDconstant in all cases [Cornelia]
* Updatehw/core/machine.ccompat properties for QEMU 5.0 [Michael]
v3:
* Add new performance results that demonstrate the scalability
* Mention that this is PCI-specific [Cornelia]
v2:
* Let the virtio-DEVICE-pci device select num-queues because the optimal multi-queue configuration may differ between virtio-pci, virtio-mmio, and virtio-ccw [Cornelia]Enabling multi-queue on virtio-pci storage devices improves performance on SMP guests because the completion interrupt is handled on the vCPU that submitted the I/O request. This avoids IPIs inside the guest.
Note that performance is unchanged in these cases:
1. Uniprocessor guests. They don't have IPIs.
2. Application threads might be scheduled on the sole vCPU that handles completion interrupts purely by chance. (This is one reason why benchmark results can vary noticably between runs.)
3. Users may bind the application to the vCPU that handles completion interrupts.Set the number of queues to the number of vCPUs by default on virtio-blk and virtio-scsi PCI devices. Older machine types continue to default to 1 queue for live migration compatibility.
Random read performance:
IOPS
q=1 78k
q=32 104k +33%Boot time:
Duration
q=1 51s
q=32 1m41s +98%
Quoted 5 lines
Guest configuration: 32 vCPUs, 101 virtio-blk-pci disks
Previously measured results on a 4 vCPU guest were also positive but showed a smaller 1-4% performance improvement. They are no longer valid because significant event loop optimizations have been merged.
I'm guessing this should be deferred to the next release as it (narrowly) missed the freeze window. Does this make sense to you?
Quoted 28 lines
Stefan Hajnoczi (5):
virtio-pci: addvirtio_pci_optimal_num_queues()helper
virtio-scsi: introduce a constant for fixed virtqueues
virtio-scsi: defaultnum_queuesto -smp N
virtio-blk: defaultnum_queuesto -smp N
vhost-user-blk: defaultnum_queuesto -smp Nhw/virtio/virtio-pci.h | 9 +++++++++ include/hw/virtio/vhost-user-blk.h | 2 ++ include/hw/virtio/virtio-blk.h | 2 ++ include/hw/virtio/virtio-scsi.h | 5 +++++ hw/block/vhost-user-blk.c | 6 +++++- hw/block/virtio-blk.c | 6 +++++- hw/core/machine.c | 5 +++++ hw/scsi/vhost-scsi.c | 3 ++- hw/scsi/vhost-user-scsi.c | 5 +++-- hw/scsi/virtio-scsi.c | 13 ++++++++---- hw/virtio/vhost-scsi-pci.c | 9 +++++++-- hw/virtio/vhost-user-blk-pci.c | 4 ++++ hw/virtio/vhost-user-scsi-pci.c | 9 +++++++-- hw/virtio/virtio-blk-pci.c | 7 ++++++- hw/virtio/virtio-pci.c | 32 ++++++++++++++++++++++++++++++ hw/virtio/virtio-scsi-pci.c | 9 +++++++-- 16 files changed, 110 insertions(+), 16 deletions(-)Signature · 1 line
2.26.2
Quoted 53 lines · Michael S. Tsirkin
Quoted 52 lines · Stefan Hajnoczi
v4:
* Sorry for the long delay. I considered replacing this series with a simpler approach. Real hardware ships with a fixed number of queues (e.g. 128). The equivalent can be done in QEMU too. That way we don't need to magically sizenum_queues. In the end I decided against this approach because the Linux virtio_blk.ko and virtio_scsi.ko guest drivers unconditionally initialized all available queues until recently (it was written with num_queues=num_vcpus in mind). It doesn't make sense for a 1 CPU guest to bring up 128 virtqueues (waste of resources and possibly weird performance effects with blk-mq).
* Honor maximum number of MSI-X vectors and virtqueues [Daniel Berrange]
* Update commit descriptions to mention maximum MSI-X vector and virtqueue caps [Raphael]
v3:
* Introducevirtio_pci_optimal_num_queues()helper to enforceVIRTIO_QUEUE_MAXin one place
* UseVIRTIO_SCSI_VQ_NUM_FIXEDconstant in all cases [Cornelia]
* Updatehw/core/machine.ccompat properties for QEMU 5.0 [Michael]
v3:
* Add new performance results that demonstrate the scalability
* Mention that this is PCI-specific [Cornelia]
v2:
* Let the virtio-DEVICE-pci device select num-queues because the optimal multi-queue configuration may differ between virtio-pci, virtio-mmio, and virtio-ccw [Cornelia]Enabling multi-queue on virtio-pci storage devices improves performance on SMP guests because the completion interrupt is handled on the vCPU that submitted the I/O request. This avoids IPIs inside the guest.
Note that performance is unchanged in these cases:
1. Uniprocessor guests. They don't have IPIs.
2. Application threads might be scheduled on the sole vCPU that handles completion interrupts purely by chance. (This is one reason why benchmark results can vary noticably between runs.)
3. Users may bind the application to the vCPU that handles completion interrupts.Set the number of queues to the number of vCPUs by default on virtio-blk and virtio-scsi PCI devices. Older machine types continue to default to 1 queue for live migration compatibility.
Random read performance:
IOPS
q=1 78k
q=32 104k +33%Boot time:
Duration
q=1 51s
q=32 1m41s +98%
Quoted 8 lines
Quoted 5 lines
Guest configuration: 32 vCPUs, 101 virtio-blk-pci disks
Previously measured results on a 4 vCPU guest were also positive but showed a smaller 1-4% performance improvement. They are no longer valid because significant event loop optimizations have been merged.
I'm guessing this should be deferred to the next release as it (narrowly) missed the freeze window. Does this make sense to you?
Yes, that is fine. Thanks!
Stefan