* [Qemu-devel] [PATCH] virtio-scsi: Add virtqueue_size parameter allowing virtqueue size to be set.
@ 2017-08-10 16:52 Richard W.M. Jones
2017-08-10 21:22 ` Michael S. Tsirkin
2017-08-11 10:40 ` Stefan Hajnoczi
0 siblings, 2 replies; 3+ messages in thread
From: Richard W.M. Jones @ 2017-08-10 16:52 UTC (permalink / raw)
To: pbonzini; +Cc: mst, qemu-devel, hch, martin.petersen
Since Linux switched to blk-mq as the default in Linux commit
5c279bd9e406 ("scsi: default to scsi-mq"), virtio-scsi LUNs consume
about 10x as much guest kernel memory.
This commit allows you to choose the virtqueue size for each
virtio-scsi-pci controller like this:
-device virtio-scsi-pci,id=scsi,virtqueue_size=16
The default is still 128 as before. Using smaller virtqueue_size
allows many more disks to be added to small memory virtual machines.
For a 1 vCPU, 500 MB, no swap VM I observed:
With scsi-mq enabled (upstream kernel): 175 disks
-"- ditto -"- virtqueue_size=64: 318 disks
-"- ditto -"- virtqueue_size=16: 775 disks
With scsi-mq disabled (kernel before 5c279bd9e406): 1755 disks
Note that to have any effect, this requires a kernel patch:
https://lkml.org/lkml/2017/8/10/689
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
hw/scsi/virtio-scsi.c | 8 +++++---
include/hw/virtio/virtio-scsi.h | 2 +-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index eb639442d1..aca1909a59 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -867,10 +867,10 @@ void virtio_scsi_common_realize(DeviceState *dev,
s->sense_size = VIRTIO_SCSI_SENSE_DEFAULT_SIZE;
s->cdb_size = VIRTIO_SCSI_CDB_DEFAULT_SIZE;
- s->ctrl_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, ctrl);
- s->event_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, evt);
+ s->ctrl_vq = virtio_add_queue(vdev, s->conf.virtqueue_size, ctrl);
+ s->event_vq = virtio_add_queue(vdev, s->conf.virtqueue_size, evt);
for (i = 0; i < s->conf.num_queues; i++) {
- s->cmd_vqs[i] = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, cmd);
+ s->cmd_vqs[i] = virtio_add_queue(vdev, s->conf.virtqueue_size, cmd);
}
}
@@ -917,6 +917,8 @@ static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp)
static Property virtio_scsi_properties[] = {
DEFINE_PROP_UINT32("num_queues", VirtIOSCSI, parent_obj.conf.num_queues, 1),
+ DEFINE_PROP_UINT32("virtqueue_size", VirtIOSCSI,
+ parent_obj.conf.virtqueue_size, 128),
DEFINE_PROP_UINT32("max_sectors", VirtIOSCSI, parent_obj.conf.max_sectors,
0xFFFF),
DEFINE_PROP_UINT32("cmd_per_lun", VirtIOSCSI, parent_obj.conf.cmd_per_lun,
diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
index de6ae5a9f6..4c0bcdb788 100644
--- a/include/hw/virtio/virtio-scsi.h
+++ b/include/hw/virtio/virtio-scsi.h
@@ -32,7 +32,6 @@
#define VIRTIO_SCSI(obj) \
OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)
-#define VIRTIO_SCSI_VQ_SIZE 128
#define VIRTIO_SCSI_MAX_CHANNEL 0
#define VIRTIO_SCSI_MAX_TARGET 255
#define VIRTIO_SCSI_MAX_LUN 16383
@@ -48,6 +47,7 @@ typedef struct virtio_scsi_config VirtIOSCSIConfig;
struct VirtIOSCSIConf {
uint32_t num_queues;
+ uint32_t virtqueue_size;
uint32_t max_sectors;
uint32_t cmd_per_lun;
#ifdef CONFIG_VHOST_SCSI
--
2.13.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] virtio-scsi: Add virtqueue_size parameter allowing virtqueue size to be set.
2017-08-10 16:52 [Qemu-devel] [PATCH] virtio-scsi: Add virtqueue_size parameter allowing virtqueue size to be set Richard W.M. Jones
@ 2017-08-10 21:22 ` Michael S. Tsirkin
2017-08-11 10:40 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2017-08-10 21:22 UTC (permalink / raw)
To: Richard W.M. Jones; +Cc: pbonzini, qemu-devel, hch, martin.petersen
On Thu, Aug 10, 2017 at 05:52:55PM +0100, Richard W.M. Jones wrote:
> Since Linux switched to blk-mq as the default in Linux commit
> 5c279bd9e406 ("scsi: default to scsi-mq"), virtio-scsi LUNs consume
> about 10x as much guest kernel memory.
>
> This commit allows you to choose the virtqueue size for each
> virtio-scsi-pci controller like this:
>
> -device virtio-scsi-pci,id=scsi,virtqueue_size=16
>
> The default is still 128 as before. Using smaller virtqueue_size
> allows many more disks to be added to small memory virtual machines.
> For a 1 vCPU, 500 MB, no swap VM I observed:
>
> With scsi-mq enabled (upstream kernel): 175 disks
> -"- ditto -"- virtqueue_size=64: 318 disks
> -"- ditto -"- virtqueue_size=16: 775 disks
> With scsi-mq disabled (kernel before 5c279bd9e406): 1755 disks
>
> Note that to have any effect, this requires a kernel patch:
>
> https://lkml.org/lkml/2017/8/10/689
>
> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Looks reasonable but pls remember to repost after the release.
> ---
> hw/scsi/virtio-scsi.c | 8 +++++---
> include/hw/virtio/virtio-scsi.h | 2 +-
> 2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
> index eb639442d1..aca1909a59 100644
> --- a/hw/scsi/virtio-scsi.c
> +++ b/hw/scsi/virtio-scsi.c
> @@ -867,10 +867,10 @@ void virtio_scsi_common_realize(DeviceState *dev,
> s->sense_size = VIRTIO_SCSI_SENSE_DEFAULT_SIZE;
> s->cdb_size = VIRTIO_SCSI_CDB_DEFAULT_SIZE;
>
> - s->ctrl_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, ctrl);
> - s->event_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, evt);
> + s->ctrl_vq = virtio_add_queue(vdev, s->conf.virtqueue_size, ctrl);
> + s->event_vq = virtio_add_queue(vdev, s->conf.virtqueue_size, evt);
> for (i = 0; i < s->conf.num_queues; i++) {
> - s->cmd_vqs[i] = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, cmd);
> + s->cmd_vqs[i] = virtio_add_queue(vdev, s->conf.virtqueue_size, cmd);
> }
> }
>
> @@ -917,6 +917,8 @@ static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp)
>
> static Property virtio_scsi_properties[] = {
> DEFINE_PROP_UINT32("num_queues", VirtIOSCSI, parent_obj.conf.num_queues, 1),
> + DEFINE_PROP_UINT32("virtqueue_size", VirtIOSCSI,
> + parent_obj.conf.virtqueue_size, 128),
> DEFINE_PROP_UINT32("max_sectors", VirtIOSCSI, parent_obj.conf.max_sectors,
> 0xFFFF),
> DEFINE_PROP_UINT32("cmd_per_lun", VirtIOSCSI, parent_obj.conf.cmd_per_lun,
> diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
> index de6ae5a9f6..4c0bcdb788 100644
> --- a/include/hw/virtio/virtio-scsi.h
> +++ b/include/hw/virtio/virtio-scsi.h
> @@ -32,7 +32,6 @@
> #define VIRTIO_SCSI(obj) \
> OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)
>
> -#define VIRTIO_SCSI_VQ_SIZE 128
> #define VIRTIO_SCSI_MAX_CHANNEL 0
> #define VIRTIO_SCSI_MAX_TARGET 255
> #define VIRTIO_SCSI_MAX_LUN 16383
> @@ -48,6 +47,7 @@ typedef struct virtio_scsi_config VirtIOSCSIConfig;
>
> struct VirtIOSCSIConf {
> uint32_t num_queues;
> + uint32_t virtqueue_size;
> uint32_t max_sectors;
> uint32_t cmd_per_lun;
> #ifdef CONFIG_VHOST_SCSI
> --
> 2.13.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] virtio-scsi: Add virtqueue_size parameter allowing virtqueue size to be set.
2017-08-10 16:52 [Qemu-devel] [PATCH] virtio-scsi: Add virtqueue_size parameter allowing virtqueue size to be set Richard W.M. Jones
2017-08-10 21:22 ` Michael S. Tsirkin
@ 2017-08-11 10:40 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2017-08-11 10:40 UTC (permalink / raw)
To: Richard W.M. Jones; +Cc: pbonzini, hch, qemu-devel, martin.petersen, mst
[-- Attachment #1: Type: text/plain, Size: 2138 bytes --]
On Thu, Aug 10, 2017 at 05:52:55PM +0100, Richard W.M. Jones wrote:
> Since Linux switched to blk-mq as the default in Linux commit
> 5c279bd9e406 ("scsi: default to scsi-mq"), virtio-scsi LUNs consume
> about 10x as much guest kernel memory.
>
> This commit allows you to choose the virtqueue size for each
> virtio-scsi-pci controller like this:
>
> -device virtio-scsi-pci,id=scsi,virtqueue_size=16
>
> The default is still 128 as before. Using smaller virtqueue_size
> allows many more disks to be added to small memory virtual machines.
> For a 1 vCPU, 500 MB, no swap VM I observed:
>
> With scsi-mq enabled (upstream kernel): 175 disks
> -"- ditto -"- virtqueue_size=64: 318 disks
> -"- ditto -"- virtqueue_size=16: 775 disks
> With scsi-mq disabled (kernel before 5c279bd9e406): 1755 disks
>
> Note that to have any effect, this requires a kernel patch:
>
> https://lkml.org/lkml/2017/8/10/689
>
> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> ---
> hw/scsi/virtio-scsi.c | 8 +++++---
> include/hw/virtio/virtio-scsi.h | 2 +-
> 2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
> index eb639442d1..aca1909a59 100644
> --- a/hw/scsi/virtio-scsi.c
> +++ b/hw/scsi/virtio-scsi.c
> @@ -867,10 +867,10 @@ void virtio_scsi_common_realize(DeviceState *dev,
> s->sense_size = VIRTIO_SCSI_SENSE_DEFAULT_SIZE;
> s->cdb_size = VIRTIO_SCSI_CDB_DEFAULT_SIZE;
>
> - s->ctrl_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, ctrl);
> - s->event_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, evt);
> + s->ctrl_vq = virtio_add_queue(vdev, s->conf.virtqueue_size, ctrl);
> + s->event_vq = virtio_add_queue(vdev, s->conf.virtqueue_size, evt);
> for (i = 0; i < s->conf.num_queues; i++) {
> - s->cmd_vqs[i] = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, cmd);
> + s->cmd_vqs[i] = virtio_add_queue(vdev, s->conf.virtqueue_size, cmd);
> }
> }
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-08-11 10:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-10 16:52 [Qemu-devel] [PATCH] virtio-scsi: Add virtqueue_size parameter allowing virtqueue size to be set Richard W.M. Jones
2017-08-10 21:22 ` Michael S. Tsirkin
2017-08-11 10:40 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).