2017-04-28 23:19:05 +00:00
|
|
|
# vhost {#vhost}
|
|
|
|
|
2017-03-23 08:28:21 +00:00
|
|
|
# vhost Getting Started Guide {#vhost_getting_started}
|
|
|
|
|
2017-07-05 17:56:49 +00:00
|
|
|
The Storage Performance Development Kit vhost application is named `vhost`.
|
2017-06-08 17:47:39 +00:00
|
|
|
This application extends SPDK to present virtio storage controllers to QEMU-based
|
2017-03-23 08:28:21 +00:00
|
|
|
VMs and process I/O submitted to devices attached to those controllers.
|
|
|
|
|
|
|
|
# Prerequisites {#vhost_prereqs}
|
|
|
|
|
2017-07-05 17:56:49 +00:00
|
|
|
The base SPDK build instructions are located in README.md in the SPDK root directory.
|
2017-03-23 08:28:21 +00:00
|
|
|
This guide assumes familiarity with building SPDK using the default options.
|
|
|
|
|
|
|
|
## Supported Guest Operating Systems
|
2017-07-05 17:56:49 +00:00
|
|
|
|
2017-03-23 08:28:21 +00:00
|
|
|
The guest OS must contain virtio drivers. The SPDK vhost target has been tested
|
|
|
|
with Ubuntu 16.04, Fedora 25, Windows 2012 R2.
|
|
|
|
|
|
|
|
# Building
|
|
|
|
|
|
|
|
## SPDK
|
|
|
|
|
2017-07-05 17:56:49 +00:00
|
|
|
The vhost target is built by default.
|
2017-03-23 08:28:21 +00:00
|
|
|
Once built, the binary will be at `app/vhost/vhost`.
|
|
|
|
|
|
|
|
## QEMU
|
|
|
|
|
2017-06-08 17:47:39 +00:00
|
|
|
Vhost functionality is dependent on QEMU patches to enable virtio-scsi and
|
2017-07-05 17:56:49 +00:00
|
|
|
virtio-blk in userspace - those patches are currently working their way
|
2017-06-08 17:47:39 +00:00
|
|
|
through the QEMU mailing list, but temporary patches to enable this
|
|
|
|
functionality are available in the spdk branch at https://github.com/spdk/qemu.
|
2017-03-23 08:28:21 +00:00
|
|
|
|
|
|
|
# Configuration {#vhost_config}
|
|
|
|
|
|
|
|
## SPDK
|
2017-07-05 17:56:49 +00:00
|
|
|
|
|
|
|
A vhost-specific configuration file is used to configure the SPDK vhost
|
2017-03-23 08:28:21 +00:00
|
|
|
target. A fully documented example configuration file is located at
|
|
|
|
`etc/spdk/vhost.conf.in`. This file defines the following:
|
|
|
|
|
|
|
|
### Storage Backends
|
2017-07-05 17:56:49 +00:00
|
|
|
|
|
|
|
Storage backends are devices which will be exposed to the guest OS.
|
|
|
|
Vhost-blk backends are exposed as block devices in the guest OS, and vhost-scsi backends are
|
|
|
|
exposed as as SCSI LUNs on devices attached to the vhost-scsi controller in the guest OS.
|
2017-06-08 17:47:39 +00:00
|
|
|
SPDK supports several different types of storage backends, including NVMe,
|
2017-07-05 17:56:49 +00:00
|
|
|
Linux AIO, malloc ramdisk and Ceph RBD. Refer to @ref bdev_getting_started for
|
2017-06-08 17:47:39 +00:00
|
|
|
additional information on specifying storage backends in the configuration file.
|
|
|
|
|
2017-07-05 17:56:49 +00:00
|
|
|
### Mappings Between Block Controllers and Storage Backends
|
|
|
|
|
|
|
|
The vhost target exposes block devices to the virtual machines.
|
|
|
|
The device in the vhost controller is associated with an SPDK block device, and the
|
2017-06-08 17:47:39 +00:00
|
|
|
configuration file defines those associations. The block device to Dev mapping
|
|
|
|
is specified in the configuration file as:
|
|
|
|
|
|
|
|
~~~
|
|
|
|
[VhostBlkX]
|
|
|
|
Name vhost.X # Name of vhost socket
|
|
|
|
Dev BackendX # "BackendX" is block device name from previous
|
|
|
|
# sections in config file
|
|
|
|
#Cpumask 0x1 # Optional parameter defining which core controller uses
|
|
|
|
~~~
|
2017-03-23 08:28:21 +00:00
|
|
|
|
|
|
|
### Mappings Between SCSI Controllers and Storage Backends
|
2017-07-05 17:56:49 +00:00
|
|
|
|
|
|
|
The vhost target exposes SCSI controllers to the virtual machines.
|
2017-03-23 08:28:21 +00:00
|
|
|
Each device in the vhost controller is associated with an SPDK block device and
|
|
|
|
configuration file defines those associations. The block device to Dev mappings
|
|
|
|
are specified in the configuration file as:
|
|
|
|
|
|
|
|
~~~
|
|
|
|
[VhostScsiX]
|
|
|
|
Name vhost.X # Name of vhost socket
|
|
|
|
Dev 0 BackendX # "BackendX" is block device name from previous
|
|
|
|
# sections in config file
|
|
|
|
Dev 1 BackendY
|
|
|
|
...
|
|
|
|
Dev n BackendN
|
|
|
|
#Cpumask 0x1 # Optional parameter defining which core controller uses
|
|
|
|
~~~
|
|
|
|
|
|
|
|
### Vhost Sockets
|
2017-07-05 17:56:49 +00:00
|
|
|
|
2017-03-23 08:28:21 +00:00
|
|
|
Userspace vhost uses UNIX domain sockets for communication between QEMU
|
|
|
|
and the vhost target. Each vhost controller is associated with a UNIX domain
|
|
|
|
socket file with filename equal to the Name argument in configuration file.
|
2017-06-08 17:47:39 +00:00
|
|
|
Sockets are created at current working directory when starting the SPDK vhost
|
|
|
|
target.
|
2017-03-23 08:28:21 +00:00
|
|
|
|
|
|
|
### Core Affinity Configuration
|
2017-07-05 17:56:49 +00:00
|
|
|
|
|
|
|
Vhost target can be restricted to run on certain cores by specifying a `ReactorMask`.
|
|
|
|
Default is to allow vhost target work on core 0. For NUMA systems, it is essential
|
2017-03-23 08:28:21 +00:00
|
|
|
to run vhost with cores on each socket to achieve optimal performance.
|
|
|
|
|
2017-07-05 17:56:49 +00:00
|
|
|
Each controller may be assigned a set of cores using the optional
|
|
|
|
`Cpumask` parameter in configuration file. For NUMA systems, the Cpumask should
|
|
|
|
specify cores on the same CPU socket as its associated VM. The `vhost` application will
|
|
|
|
pick one core from `ReactorMask` masked by `Cpumask`. `Cpumask` must be a subset of
|
|
|
|
`ReactorMask`.
|
2017-03-23 08:28:21 +00:00
|
|
|
|
|
|
|
## QEMU
|
|
|
|
|
|
|
|
Userspace vhost-scsi adds the following command line option for QEMU:
|
|
|
|
~~~
|
2017-07-05 17:56:49 +00:00
|
|
|
-device vhost-user-scsi-pci,id=scsi0,chardev=char0
|
2017-03-23 08:28:21 +00:00
|
|
|
~~~
|
|
|
|
|
2017-07-05 17:56:49 +00:00
|
|
|
Userspace vhost-blk adds the following command line option for QEMU:
|
2017-06-08 17:47:39 +00:00
|
|
|
~~~
|
2017-07-05 17:56:49 +00:00
|
|
|
-device vhost-user-blk-pci,logical_block_size=4096,size=512M,chardev=char0
|
2017-06-08 17:47:39 +00:00
|
|
|
~~~
|
|
|
|
|
2017-03-23 08:28:21 +00:00
|
|
|
In order to start qemu with vhost you need to specify following options:
|
|
|
|
|
|
|
|
- Socket, which QEMU will use for vhost communication with SPDK:
|
|
|
|
~~~
|
2017-07-05 17:56:49 +00:00
|
|
|
-chardev socket,id=char0,path=/path/to/vhost/socket
|
2017-03-23 08:28:21 +00:00
|
|
|
~~~
|
|
|
|
|
|
|
|
- Hugepages to share memory between vm and vhost target
|
|
|
|
~~~
|
2017-07-05 17:56:49 +00:00
|
|
|
-object memory-backend-file,id=mem,size=1G,mem-path=/dev/hugepages,share=on
|
2017-03-23 08:28:21 +00:00
|
|
|
~~~
|
|
|
|
|
|
|
|
# Running Vhost Target
|
2017-07-05 17:56:49 +00:00
|
|
|
|
2017-03-23 08:28:21 +00:00
|
|
|
To get started, the following example is usually sufficient:
|
|
|
|
~~~
|
|
|
|
app/vhost/vhost -c /path/to/vhost.conf
|
|
|
|
~~~
|
|
|
|
|
|
|
|
A full list of command line arguments to vhost can be obtained by:
|
|
|
|
~~~
|
|
|
|
app/vhost/vhost -h
|
|
|
|
~~~
|
|
|
|
|
|
|
|
|
|
|
|
## Example
|
2017-07-05 17:56:49 +00:00
|
|
|
|
2017-03-23 08:28:21 +00:00
|
|
|
Assume that qemu and spdk are in respectively `qemu` and `spdk` directories.
|
|
|
|
~~~
|
2017-07-05 17:56:49 +00:00
|
|
|
./qemu/build/x86_64-softmmu/qemu-system-x86_64 \
|
|
|
|
-m 1024 \
|
|
|
|
-object memory-backend-file,id=mem,size=1G,mem-path=/dev/hugepages,share=on \
|
|
|
|
-numa node,memdev=mem \
|
|
|
|
-drive file=$PROJECTS/os.qcow2,if=none,id=disk \
|
|
|
|
-device ide-hd,drive=disk,bootindex=0 \
|
|
|
|
-chardev socket,id=char0,path=./spdk/vhost.0 \
|
|
|
|
-device vhost-user-scsi-pci,id=scsi0,chardev=char0 \
|
|
|
|
-chardev socket,id=char1,path=./spdk/vhost.1 \
|
|
|
|
-device vhost-user-blk-pci,logical_block_size=4096,size=512M,chardev=char1 \
|
|
|
|
--enable-kvm
|
2017-03-23 08:28:21 +00:00
|
|
|
~~~
|
|
|
|
|
2017-07-05 17:56:49 +00:00
|
|
|
# Experimental Features {#vhost_experimental}
|
2017-03-23 08:28:21 +00:00
|
|
|
|
2017-07-05 17:56:49 +00:00
|
|
|
## Multi-Queue Block Layer (blk-mq)
|
|
|
|
|
|
|
|
It is possible to use the Linux kernel block multi-queue feature with vhost.
|
|
|
|
To enable it on Linux, it is required to modify kernel options inside the
|
2017-03-23 08:28:21 +00:00
|
|
|
virtual machine.
|
|
|
|
|
|
|
|
Instructions below for Ubuntu OS:
|
|
|
|
1. `vi /etc/default/grub`
|
|
|
|
2. Make sure mq is enabled:
|
2017-07-05 17:56:49 +00:00
|
|
|
`GRUB_CMDLINE_LINUX="scsi_mod.use_blk_mq=1"`
|
2017-03-23 08:28:21 +00:00
|
|
|
3. `sudo update-grub`
|
|
|
|
4. Reboot virtual machine
|
|
|
|
|
2017-07-05 17:56:49 +00:00
|
|
|
To achieve better performance, make sure to increase number of cores
|
|
|
|
assigned to the VM.
|
2017-03-23 08:28:21 +00:00
|
|
|
|
|
|
|
# Known bugs and limitations {#vhost_bugs}
|
|
|
|
|
|
|
|
## Hot plug is not supported
|
2017-07-05 17:56:49 +00:00
|
|
|
|
2017-03-23 08:28:21 +00:00
|
|
|
Hot plug is not supported in vhost yet. Event queue path doesn't handle that
|
2017-06-06 18:35:56 +00:00
|
|
|
case yet.
|
2017-07-31 23:45:58 +00:00
|
|
|
|
|
|
|
## Windows virtio-blk driver only works with 512-byte sectors
|
|
|
|
|
|
|
|
The Windows `viostor` driver is buggy and does not correctly support vhost-blk
|
|
|
|
devices with non-512-byte block size.
|
|
|
|
See the [bug report](https://bugzilla.redhat.com/show_bug.cgi?id=1411092) for
|
|
|
|
more information.
|