Skip to contentSkip to conversation

Add vhost-pci-blk driver

PATCH RESEND Superseded Vitaly Mayatskikh 3 participants 5 messages Nov 5, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add vhost-pci-blk driver

This driver moves virtio-blk host-side processing to kernel (via new vhost_blk kernel driver). It accelerates virtual disk performance close to bare metal levels, especially for parellel loads.

For example, fio numjobs=16 gets 101k randread IOPS using virtio-blk and 1202k IOPS using vhost-blk, close to 1480k of raw disk performance.

See the IOPS numbers below.

The kernel part if you want to try:
- vhost_blk: https://lkml.org/lkml/2018/11/2/648
- vhost num-queues scalability fix: https://lkml.org/lkml/2018/11/2/550

# fio num-jobs
# A: bare metal over block
# B: bare metal over file
# C: virtio-blk over block
# D: virtio-blk over file
# E: vhost-blk over block
# F: vhost-blk over file
#
#  A     B     C    D    E     F
1  171k  151k  148k 151k 187k  175k
2  328k  302k  249k 241k 334k  296k
3  479k  437k  179k 174k 464k  404k
4  622k  568k  143k 183k 580k  492k
5  755k  697k  136k 128k 693k  579k
6  887k  808k  131k 120k 782k  640k
7  1004k 926k  126k 131k 863k  693k
8  1099k 1015k 117k 115k 931k  712k
9  1194k 1119k 115k 111k 991k  711k

10 1278k 1207k 109k 114k 1046k 695k
11 1345k 1280k 110k 108k 1091k 663k
12 1411k 1356k 104k 106k 1142k 629k
13 1466k 1423k 106k 106k 1170k 607k
14 1517k 1486k 103k 106k 1179k 589k
15 1552k 1543k 102k 102k 1191k 571k
16 1480k 1506k 101k 102k 1202k 566k

Vitaly Mayatskikh (1):
Add vhost-pci-blk driver

 configure                  | 10 +++++++
 default-configs/virtio.mak |  1 +
 hw/block/Makefile.objs     |  1 +
 hw/virtio/virtio-pci.c     | 60 ++++++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.h     | 19 ++++++++++++
 5 files changed, 91 insertions(+)
Signature · 1 line
2.17.1
#1 lore raw

PATCH RESEND 1/1 Add vhost-pci-blk driver

This driver uses the kernel-mode acceleration for virtio-blk and allows to get a near bare metal disk performance inside a VM.

---
 configure                     |  10 +
 default-configs/virtio.mak    |   1 +
 hw/block/Makefile.objs        |   1 +
 hw/block/vhost-blk.c          | 411 ++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.c        |  60 +++++
 hw/virtio/virtio-pci.h        |  19 ++
 include/hw/virtio/vhost-blk.h |  43 ++++
 7 files changed, 545 insertions(+)
 create mode 100644 hw/block/vhost-blk.c
 create mode 100644 include/hw/virtio/vhost-blk.h
configure +10 -0
index 46ae1e8c76..787bc780da 100755
@@ -371,6 +371,7 @@ vhost_crypto="no"
 vhost_scsi="no"
 vhost_vsock="no"
 vhost_user=""
+vhost_blk=""
 kvm="no"
 hax="no"
 hvf="no"
@@ -869,6 +870,7 @@ Linux)
   vhost_crypto="yes"
   vhost_scsi="yes"
   vhost_vsock="yes"
+  vhost_blk="yes"
   QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES"
   supported_os="yes"
   libudev="yes"
@@ -1263,6 +1265,10 @@ for opt do
   ;;
   --enable-vhost-vsock) vhost_vsock="yes"
   ;;
+  --disable-vhost-blk) vhost_blk="no"
+  ;;
+  --enable-vhost-blk) vhost_blk="yes"
+  ;;
   --disable-opengl) opengl="no"
   ;;
   --enable-opengl) opengl="yes"
@@ -6000,6 +6006,7 @@ echo "vhost-crypto support $vhost_crypto"
 echo "vhost-scsi support $vhost_scsi"
 echo "vhost-vsock support $vhost_vsock"
 echo "vhost-user support $vhost_user"
+echo "vhost-blk support $vhost_blk"
 echo "Trace backends    $trace_backends"
 if have_backend "simple"; then
 echo "Trace output file $trace_file-<pid>"
@@ -6461,6 +6468,9 @@ fi
 if test "$vhost_user" = "yes" ; then
   echo "CONFIG_VHOST_USER=y" >> $config_host_mak
 fi
+if test "$vhost_blk" = "yes" ; then
+  echo "CONFIG_VHOST_BLK=y" >> $config_host_mak
+fi
 if test "$blobs" = "yes" ; then
   echo "INSTALL_BLOBS=yes" >> $config_host_mak
 fi
default-configs/virtio.mak +1 -0
index 1304849018..765c0a2a04 100644
@@ -1,5 +1,6 @@
 CONFIG_VHOST_USER_SCSI=$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX))
 CONFIG_VHOST_USER_BLK=$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX))
+CONFIG_VHOST_BLK=$(CONFIG_LINUX)
 CONFIG_VIRTIO=y
 CONFIG_VIRTIO_9P=y
 CONFIG_VIRTIO_BALLOON=y
hw/block/Makefile.objs +1 -0
index 53ce5751ae..857ce823fc 100644
@@ -14,3 +14,4 @@ obj-$(CONFIG_SH4) += tc58128.o
 obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o
 obj-$(CONFIG_VIRTIO_BLK) += dataplane/
 obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o
+obj-$(CONFIG_VHOST_BLK) += vhost-blk.o
hw/block/vhost-blk.c new file +411 -0

411 lines not on this page · raw message

hw/virtio/virtio-pci.c +60 -0

72 lines not on this page · raw message

hw/virtio/virtio-pci.h +19 -0
index 813082b0d7..4cca04a45a 100644
@@ -31,6 +31,10 @@
 #include "hw/virtio/vhost-user-blk.h"
 #endif
 
+#ifdef CONFIG_VHOST_BLK
+#include "hw/virtio/vhost-blk.h"
+#endif
+
 #ifdef CONFIG_VIRTFS
 #include "hw/9pfs/virtio-9p.h"
 #endif
@@ -50,6 +54,7 @@ typedef struct VirtIONetPCI VirtIONetPCI;
 typedef struct VHostSCSIPCI VHostSCSIPCI;
 typedef struct VHostUserSCSIPCI VHostUserSCSIPCI;
 typedef struct VHostUserBlkPCI VHostUserBlkPCI;
+typedef struct VHostBlkPCI VHostBlkPCI;
 typedef struct VirtIORngPCI VirtIORngPCI;
 typedef struct VirtIOInputPCI VirtIOInputPCI;
 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
@@ -262,6 +267,20 @@ struct VHostUserBlkPCI {
 };
 #endif
 
+#ifdef CONFIG_VHOST_BLK
+/*
+ * vhost-blk-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VHOST_BLK_PCI "vhost-blk-pci"
+#define VHOST_BLK_PCI(obj) \
+        OBJECT_CHECK(VHostBlkPCI, (obj), TYPE_VHOST_BLK_PCI)
+
+struct VHostBlkPCI {
+    VirtIOPCIProxy parent_obj;
+    VHostBlk vdev;
+};
+#endif
+
 /*
  * virtio-blk-pci: This extends VirtioPCIProxy.
  */
include/hw/virtio/vhost-blk.h new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw
In reply to Vitaly Mayatskikh
Quoted 43 lines · Vitaly Mayatskikh

This driver moves virtio-blk host-side processing to kernel (via new vhost_blk kernel driver). It accelerates virtual disk performance close to bare metal levels, especially for parellel loads.

For example, fio numjobs=16 gets 101k randread IOPS using virtio-blk and 1202k IOPS using vhost-blk, close to 1480k of raw disk performance.

See the IOPS numbers below.

The kernel part if you want to try:
- vhost_blk: https://lkml.org/lkml/2018/11/2/648
- vhost num-queues scalability fix: https://lkml.org/lkml/2018/11/2/550

# fio num-jobs
# A: bare metal over block
# B: bare metal over file
# C: virtio-blk over block
# D: virtio-blk over file
# E: vhost-blk over block
# F: vhost-blk over file
#
#  A     B     C    D    E     F
1  171k  151k  148k 151k 187k  175k
2  328k  302k  249k 241k 334k  296k
3  479k  437k  179k 174k 464k  404k
4  622k  568k  143k 183k 580k  492k
5  755k  697k  136k 128k 693k  579k
6  887k  808k  131k 120k 782k  640k
7  1004k 926k  126k 131k 863k  693k
8  1099k 1015k 117k 115k 931k  712k
9  1194k 1119k 115k 111k 991k  711k

10 1278k 1207k 109k 114k 1046k 695k
11 1345k 1280k 110k 108k 1091k 663k
12 1411k 1356k 104k 106k 1142k 629k
13 1466k 1423k 106k 106k 1170k 607k
14 1517k 1486k 103k 106k 1179k 589k
15 1552k 1543k 102k 102k 1191k 571k
16 1480k 1506k 101k 102k 1202k 566k

Vitaly Mayatskikh (1):
Add vhost-pci-blk driver

Quoted 6 lines
 configure                  | 10 +++++++
 default-configs/virtio.mak |  1 +
 hw/block/Makefile.objs     |  1 +
 hw/virtio/virtio-pci.c     | 60 ++++++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.h     | 19 ++++++++++++
 5 files changed, 91 insertions(+)

I think you should Cc more widely to get meaningful review. At least virtio-blk and block layer core people.

Quoted 2 lines
Signature · 1 line
2.17.1
#3 lore raw
Quoted 2 lines · Michael S. Tsirkin

I think you should Cc more widely to get meaningful review. At least virtio-blk and block layer core people.

Thanks, it turns out I missed the existence of qemu/scripts directory completely.

Signature · 1 line
wbr, Vitaly
#4 lore raw
In reply to Vitaly Mayatskikh
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH 0/1 resend] Add vhost-pci-blk driver

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
19803cc4ae Add vhost-pci-blk driver

=== OUTPUT BEGIN ===
Checking PATCH 1/1: Add vhost-pci-blk driver...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #82:
new file mode 100644

ERROR: Error messages should not contain newlines
#229: FILE: hw/block/vhost-blk.c:143:
+ error_report("Error opening backing store: %d\n", -errno);

ERROR: braces {} are necessary for all arms of this statement #241: FILE: hw/block/vhost-blk.c:155:
+ if (s->bs_fd > 0)
[...]

ERROR: space prohibited after that '-' (ctx:WxW)
#327: FILE: hw/block/vhost-blk.c:241:

+    int fd = - 1;
              ^

WARNING: line over 80 characters
#331: FILE: hw/block/vhost-blk.c:245:
+ error_report("Can't open device %s: %d\n", blk_bs(s->blk)->filename, errno);

ERROR: code indent should never use tabs
#331: FILE: hw/block/vhost-blk.c:245:
+^I error_report("Can't open device %s: %d\n", blk_bs(s->blk)->filename, errno);$

ERROR: Error messages should not contain newlines
#331: FILE: hw/block/vhost-blk.c:245:
+ error_report("Can't open device %s: %d\n", blk_bs(s->blk)->filename, errno);

ERROR: code indent should never use tabs
#332: FILE: hw/block/vhost-blk.c:246:
+^I goto out;$

ERROR: code indent should never use tabs
#336: FILE: hw/block/vhost-blk.c:250:
+^I ret = ioctl(fd, BLKGETSIZE, &var);$

ERROR: code indent should never use tabs
#337: FILE: hw/block/vhost-blk.c:251:
+^I var64 = var;$

ERROR: code indent should never use tabs
#340: FILE: hw/block/vhost-blk.c:254:
+^I error_report("Can't get drive size: %d\n", errno);$

ERROR: Error messages should not contain newlines
#340: FILE: hw/block/vhost-blk.c:254:
+ error_report("Can't get drive size: %d\n", errno);

ERROR: code indent should never use tabs
#341: FILE: hw/block/vhost-blk.c:255:
+^I goto out;$

ERROR: line over 90 characters
#347: FILE: hw/block/vhost-blk.c:261:
+ error_report("Can't get drive logical sector size, assuming 512: %d\n", errno);

ERROR: code indent should never use tabs
#347: FILE: hw/block/vhost-blk.c:261:
+^I error_report("Can't get drive logical sector size, assuming 512: %d\n", errno);$

ERROR: Error messages should not contain newlines
#347: FILE: hw/block/vhost-blk.c:261:
+ error_report("Can't get drive logical sector size, assuming 512: %d\n", errno);

ERROR: code indent should never use tabs
#348: FILE: hw/block/vhost-blk.c:262:
+^I var = 512;$

ERROR: braces {} are necessary for all arms of this statement #360: FILE: hw/block/vhost-blk.c:274:
+ if (fd > 0)
[...]

ERROR: code indent should never use tabs
#361: FILE: hw/block/vhost-blk.c:275:
+^I close(fd);$

ERROR: code indent should never use tabs
#410: FILE: hw/block/vhost-blk.c:324:
+^Igoto virtio_err;$

ERROR: line over 90 characters
#413: FILE: hw/block/vhost-blk.c:327:
+ ret = vhost_dev_init(&s->dev, (void *)(uintptr_t)s->vhostfd, VHOST_BACKEND_TYPE_KERNEL, 0);

total: 19 errors, 2 warnings, 613 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]