From nobody Fri Apr 26 17:53:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502384637190148.6477974828066; Thu, 10 Aug 2017 10:03:57 -0700 (PDT) Received: from localhost ([::1]:54280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfqsF-0002EQ-Rd for importer@patchew.org; Thu, 10 Aug 2017 13:03:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfqrJ-0001vw-5w for qemu-devel@nongnu.org; Thu, 10 Aug 2017 13:03:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfqrG-0004Xc-16 for qemu-devel@nongnu.org; Thu, 10 Aug 2017 13:02:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38284) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfqrF-0004T3-O0 for qemu-devel@nongnu.org; Thu, 10 Aug 2017 13:02:53 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFA8929B5F4; Thu, 10 Aug 2017 16:53:01 +0000 (UTC) Received: from trick.home.annexia.org (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC8498A07F; Thu, 10 Aug 2017 16:52:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AFA8929B5F4 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=rjones@redhat.com From: "Richard W.M. Jones" To: pbonzini@redhat.com Date: Thu, 10 Aug 2017 17:52:55 +0100 Message-Id: <20170810165255.20865-1-rjones@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 10 Aug 2017 16:53:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] virtio-scsi: Add virtqueue_size parameter allowing virtqueue size to be set. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hch@lst.de, qemu-devel@nongnu.org, martin.petersen@oracle.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3Dscsi,virtqueue_size=3D16 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=3D64: 318 disks -"- ditto -"- virtqueue_size=3D16: 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 Reviewed-by: Stefan Hajnoczi --- 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 =3D VIRTIO_SCSI_SENSE_DEFAULT_SIZE; s->cdb_size =3D VIRTIO_SCSI_CDB_DEFAULT_SIZE; =20 - s->ctrl_vq =3D virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, ctrl); - s->event_vq =3D virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, evt); + s->ctrl_vq =3D virtio_add_queue(vdev, s->conf.virtqueue_size, ctrl); + s->event_vq =3D virtio_add_queue(vdev, s->conf.virtqueue_size, evt); for (i =3D 0; i < s->conf.num_queues; i++) { - s->cmd_vqs[i] =3D virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, cmd); + s->cmd_vqs[i] =3D virtio_add_queue(vdev, s->conf.virtqueue_size, c= md); } } =20 @@ -917,6 +917,8 @@ static void virtio_scsi_device_unrealize(DeviceState *d= ev, Error **errp) =20 static Property virtio_scsi_properties[] =3D { DEFINE_PROP_UINT32("num_queues", VirtIOSCSI, parent_obj.conf.num_queue= s, 1), + DEFINE_PROP_UINT32("virtqueue_size", VirtIOSCSI, + parent_obj.conf.virtqueue_size, 1= 28), DEFINE_PROP_UINT32("max_sectors", VirtIOSCSI, parent_obj.conf.max_sect= ors, 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-scs= i.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) =20 -#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; =20 struct VirtIOSCSIConf { uint32_t num_queues; + uint32_t virtqueue_size; uint32_t max_sectors; uint32_t cmd_per_lun; #ifdef CONFIG_VHOST_SCSI --=20 2.13.1