From nobody Mon Feb 9 13:37:30 2026 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; dkim=fail; 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 1505824649910105.7245489876932; Tue, 19 Sep 2017 05:37:29 -0700 (PDT) Received: from localhost ([::1]:42596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duHmL-0001PZ-3Q for importer@patchew.org; Tue, 19 Sep 2017 08:37:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duHey-0003fq-Kt for qemu-devel@nongnu.org; Tue, 19 Sep 2017 08:29:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duHex-0005Cq-AO for qemu-devel@nongnu.org; Tue, 19 Sep 2017 08:29:52 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:34338) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1duHex-0005CH-3O for qemu-devel@nongnu.org; Tue, 19 Sep 2017 08:29:51 -0400 Received: by mail-wr0-x241.google.com with SMTP id k20so2149239wre.1 for ; Tue, 19 Sep 2017 05:29:50 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-246-117.clienti.tiscali.it. [78.12.246.117]) by smtp.gmail.com with ESMTPSA id k18sm1292878wmd.22.2017.09.19.05.29.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Sep 2017 05:29:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=zqYZM98aGIApT7oS63tPo/APdeFSHjm3rmdSOE0I2rk=; b=j/qKMcR9PsZsP5DtJqS1w9sNjbaR2kT3VGRPmlBhEcF4hErbuK2w/OR92GMUTBTJDx /lYJp7fjbrtUnSEu+8MpMklXillF55NqkDaracCddlI5gERzgUT7TtLyw4CC9m5EVRhf spGlFA/HEWot4rp7ZzxND8mmKAWV+UhhVmm6PguhVChEH2eGTkwAwSWBd1SVjQE1rZXk wbaLo5MEP14OTB1iVLi35lHNc4Kauiz8rcldRCfiftUrtH+lDdeAskWo5TDwuS+0Q+kH LVgvxNCUt9iqSL6AT7tsN7Qq0+CuzL0/Rt8stg9DGSQnHM1yKmNu8anRLMaJr7fWrcNy jR1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=zqYZM98aGIApT7oS63tPo/APdeFSHjm3rmdSOE0I2rk=; b=kAQ8KiTgd48HJB/tTjd37xyJ38XtP3InRNeQ1TQFyvBOvnEe77uSdGs2P75fgP7IR0 ZmN4ZpKKo7V9aZuF1vDhV0KVYm+BPbmrHm7GaA1Uccmbu5KmFlO7U2xxJO+YBKKdwIl2 WYbrvYc7yHezD1x+UvQAmJztrUh5/iHbZZ9FN5m+SohxOT1dm8hzqZ21cvdtKQsbOC68 V1EQu3ePHFFhcszjv1EvEy6oNT2b/movQc/KCp+P9ZvtLqYXWUtpGkE1sH8trlXAsdL4 s8s0KjU6uyE61/VszUBoojUtsGaw7LHrSLWNbBEnglXsqMYScJiozF+smifROdCQuAZz mZUA== X-Gm-Message-State: AHPjjUjmPm8ZeKf9rdKUYeHpgzFP0eFNXBn1MZTW7ZVxYfSEkHPuDtIy d4k75lKJKdn0cH35pP5OkXl0i6E1 X-Google-Smtp-Source: AOwi7QD7MA5VS4ffT2QD8ZmUBw8cZuVnGE1AKfW6j80JVmlYGyOMzhCvq4yY/F+61EJn5xl3yp2ksQ== X-Received: by 10.223.131.99 with SMTP id 90mr1309841wrd.198.1505824189842; Tue, 19 Sep 2017 05:29:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 19 Sep 2017 14:28:55 +0200 Message-Id: <1505824179-21541-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1505824179-21541-1-git-send-email-pbonzini@redhat.com> References: <1505824179-21541-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PULL 06/50] 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: "Richard W.M. Jones" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Richard W.M. Jones" 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 Message-Id: <20170810165255.20865-1-rjones@redhat.com> Signed-off-by: Paolo Bonzini --- 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 eb63944..aca1909 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 de6ae5a..4c0bcdb 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 1.8.3.1