virtio: virtio-blk data plane
cover virtio: virtio-blk data plane
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=on
Limitations:
* Only format=raw is supported
* Live migration is not supported
* Block jobs, hot unplug, and other operations fail with -EBUSY
* I/O throttling limits are ignored
* Only Linux hosts are supported due to Linux AIO usage
The code has reached a stage where I feel it is ready to merge. Users have been playing with it for some time and want the significant performance boost.
We are refactoring QEMU to get rid of the global mutex. I believe that virtio-blk-data-plane can eventually become the default mode of operation.
Instead of waiting for global mutex removal efforts to finish, I want to use virtio-blk-data-plane as an example device for AioContext and threaded hw dispatch refactoring. This means:
1. When the block layer can bind to an AioContext and execute I/O outside the global mutex, virtio-blk-data-plane can use this (and gain image format support).
2. When hw dispatch no longer needs the global mutex we can use hw/virtio.c again and perhaps run a pool of iothreads instead of dedicated data plane threads.
But in the meantime, I have cleaned up the virtio-blk-data-plane code so that it can be merged as an experimental feature.
Changes from the RFC v9:
* Add x-data-plane=on|off option and coexist with regular virtio-blk code
* Create thread from BH so it inherits iothread cpusets
* Drain requests on vm_stop() so stopped guest does not access image file
* Add migration blocker
* Add bdrv_in_use() to prevent block jobs and other operations that can interfere
* Drop IOQueue request merging for simplicity
* Drop ioctl interrupt injection and always use irqfd for simplicity
* Major cleanup to split up source files
* Rebase from qemu-kvm.git onto qemu.git
* Address Michael Tsirkin's review comments
Stefan Hajnoczi (7):
raw-posix: add raw_get_aio_fd() for virtio-blk-data-plane
configure: add CONFIG_VIRTIO_BLK_DATA_PLANE
dataplane: add virtqueue vring code
dataplane: add event loop
dataplane: add Linux AIO request queue
dataplane: add virtio-blk data plane code
virtio-blk: add x-data-plane=on|off performance feature
block.h | 9 + block/raw-posix.c | 34 ++++ configure | 21 +++ hw/Makefile.objs | 2 +- hw/dataplane/Makefile.objs | 3 + hw/dataplane/event-poll.c | 109 ++++++++++++ hw/dataplane/event-poll.h | 40 +++++ hw/dataplane/ioq.c | 118 +++++++++++++ hw/dataplane/ioq.h | 57 +++++++ hw/dataplane/virtio-blk.c | 414 +++++++++++++++++++++++++++++++++++++++++++++ hw/dataplane/virtio-blk.h | 41 +++++ hw/dataplane/vring.c | 321 +++++++++++++++++++++++++++++++++++ hw/dataplane/vring.h | 54 ++++++ hw/virtio-blk.c | 59 ++++++- hw/virtio-blk.h | 1 + hw/virtio-pci.c | 3 + trace-events | 9 + 17 files changed, 1293 insertions(+), 2 deletions(-) create mode 100644 hw/dataplane/Makefile.objs create mode 100644 hw/dataplane/event-poll.c create mode 100644 hw/dataplane/event-poll.h create mode 100644 hw/dataplane/ioq.c create mode 100644 hw/dataplane/ioq.h create mode 100644 hw/dataplane/virtio-blk.c create mode 100644 hw/dataplane/virtio-blk.h create mode 100644 hw/dataplane/vring.c create mode 100644 hw/dataplane/vring.h
Signature · 1 line
1.8.0
PATCH 1/7 raw-posix: add raw_get_aio_fd() for virtio-blk-data-plane
The raw_get_aio_fd() function allows virtio-blk-data-plane to get the file descriptor of a raw image file with Linux AIO enabled. This interface is really a layering violation that can be resolved once the block layer is able to run outside the global mutex - at that point virtio-blk-data-plane will switch from custom Linux AIO code to using the block layer.
--- block.h | 9 +++++++++ block/raw-posix.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
block.h +9 -0
@@ -365,6 +365,15 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);void bdrv_set_in_use (BlockDriverState *bs,int in_use);int bdrv_in_use (BlockDriverState *bs); +#ifdef CONFIG_LINUX_AIO +int raw_get_aio_fd (BlockDriverState *bs); +#else +static inline int raw_get_aio_fd (BlockDriverState *bs) +{ +return -ENOTSUP ; +} +#endif +enum BlockAcctType {BDRV_ACCT_READ ,BDRV_ACCT_WRITE ,
block/raw-posix.c +34 -0
@@ -1768,6 +1768,40 @@ static BlockDriver bdrv_host_cdrom = { };#endif /* __FreeBSD__ */ +#ifdef CONFIG_LINUX_AIO +/** +* Return the file descriptor for Linux AIO +* +* This function is a layering violation and should be removed when it becomes +* possible to call the block layer outside the global mutex. It allows the +* caller to hijack the file descriptor so I/O can be performed outside the +* block layer. +*/ +int raw_get_aio_fd (BlockDriverState *bs) +{ +BDRVRawState *s; + +if (!bs->drv) { +return -ENOMEDIUM ; + } + +if (bs->drv ==bdrv_find_format ("raw" )) { + bs = bs->file; + } + +/* raw-posix has several protocols so just check for raw_aio_readv */ +if (bs->drv->bdrv_aio_readv != raw_aio_readv) { +return -ENOTSUP ; + } + + s = bs->opaque; +if (!s->use_aio) { +return -ENOTSUP ; + } +return s->fd; +} +#endif /* CONFIG_LINUX_AIO */ +static void bdrv_file_init (void ) {/*
Signature · 1 line
1.8.0
PATCH 2/7 configure: add CONFIG_VIRTIO_BLK_DATA_PLANE
In reply to Stefan HajnocziThe virtio-blk-data-plane feature only works with Linux AIO. Therefore add a ./configure option and necessary checks to implement this dependency.
--- configure | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
configure +21 -0
@@ -223,6 +223,7 @@ libiscsi="" coroutine="" seccomp="" glusterfs="" +virtio_blk_data_plane="" # parse CC options first for opt do
@@ -871,6 +872,10 @@ for opt do ;; --enable-glusterfs) glusterfs="yes" ;; + --disable-virtio-blk-data-plane) virtio_blk_data_plane="no" + ;; + --enable-virtio-blk-data-plane) virtio_blk_data_plane="yes" + ;; *) echo "ERROR: unknown option $opt"; show_help="yes" ;; esac
@@ -2233,6 +2238,17 @@ EOF fi ########################################## +# adjust virtio-blk-data-plane based on linux-aio + +if test "$virtio_blk_data_plane" = "yes" -a \ + "$linux_aio" != "yes" ; then + echo "Error: virtio-blk-data-plane requires Linux AIO, please try --enable-linux-aio" + exit 1 +elif test -z "$virtio_blk_data_plane" ; then + virtio_blk_data_plane=$linux_aio +fi + +########################################## # attr probe if test "$attr" != "no" ; then
@@ -3235,6 +3251,7 @@ echo "build guest agent $guest_agent" echo "seccomp support $seccomp" echo "coroutine backend $coroutine_backend" echo "GlusterFS support $glusterfs" +echo "virtio-blk-data-plane $virtio_blk_data_plane" if test "$sdl_too_old" = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -3581,6 +3598,10 @@ if test "$glusterfs" = "yes" ; then echo "CONFIG_GLUSTERFS=y" >> $config_host_mak fi +if test "$virtio_blk_data_plane" = "yes" ; then + echo "CONFIG_VIRTIO_BLK_DATA_PLANE=y" >> $config_host_mak +fi + # USB host support case "$usb" in linux)
Signature · 1 line
1.8.0
PATCH 3/7 dataplane: add virtqueue vring code
In reply to Stefan HajnocziThe virtio-blk-data-plane cannot access memory using the usual QEMU functions since it executes outside the global mutex and the memory APIs are this time are not thread-safe.
This patch introduces a virtqueue module based on the kernel's vhost vring code. The trick is that we map guest memory ahead of time and access it cheaply outside the global mutex.
Once the hardware emulation code can execute outside the global mutex it will be possible to drop this code.
--- hw/Makefile.objs | 2 +- hw/dataplane/Makefile.objs | 3 + hw/dataplane/vring.c | 321 +++++++++++++++++++++++++++++++++++++++++++++ hw/dataplane/vring.h | 54 ++++++++ trace-events | 3 + 5 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 hw/dataplane/Makefile.objs create mode 100644 hw/dataplane/vring.c create mode 100644 hw/dataplane/vring.h
hw/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-y = usb/ ide/ +common-obj-y = usb/ ide/ dataplane/ common-obj-y += loader.o common-obj-$(CONFIG_VIRTIO) += virtio-console.o common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
hw/dataplane/Makefile.objs new file +3 -0
@@ -0,0 +1,3 @@ +ifeq ($(CONFIG_VIRTIO), y) +common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o +endif
hw/dataplane/vring.c new file +321 -0
321 lines not on this page · raw message
hw/dataplane/vring.h new file +54 -0
54 lines not on this page · raw message
trace-events +3 -0
@@ -98,6 +98,9 @@ virtio_blk_rw_complete(void *req, int ret) "req %p ret %d" virtio_blk_handle_write(void *req, uint64_t sector, size_t nsectors) "req %p sector %"PRIu64" nsectors %zu" virtio_blk_handle_read(void *req, uint64_t sector, size_t nsectors) "req %p sector %"PRIu64" nsectors %zu" +# hw/dataplane/vring.c +vring_setup(uint64_t physical, void *desc, void *avail, void *used) "vring physical %#"PRIx64" desc %p avail %p used %p" + # thread-pool.c thread_pool_submit(void *req, void *opaque) "req %p opaque %p" thread_pool_complete(void *req, void *opaque, int ret) "req %p opaque %p ret %d"
Signature · 1 line
1.8.0
PATCH 4/7 dataplane: add event loop
In reply to Stefan HajnocziOutside the safety of the global mutex we need to poll on file descriptors. I found epoll(2) is a convenient way to do that, although other options could replace this module in the future (such as an AioContext-based loop or glib's GMainLoop).
One important feature of this small event loop implementation is that the loop can be terminated in a thread-safe way. This allows QEMU to stop the data plane thread cleanly.
--- hw/dataplane/Makefile.objs | 2 +- hw/dataplane/event-poll.c | 109 +++++++++++++++++++++++++++++++++++++++++++++ hw/dataplane/event-poll.h | 40 +++++++++++++++++ 3 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 hw/dataplane/event-poll.c create mode 100644 hw/dataplane/event-poll.h
hw/dataplane/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ ifeq ($(CONFIG_VIRTIO), y) -common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o +common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o event-poll.o endif
hw/dataplane/event-poll.c new file +109 -0
109 lines not on this page · raw message
hw/dataplane/event-poll.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Event loop with file descriptor polling +* +* Copyright 2012 IBM, Corp. +* Copyright 2012 Red Hat, Inc. and/or its affiliates +* +* Authors: +* Stefan Hajnoczi <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef EVENT_POLL_H +#define EVENT_POLL_H + +#include "event_notifier.h" + +typedef struct EventHandler EventHandler ; +typedef bool EventCallback (EventHandler *handler); +struct EventHandler { +EventNotifier *notifier;/* eventfd */ +EventCallback *callback;/* callback function */ +}; + +typedef struct { +int epoll_fd;/* epoll(2) file descriptor */ +EventNotifier stop_notifier;/* stop poll notifier */ +EventHandler stop_handler;/* stop poll handler */ +}EventPoll ; + +void event_poll_add (EventPoll *poll,EventHandler *handler, +EventNotifier *notifier,EventCallback *callback); +void event_poll_init (EventPoll *poll); +void event_poll_cleanup (EventPoll *poll); +void event_poll_run (EventPoll *poll); +void event_poll_stop (EventPoll *poll); + +#endif /* EVENT_POLL_H */
Signature · 1 line
1.8.0
PATCH 5/7 dataplane: add Linux AIO request queue
In reply to Stefan HajnocziThe IOQueue has a pool of iocb structs and a function to add new read/write requests. Multiple requests can be added before calling the submit function to actually tell the host kernel to begin I/O. This allows callers to batch requests and submit them in one go.
The actual I/O is performed using Linux AIO.
--- hw/dataplane/Makefile.objs | 2 +- hw/dataplane/ioq.c | 118 +++++++++++++++++++++++++++++++++++++++++++++ hw/dataplane/ioq.h | 57 ++++++++++++++++++++++ 3 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 hw/dataplane/ioq.c create mode 100644 hw/dataplane/ioq.h
hw/dataplane/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ ifeq ($(CONFIG_VIRTIO), y) -common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o event-poll.o +common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o event-poll.o ioq.o endif
hw/dataplane/ioq.c new file +118 -0
118 lines not on this page · raw message
hw/dataplane/ioq.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 7/7 virtio-blk: add x-data-plane=on|off performance feature
In reply to Stefan HajnocziThe virtio-blk-data-plane feature is easy to integrate into hw/virtio-blk.c. The data plane can be started and stopped similar to vhost-net.
Users can take advantage of the virtio-blk-data-plane feature using the new -device virtio-blk-pci,x-data-plane=on property.
The x-data-plane name was chosen because at this stage the feature is experimental and likely to see changes in the future.
If the VM configuration does not support virtio-blk-data-plane an error message is printed. Although we could fall back to regular virtio-blk, I prefer the explicit approach since it prompts the user to fix their configuration if they want the performance benefit of virtio-blk-data-plane.
Limitations:
* Only format=raw is supported
* Live migration is not supported
* Block jobs, hot unplug, and other operations fail with -EBUSY
* I/O throttling limits are ignored
* Only Linux hosts are supported due to Linux AIO usage
--- hw/virtio-blk.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- hw/virtio-blk.h | 1 + hw/virtio-pci.c | 3 +++ 3 files changed, 62 insertions(+), 1 deletion(-)
hw/virtio-blk.c +58 -1
@@ -17,6 +17,8 @@#include "hw/block-common.h" #include "blockdev.h" #include "virtio-blk.h" +#include "hw/dataplane/virtio-blk.h" +#include "migration.h" #include "scsi-defs.h" #ifdef __linux__# include <scsi/sg.h>
@@ -33,6 +35,8 @@ typedef struct VirtIOBlockVirtIOBlkConf *blk;unsigned short sector_mask;DeviceState *qdev; +VirtIOBlockDataPlane *dataplane; +Error *migration_blocker; } VirtIOBlock;static VirtIOBlock *to_virtio_blk (VirtIODevice *vdev)
@@ -407,6 +411,14 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) .num_writes = 0, }; +/* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start +* dataplane here instead of waiting for .set_status(). +*/ +if (s->dataplane) { +virtio_blk_data_plane_start (s->dataplane); +return ; + } +while ((req =virtio_blk_get_request (s))) {virtio_blk_handle_request (req, &mrb); }
@@ -446,8 +458,13 @@ static void virtio_blk_dma_restart_cb(void *opaque, int running, {VirtIOBlock *s = opaque; -if (!running) +if (!running) { +/* qemu_drain_all() doesn't know about data plane, quiesce here */ +if (s->dataplane) { +virtio_blk_data_plane_drain (s->dataplane); + }return ; + }if (!s->bh) { s->bh =qemu_bh_new (virtio_blk_dma_restart_bh, s);
@@ -538,6 +555,10 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)VirtIOBlock *s =to_virtio_blk (vdev);uint32_t features; +if (s->dataplane && !(status &VIRTIO_CONFIG_S_DRIVER )) { +virtio_blk_data_plane_stop (s->dataplane); + } +if (!(status &VIRTIO_CONFIG_S_DRIVER_OK )) {return ; }
@@ -604,6 +625,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) {VirtIOBlock *s;static int virtio_blk_id; +int fd =-1 ;if (!blk->conf.bs) {error_report ("drive property not set" );
@@ -619,6 +641,21 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)return NULL ; } +if (blk->data_plane) { +if (blk->scsi) { +error_report ("device is incompatible with x-data-plane, " +"use scsi=off" ); +return NULL ; + } + + fd =raw_get_aio_fd (blk->conf.bs); +if (fd <0 ) { +error_report ("drive is incompatible with x-data-plane, " +"use format=raw,cache=none,aio=native" ); +return NULL ; + } + } + s = (VirtIOBlock *)virtio_common_init ("virtio-blk" ,VIRTIO_ID_BLOCK ,sizeof (struct virtio_blk_config ),sizeof (VirtIOBlock));
@@ -636,6 +673,17 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) s->vq =virtio_add_queue (&s->vdev,128 , virtio_blk_handle_output); +if (fd >=0 ) { + s->dataplane =virtio_blk_data_plane_create (&s->vdev, fd); + +/* Prevent block operations that conflict with data plane thread */ +bdrv_set_in_use (s->bs,1 ); + +error_setg (&s->migration_blocker, +"x-data-plane does not support migration" ); +migrate_add_blocker (s->migration_blocker); + } +qemu_add_vm_change_state_handler (virtio_blk_dma_restart_cb, s); s->qdev = dev; register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
@@ -652,6 +700,15 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)void virtio_blk_exit (VirtIODevice *vdev) {VirtIOBlock *s =to_virtio_blk (vdev); + +if (s->dataplane) { +migrate_del_blocker (s->migration_blocker); +error_free (s->migration_blocker); +bdrv_set_in_use (s->bs,0 ); +virtio_blk_data_plane_destroy (s->dataplane); + s->dataplane =NULL ; + } +unregister_savevm (s->qdev,"virtio-blk" , s);blockdev_mark_auto_del (s->bs);virtio_cleanup (vdev);
hw/virtio-blk.h +1 -0
@@ -105,6 +105,7 @@ struct VirtIOBlkConfchar *serial;uint32_t scsi;uint32_t config_wce; +uint32_t data_plane; };#define DEFINE_VIRTIO_BLK_FEATURES (_state, _field) \
hw/virtio-pci.c +3 -0
@@ -862,6 +862,9 @@ static Property virtio_blk_properties[] = {#endif DEFINE_PROP_BIT ("config-wce" , VirtIOPCIProxy, blk.config_wce,0 , true),DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE +DEFINE_PROP_BIT ("x-data-plane" , VirtIOPCIProxy, blk.data_plane,0 , false), +#endifDEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_VIRTIO_BLK_FEATURES (VirtIOPCIProxy, host_features), DEFINE_PROP_END_OF_LIST(),
Signature · 1 line
1.8.0
PATCH 6/7 dataplane: add virtio-blk data plane code
In reply to Stefan Hajnoczivirtio-blk-data-plane is a subset implementation of virtio-blk. It only handles read, write, and flush requests. It does this using a dedicated thread that executes an epoll(2)-based event loop and processes I/O using Linux AIO.
This approach performs very well but can be used for raw image files only. The number of IOPS achieved has been reported to be several times higher than the existing virtio-blk implementation.
Eventually it should be possible to unify virtio-blk-data-plane with the main body of QEMU code once the block layer and hardware emulation is able to run outside the global mutex.
--- hw/dataplane/Makefile.objs | 2 +- hw/dataplane/virtio-blk.c | 414 +++++++++++++++++++++++++++++++++++++++++++++ hw/dataplane/virtio-blk.h | 41 +++++ trace-events | 6 + 4 files changed, 462 insertions(+), 1 deletion(-) create mode 100644 hw/dataplane/virtio-blk.c create mode 100644 hw/dataplane/virtio-blk.h
hw/dataplane/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ ifeq ($(CONFIG_VIRTIO), y) -common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o event-poll.o ioq.o +common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o event-poll.o ioq.o virtio-blk.o endif
hw/dataplane/virtio-blk.c new file +414 -0
414 lines not on this page · raw message
hw/dataplane/virtio-blk.h new file +41 -0
41 lines not on this page · raw message
trace-events +6 -0
@@ -98,6 +98,12 @@ virtio_blk_rw_complete(void *req, int ret) "req %p ret %d" virtio_blk_handle_write(void *req, uint64_t sector, size_t nsectors) "req %p sector %"PRIu64" nsectors %zu" virtio_blk_handle_read(void *req, uint64_t sector, size_t nsectors) "req %p sector %"PRIu64" nsectors %zu" +# hw/dataplane/virtio-blk.c +virtio_blk_data_plane_start(void *s) "dataplane %p" +virtio_blk_data_plane_stop(void *s) "dataplane %p" +virtio_blk_data_plane_process_request(void *s, unsigned int out_num, unsigned int in_num, unsigned int head) "dataplane %p out_num %u in_num %u head %u" +virtio_blk_data_plane_complete_request(void *s, unsigned int head, int ret) "dataplane %p head %u ret %d" + # hw/dataplane/vring.c vring_setup(uint64_t physical, void *desc, void *avail, void *used) "vring physical %#"PRIx64" desc %p avail %p used %p"
Signature · 1 line
1.8.0
Re: [Qemu-devel] [PATCH 3/7] dataplane: add virtqueue vring code
In reply to Stefan HajnocziIl 15/11/2012 16:19, Stefan Hajnoczi ha scritto:
Quoted 5 lines
hw/dataplane/vring.c new file +5
-0+/* Map target physical address to host address +*/ +static inline void *phys_to_host (Vring *vring,hwaddr phys) +{ +/* Adjust for 3.6-4 GB PCI memory range */
hw/dataplane/vring.c line 34
Quoted 10 lines
hw/dataplane/vring.c new file +10
-0+if (phys >=0x100000000 ) { + phys -=0x100000000 -0xe0000000 ; + }else if (phys >=0xe0000000 ) { +fprintf (stderr,"phys_to_host bad physical address in " +"PCI range %#lx\n" , phys); +exit (1 ); + } +return vring->phys_mem_zero_host_ptr + phys; +} +
Hmm, perhaps *this* is not quite ready. :)
What we want is lockless address_space_map. We're not far from it, but not there either.
Can you add, at least for now, a weak function that does a 1:1 mapping, and override it with the above code in hw/pc.c? The prototype then would be
static inline void *dataplane_phys_to_host(void *base, hwaddr phys) {
}
or something like that.
Paolo
Re: [Qemu-devel] [PATCH 7/7] virtio-blk: add x-data-plane=on|off performance feature
In reply to Stefan HajnocziQuoted 16 lines · Stefan Hajnoczi
The virtio-blk-data-plane feature is easy to integrate into
hw/virtio-blk.c. The data plane can be started and stopped similar to vhost-net.Users can take advantage of the virtio-blk-data-plane feature using the new -device virtio-blk-pci,x-data-plane=on property.
The x-data-plane name was chosen because at this stage the feature is experimental and likely to see changes in the future.
If the VM configuration does not support virtio-blk-data-plane an error message is printed. Although we could fall back to regular virtio-blk, I prefer the explicit approach since it prompts the user to fix their configuration if they want the performance benefit of virtio-blk-data-plane.
Quoted 8 lines
Limitations:
* Only format=raw is supported
* Live migration is not supported
* Block jobs, hot unplug, and other operations fail with-EBUSY
* I/O throttling limits are ignored
* Only Linux hosts are supported due to Linux AIO usageSigned-off-by Stefan Hajnoczi <[email protected]>
Would be very interested in learning about the performance impact of this. How does this compare to current model and to vhost-blk?
Quoted 161 lines
--- hw/virtio-blk.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- hw/virtio-blk.h | 1 + hw/virtio-pci.c | 3 +++ 3 files changed, 62 insertions(+), 1 deletion(-)hw/virtio-blk.c +58
-1@@ -17,6 +17,8 @@#include "hw/block-common.h" #include "blockdev.h" #include "virtio-blk.h" +#include "hw/dataplane/virtio-blk.h" +#include "migration.h" #include "scsi-defs.h" #ifdef __linux__# include <scsi/sg.h> @@ -33,6 +35,8 @@ typedef struct VirtIOBlockVirtIOBlkConf *blk;unsigned short sector_mask;DeviceState *qdev; +VirtIOBlockDataPlane *dataplane; +Error *migration_blocker; } VirtIOBlock;static VirtIOBlock *to_virtio_blk (VirtIODevice *vdev)@@ -407,6 +411,14 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) .num_writes = 0, }; +/* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start +* dataplane here instead of waiting for .set_status(). +*/ +if (s->dataplane) { +virtio_blk_data_plane_start (s->dataplane); +return ; + } +while ((req =virtio_blk_get_request (s))) {virtio_blk_handle_request (req, &mrb); }@@ -446,8 +458,13 @@ static void virtio_blk_dma_restart_cb(void *opaque, int running, {VirtIOBlock *s = opaque; -if (!running) +if (!running) { +/* qemu_drain_all() doesn't know about data plane, quiesce here */ +if (s->dataplane) { +virtio_blk_data_plane_drain (s->dataplane); + }return ; + }if (!s->bh) { s->bh =qemu_bh_new (virtio_blk_dma_restart_bh, s);@@ -538,6 +555,10 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)VirtIOBlock *s =to_virtio_blk (vdev);uint32_t features; +if (s->dataplane && !(status &VIRTIO_CONFIG_S_DRIVER )) { +virtio_blk_data_plane_stop (s->dataplane); + } +if (!(status &VIRTIO_CONFIG_S_DRIVER_OK )) {return ; }@@ -604,6 +625,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) {VirtIOBlock *s;static int virtio_blk_id; +int fd =-1 ;if (!blk->conf.bs) {error_report ("drive property not set" );@@ -619,6 +641,21 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)return NULL ; } +if (blk->data_plane) { +if (blk->scsi) { +error_report ("device is incompatible with x-data-plane, " +"use scsi=off" ); +return NULL ; + } + + fd =raw_get_aio_fd (blk->conf.bs); +if (fd <0 ) { +error_report ("drive is incompatible with x-data-plane, " +"use format=raw,cache=none,aio=native" ); +return NULL ; + } + } + s = (VirtIOBlock *)virtio_common_init ("virtio-blk" ,VIRTIO_ID_BLOCK ,sizeof (struct virtio_blk_config ),sizeof (VirtIOBlock));@@ -636,6 +673,17 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) s->vq =virtio_add_queue (&s->vdev,128 , virtio_blk_handle_output); +if (fd >=0 ) { + s->dataplane =virtio_blk_data_plane_create (&s->vdev, fd); + +/* Prevent block operations that conflict with data plane thread */ +bdrv_set_in_use (s->bs,1 ); + +error_setg (&s->migration_blocker, +"x-data-plane does not support migration" ); +migrate_add_blocker (s->migration_blocker); + } +qemu_add_vm_change_state_handler (virtio_blk_dma_restart_cb, s); s->qdev = dev; register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,@@ -652,6 +700,15 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)void virtio_blk_exit (VirtIODevice *vdev) {VirtIOBlock *s =to_virtio_blk (vdev); + +if (s->dataplane) { +migrate_del_blocker (s->migration_blocker); +error_free (s->migration_blocker); +bdrv_set_in_use (s->bs,0 ); +virtio_blk_data_plane_destroy (s->dataplane); + s->dataplane =NULL ; + } +unregister_savevm (s->qdev,"virtio-blk" , s);blockdev_mark_auto_del (s->bs);virtio_cleanup (vdev);hw/virtio-blk.h +1
-0@@ -105,6 +105,7 @@ struct VirtIOBlkConfchar *serial;uint32_t scsi;uint32_t config_wce; +uint32_t data_plane; };#define DEFINE_VIRTIO_BLK_FEATURES (_state, _field) \hw/virtio-pci.c +3
-0@@ -862,6 +862,9 @@ static Property virtio_blk_properties[] = {#endif DEFINE_PROP_BIT ("config-wce" , VirtIOPCIProxy, blk.config_wce,0 , true),DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE +DEFINE_PROP_BIT ("x-data-plane" , VirtIOPCIProxy, blk.data_plane,0 , false), +#endifDEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_VIRTIO_BLK_FEATURES (VirtIOPCIProxy, host_features), DEFINE_PROP_END_OF_LIST(),Signature · 1 line
1.8.0
Re: [Qemu-devel] [PATCH 7/7] virtio-blk: add x-data-plane=on|off performance feature
"Michael S. Tsirkin" <[email protected]> wrote on 11/15/2012 12:48:49 PM:
Quoted 33 lines
From: "Michael S. Tsirkin" <[email protected]>
To: Stefan Hajnoczi <[email protected]>,
Cc: [email protected], Anthony Liguori/Austin/IBM@IBMUS, Paolo Bonzini <[email protected]>, Kevin Wolf <[email protected]>, Asias He <[email protected]>, Khoa Huynh/Austin/IBM@IBMUS
Date: 11/15/2012 12:46 PM
Subject: Re: [PATCH 7/7] virtio-blk: add x-data-plane=on|off performance featureQuoted 23 lines · Stefan Hajnoczi
The virtio-blk-data-plane feature is easy to integrate into
hw/virtio-blk.c. The data plane can be started and stopped similar to vhost-net.Users can take advantage of the virtio-blk-data-plane feature using the new -device virtio-blk-pci,x-data-plane=on property.
The x-data-plane name was chosen because at this stage the feature is experimental and likely to see changes in the future.
If the VM configuration does not support virtio-blk-data-plane an error message is printed. Although we could fall back to regular virtio-blk, I prefer the explicit approach since it prompts the user to fix their configuration if they want the performance benefit of virtio-blk-data-plane.
Limitations:
* Only format=raw is supported
* Live migration is not supported
* Block jobs, hot unplug, and other operations fail with-EBUSY
* I/O throttling limits are ignored
* Only Linux hosts are supported due to Linux AIO usage
Quoted 6 lines
Quoted 1 line
Signed-off-by Stefan Hajnoczi <[email protected]>Would be very interested in learning about the performance impact of this. How does this compare to current model and to vhost-blk?
I plan to do a complete evaluation of this patchset in the coming days. However, I have done quite a bit of performance testing on earlier versions of the data-plane and vhost-blk code bits. Here's what I found:
1) The existing kvm/qemu code can only handle up to about 150,000 IOPS for a single KVM guest. The bottleneck here is the global qemu mutex.
2) With performance tuning, I was able to achieve 1.33 million IOPS for a single KVM guest with data-plane. This is very close to the 1.4-million-IOPS
limit of my storage setup.
3) Similarly, I was able to get up to 1.34 million IOPS for a single KVM guest with an earlier prototype of vhost-blk (using Linux AIO, from Liu Yuan).
This shows that bypassing the global qemu mutex would allow us to achieve much higher I/O rates. In fact, these I/O rates would handily beat claims from all other competing hypervisors.
I am currently evaluating the latest vhost-blk code bits from Asias He and will report results soon. I have already got past 1 million IOPS per guest with Asias' code and is trying to see if I could get even higher I/O rates. And as I mentioned earlier, I'll also evaluate this latest data-plane code from Stefan real soon. Please stay tuned...
-Khoa
Quoted 30 lines
Quoted 4 lines
--- hw/virtio-blk.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Quoted 25 lines
hw/virtio-blk.h | 1 + hw/virtio-pci.c | 3 +++ 3 files changed, 62 insertions(+), 1 deletion(-)hw/virtio-blk.c +4
-0@@ -17,6 +17,8 @@#include "hw/block-common.h" #include "blockdev.h" #include "virtio-blk.h" +#include "hw/dataplane/virtio-blk.h" +#include "migration.h" #include "scsi-defs.h" #ifdef __linux__# include <scsi/sg.h> @@ -33,6 +35,8 @@ typedef struct VirtIOBlockVirtIOBlkConf *blk;unsigned short sector_mask;DeviceState *qdev; +VirtIOBlockDataPlane *dataplane; +Error *migration_blocker; } VirtIOBlock;
Quoted 7 lines
hw/virtio-blk.c static void virtio_blk_handle_output
Quoted 2 lines
hw/virtio-blk.c +0
-0static VirtIOBlock *to_virtio_blk (VirtIODevice *vdev)@@ -407,6 +411,14 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
Quoted 4 lines
hw/virtio-blk.c +1
-0.num_writes = 0, }; +/* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so
start
Quoted 4 lines
Quoted 4 lines
hw/virtio-blk.c +4
-0+* dataplane here instead of waiting for .set_status(). +*/ +if (s->dataplane) { +virtio_blk_data_plane_start (s->dataplane);
Quoted 14 lines
hw/virtio-blk.c static void virtio_blk_dma_restart_cb(void
Quoted 7 lines
hw/virtio-blk.c +3
-0+return ; + } +while ((req =virtio_blk_get_request (s))) {virtio_blk_handle_request (req, &mrb); }@@ -446,8 +458,13 @@ static void virtio_blk_dma_restart_cb(void*opaque, int running,
Quoted 6 lines
hw/virtio-blk.c +2
-1{VirtIOBlock *s = opaque; -if (!running) +if (!running) { +/* qemu_drain_all() doesn't know about data plane, quiesce
here */
Quoted 34 lines
hw/virtio-blk.c static void virtio_blk_set_status
Quoted 9 lines
hw/virtio-blk.c +4
-0+if (s->dataplane) { +virtio_blk_data_plane_drain (s->dataplane); + }return ; + }if (!s->bh) { s->bh =qemu_bh_new (virtio_blk_dma_restart_bh, s);@@ -538,6 +555,10 @@ static void virtio_blk_set_status(VirtIODevice *vdev,
uint8_tstatus)hw/virtio-blk.c VirtIODevice *virtio_blk_init(DeviceState
Quoted 11 lines
hw/virtio-blk.c +4
-0VirtIOBlock *s =to_virtio_blk (vdev);uint32_t features; +if (s->dataplane && !(status &VIRTIO_CONFIG_S_DRIVER )) { +virtio_blk_data_plane_stop (s->dataplane); + } +if (!(status &VIRTIO_CONFIG_S_DRIVER_OK )) {return ; }@@ -604,6 +625,7 @@ VirtIODevice *virtio_blk_init(DeviceState*dev, VirtIOBlkConf *blk)
hw/virtio-blk.c VirtIODevice *virtio_blk_init(DeviceState
Quoted 8 lines
hw/virtio-blk.c +1
-0{VirtIOBlock *s;static int virtio_blk_id; +int fd =-1 ;if (!blk->conf.bs) {error_report ("drive property not set" );@@ -619,6 +641,21 @@ VirtIODevice *virtio_blk_init(DeviceState*dev, VirtIOBlkConf *blk)
Quoted 3 lines
hw/virtio-blk.c +0
-0return NULL ; }
Quoted 16 lines
Quoted 6 lines
hw/virtio-blk.c +6
-0+if (blk->data_plane) { +if (blk->scsi) { +error_report ("device is incompatible with x-data-plane, " +"use scsi=off" ); +return NULL ; + }hw/virtio-blk.c VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
Quoted 10 lines
hw/virtio-blk.c +9
-0+ + fd =raw_get_aio_fd (blk->conf.bs); +if (fd <0 ) { +error_report ("drive is incompatible with x-data-plane, " +"use format=raw,cache=none,aio=native" ); +return NULL ; + } + } + s = (VirtIOBlock *)virtio_common_init("virtio-blk",
VIRTIO_ID_BLOCK,
Quoted 1 line
hw/virtio-blk.c VirtIODevice *virtio_blk_init(DeviceState · line 660
Quoted 1 line
hw/virtio-blk.c +0
-0sizeof(struct
virtio_blk_config),
Quoted 10 lines
hw/virtio-blk.c VirtIODevice *virtio_blk_init(DeviceState
Quoted 2 lines
hw/virtio-blk.c +0
-0sizeof(VirtIOBlock));@@ -636,6 +673,17 @@ VirtIODevice *virtio_blk_init(DeviceState*dev, VirtIOBlkConf *blk)
Quoted 7 lines
hw/virtio-blk.c +4
-0s->vq =virtio_add_queue (&s->vdev,128 , virtio_blk_handle_output); +if (fd >=0 ) { + s->dataplane =virtio_blk_data_plane_create (&s->vdev, fd); + +/* Prevent block operations that conflict with data
planethread */
Quoted 38 lines
hw/virtio-blk.c VirtIODevice *virtio_blk_init(DeviceState
Quoted 11 lines
hw/virtio-blk.c +7
-0+bdrv_set_in_use (s->bs,1 ); + +error_setg (&s->migration_blocker, +"x-data-plane does not support migration" ); +migrate_add_blocker (s->migration_blocker); + } +qemu_add_vm_change_state_handler (virtio_blk_dma_restart_cb, s); s->qdev = dev; register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,@@ -652,6 +700,15 @@ VirtIODevice *virtio_blk_init(DeviceState*dev, VirtIOBlkConf *blk)
Quoted 26 lines
hw/virtio-blk.c +9
-0void virtio_blk_exit (VirtIODevice *vdev) {VirtIOBlock *s =to_virtio_blk (vdev); + +if (s->dataplane) { +migrate_del_blocker (s->migration_blocker); +error_free (s->migration_blocker); +bdrv_set_in_use (s->bs,0 ); +virtio_blk_data_plane_destroy (s->dataplane); + s->dataplane =NULL ; + } +unregister_savevm (s->qdev,"virtio-blk" , s);blockdev_mark_auto_del (s->bs);virtio_cleanup (vdev);hw/virtio-blk.h +1
-0@@ -105,6 +105,7 @@ struct VirtIOBlkConfchar *serial;uint32_t scsi;uint32_t config_wce; +uint32_t data_plane; };
Quoted 8 lines
hw/virtio-pci.c static Property virtio_blk_properties[] = { · line 863
Quoted 8 lines
hw/virtio-blk.h +0
-0#define DEFINE_VIRTIO_BLK_FEATURES (_state, _field) \hw/virtio-pci.c +0
-0@@ -862,6 +862,9 @@ static Property virtio_blk_properties[] = {#endif DEFINE_PROP_BIT("config-wce", VirtIOPCIProxy, blk.config_wce,0,
true),
Quoted 12 lines
hw/virtio-pci.c static Property virtio_blk_properties[] = { · line 864
Quoted 1 line
hw/virtio-pci.c +0
-0DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),hw/virtio-pci.c static Property virtio_blk_properties[] = { · line 866
Quoted 2 lines
hw/virtio-pci.c +2
-0+#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE + DEFINE_PROP_BIT("x-data-plane", VirtIOPCIProxy,blk.data_plane, 0, false),
Quoted 6 lines
hw/virtio-pci.c +1
-1+#endif DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_VIRTIO_BLK_FEATURES (VirtIOPCIProxy, host_features), DEFINE_PROP_END_OF_LIST(), --1.8.0
Re: [Qemu-devel] [PATCH 1/7] raw-posix: add raw_get_aio_fd() for virtio-blk-data-plane
In reply to Stefan HajnocziQuoted 8 lines · Stefan Hajnoczi
The
raw_get_aio_fd()function allows virtio-blk-data-plane to get the file descriptor of a raw image file with Linux AIO enabled. This interface is really a layering violation that can be resolved once the block layer is able to run outside the global mutex - at that point virtio-blk-data-plane will switch from custom Linux AIO code to using the block layer.Signed-off-by Stefan Hajnoczi <[email protected]>
I think this creates user confusion because virtio-blk-data-plane can't actually take a BDS.
So why not just make a string 'filename' property and open it directly in virtio-blk-data-plane? Then it's at least clear to the user and management tools what the device is capable of doing.
Regards,
Anthony Liguori
Quoted 72 lines
--- block.h | 9 +++++++++ block/raw-posix.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)block.h +9
-0@@ -365,6 +365,15 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);void bdrv_set_in_use (BlockDriverState *bs,int in_use);int bdrv_in_use (BlockDriverState *bs); +#ifdef CONFIG_LINUX_AIO +int raw_get_aio_fd (BlockDriverState *bs); +#else +static inline int raw_get_aio_fd (BlockDriverState *bs) +{ +return -ENOTSUP ; +} +#endif +enum BlockAcctType {BDRV_ACCT_READ ,BDRV_ACCT_WRITE ,block/raw-posix.c +34
-0@@ -1768,6 +1768,40 @@ static BlockDriver bdrv_host_cdrom = { };#endif /* __FreeBSD__ */ +#ifdef CONFIG_LINUX_AIO +/** +* Return the file descriptor for Linux AIO +* +* This function is a layering violation and should be removed when it becomes +* possible to call the block layer outside the global mutex. It allows the +* caller to hijack the file descriptor so I/O can be performed outside the +* block layer. +*/ +int raw_get_aio_fd (BlockDriverState *bs) +{ +BDRVRawState *s; + +if (!bs->drv) { +return -ENOMEDIUM ; + } + +if (bs->drv ==bdrv_find_format ("raw" )) { + bs = bs->file; + } + +/* raw-posix has several protocols so just check for raw_aio_readv */ +if (bs->drv->bdrv_aio_readv != raw_aio_readv) { +return -ENOTSUP ; + } + + s = bs->opaque; +if (!s->use_aio) { +return -ENOTSUP ; + } +return s->fd; +} +#endif /* CONFIG_LINUX_AIO */ +static void bdrv_file_init (void ) {/* Signature · 1 line
1.8.0
Re: [Qemu-devel] [PATCH 3/7] dataplane: add virtqueue vring code
In reply to Stefan HajnocziQuoted 71 lines · Stefan Hajnoczi
The virtio-blk-data-plane cannot access memory using the usual QEMU functions since it executes outside the global mutex and the memory APIs are this time are not thread-safe.
This patch introduces a virtqueue module based on the kernel's vhost vring code. The trick is that we map guest memory ahead of time and access it cheaply outside the global mutex.
Once the hardware emulation code can execute outside the global mutex it will be possible to drop this code.
Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/Makefile.objs | 2 +- hw/dataplane/Makefile.objs | 3 + hw/dataplane/vring.c | 321 +++++++++++++++++++++++++++++++++++++++++++++ hw/dataplane/vring.h | 54 ++++++++ trace-events | 3 + 5 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 hw/dataplane/Makefile.objs create mode 100644 hw/dataplane/vring.c create mode 100644 hw/dataplane/vring.hhw/Makefile.objs +1
-1@@ -1,4 +1,4 @@ -common-obj-y = usb/ ide/ +common-obj-y = usb/ ide/ dataplane/ common-obj-y += loader.o common-obj-$(CONFIG_VIRTIO) += virtio-console.o common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.ohw/dataplane/Makefile.objs new file +3
-0@@ -0,0 +1,3 @@ +ifeq ($(CONFIG_VIRTIO), y) +common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o +endifhw/dataplane/vring.c new file +23
-0@@ -0,0 +1,321 @@ +/* Copyright 2012 Red Hat, Inc. +* Copyright IBM, Corp. 2012 +* +* Based on Linux vhost code: +* Copyright (C) 2009 Red Hat, Inc. +* Copyright (C) 2006 Rusty Russell IBM Corporation +* +* Author: Michael S. Tsirkin <[email protected]> +* Stefan Hajnoczi <[email protected]> +* +* Inspiration, some code, and most witty comments come from +* Documentation/virtual/lguest/lguest.c, by Rusty Russell +* +* This work is licensed under the terms of the GNU GPL, version 2. +*/ + +#include "trace.h" +#include "hw/dataplane/vring.h" + +/* Map target physical address to host address +*/ +static inline void *phys_to_host (Vring *vring,hwaddr phys) +{
hw/dataplane/vring.c line 33
Quoted 10 lines
hw/dataplane/vring.c new file +10
-0+/* Adjust for 3.6-4 GB PCI memory range */ +if (phys >=0x100000000 ) { + phys -=0x100000000 -0xe0000000 ; + }else if (phys >=0xe0000000 ) { +fprintf (stderr,"phys_to_host bad physical address in " +"PCI range %#lx\n" , phys); +exit (1 ); + } +return vring->phys_mem_zero_host_ptr + phys; +}
This is too dirty to merge. This code should use a slot mechanism similar to what vhost uses. Then it has a plausible chance of working on other architectures.
Quoted 5 lines
hw/dataplane/vring.c new file +5
-0+ +/* Setup for cheap target physical to host address conversion +* +* This is a hack for direct access to guest memory, we're not really allowed +* to do this.
hw/dataplane/vring.c line 48
Quoted 10 lines
hw/dataplane/vring.c new file +10
-0+*/ +static void setup_phys_to_host (Vring *vring) +{ +hwaddr len =4096 ;/* RAM is really much larger but we cheat */ + vring->phys_mem_zero_host_ptr =cpu_physical_memory_map (0 , &len,0 ); +if (!vring->phys_mem_zero_host_ptr) { +fprintf (stderr,"setup_phys_to_host failed\n" ); +exit (1 ); + } +}
You should be able to use a MemoryListener to keep the memory slot table up to date. You'll need to use a mutex to protect it but again since it's mostly uncontended, that shouldn't be a problem.
Regards,
Anthony Liguori
Quoted 349 lines
hw/dataplane/vring.c new file +273
-0+ +/* Map the guest's vring to host memory +* +* This is not allowed but we know the ring won't move. +*/ +void vring_setup (Vring *vring,VirtIODevice *vdev,int n) +{ +setup_phys_to_host (vring); + +vring_init (&vring->vr,virtio_queue_get_num (vdev, n), +phys_to_host (vring,virtio_queue_get_ring_addr (vdev, n)),4096 ); + + vring->last_avail_idx =0 ; + vring->last_used_idx =0 ; + vring->signalled_used =0 ; + vring->signalled_used_valid = false; + +trace_vring_setup (virtio_queue_get_ring_addr (vdev, n), + vring->vr.desc, vring->vr.avail, vring->vr.used); +} + +/* Toggle guest->host notifies */ +void vring_set_notification (VirtIODevice *vdev,Vring *vring,bool enable) +{ +if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { +if (enable) { +vring_avail_event (&vring->vr) = vring->vr.avail->idx; + } + }else if (enable) { + vring->vr.used->flags &= ~VRING_USED_F_NO_NOTIFY ; + }else { + vring->vr.used->flags |=VRING_USED_F_NO_NOTIFY ; + } +} + +/* This is stolen from linux/drivers/vhost/vhost.c:vhost_notify() */ +bool vring_should_notify (VirtIODevice *vdev,Vring *vring) +{ +uint16_t old, new; +bool v; +/* Flush out used index updates. This is paired +* with the barrier that the Guest executes when enabling +* interrupts. */ +smp_mb (); + +if ((vdev->guest_features &VIRTIO_F_NOTIFY_ON_EMPTY ) && +unlikely (vring->vr.avail->idx == vring->last_avail_idx)) { +return true; + } + +if (!(vdev->guest_features &VIRTIO_RING_F_EVENT_IDX )) { +return !(vring->vr.avail->flags &VRING_AVAIL_F_NO_INTERRUPT ); + } + old = vring->signalled_used; + v = vring->signalled_used_valid; + new = vring->signalled_used = vring->last_used_idx; + vring->signalled_used_valid = true; + +if (unlikely (!v)) { +return true; + } + +return vring_need_event (vring_used_event (&vring->vr), new, old); +} + +/* This is stolen from linux-2.6/drivers/vhost/vhost.c. */ +static bool get_indirect (Vring *vring, +struct iovec iov[],struct iovec *iov_end, +unsigned int *out_num,unsigned int *in_num, +struct vring_desc *indirect) +{ +struct vring_desc desc; +unsigned int i =0 , count, found =0 ; + +/* Sanity check */ +if (unlikely (indirect->len %sizeof desc)) { +fprintf (stderr,"Invalid length in indirect descriptor: " +"len 0x%llx not multiple of 0x%zx\n" , + (unsigned long long )indirect->len, +sizeof desc); +exit (1 ); + } + + count = indirect->len /sizeof desc; +/* Buffers are chained via a 16 bit next field, so +* we can have at most 2^16 of these. */ +if (unlikely (count >USHRT_MAX +1 )) { +fprintf (stderr,"Indirect buffer length too big: %d\n" , + indirect->len); +exit (1 ); + } + +/* Point to translate indirect desc chain */ + indirect =phys_to_host (vring, indirect->addr); + +/* We will use the result as an address to read from, so most +* architectures only need a compiler barrier here. */ +barrier ();/* read_barrier_depends(); */ + +do { +if (unlikely (++found > count)) { +fprintf (stderr,"Loop detected: last one at %u " +"indirect size %u\n" , + i, count); +exit (1 ); + } + + desc = *indirect++; +if (unlikely (desc.flags &VRING_DESC_F_INDIRECT )) { +fprintf (stderr,"Nested indirect descriptor\n" ); +exit (1 ); + } + +/* Stop for now if there are not enough iovecs available. */ +if (iov >= iov_end) { +return false; + } + + iov->iov_base =phys_to_host (vring, desc.addr); + iov->iov_len = desc.len; + iov++; + +/* If this is an input descriptor, increment that count. */ +if (desc.flags &VRING_DESC_F_WRITE ) { + *in_num +=1 ; + }else { +/* If it's an output descriptor, they're all supposed +* to come before any input descriptors. */ +if (unlikely (*in_num)) { +fprintf (stderr,"Indirect descriptor " +"has out after in: idx %d\n" , i); +exit (1 ); + } + *out_num +=1 ; + } + i = desc.next; + }while (desc.flags &VRING_DESC_F_NEXT ); +return true; +} + +/* This looks in the virtqueue and for the first available buffer, and converts +* it to an iovec for convenient access. Since descriptors consist of some +* number of output then some number of input descriptors, it's actually two +* iovecs, but we pack them into one and note how many of each there were. +* +* This function returns the descriptor number found, or vq->num (which is +* never a valid descriptor number) if none was found. A negative code is +* returned on error. +* +* Stolen from linux-2.6/drivers/vhost/vhost.c. +*/ +int vring_pop (VirtIODevice *vdev,Vring *vring, +struct iovec iov[],struct iovec *iov_end, +unsigned int *out_num,unsigned int *in_num) +{ +struct vring_desc desc; +unsigned int i, head, found =0 , num = vring->vr.num; +__u16 avail_idx, last_avail_idx; + +/* Check it isn't doing very strange things with descriptor numbers. */ + last_avail_idx = vring->last_avail_idx; + avail_idx = vring->vr.avail->idx; + +if (unlikely ((__u16)(avail_idx - last_avail_idx) > num)) { +fprintf (stderr,"Guest moved used index from %u to %u\n" , + last_avail_idx, avail_idx); +exit (1 ); + } + +/* If there's nothing new since last we looked. */ +if (avail_idx == last_avail_idx) { +return -EAGAIN ; + } + +/* Only get avail ring entries after they have been exposed by guest. */ +smp_rmb (); + +/* Grab the next descriptor number they're advertising, and increment +* the index we've seen. */ + head = vring->vr.avail->ring[last_avail_idx % num]; + +/* If their number is silly, that's an error. */ +if (unlikely (head >= num)) { +fprintf (stderr,"Guest says index %u > %u is available\n" , + head, num); +exit (1 ); + } + +if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { +vring_avail_event (&vring->vr) = vring->vr.avail->idx; + } + +/* When we start there are none of either input nor output. */ + *out_num = *in_num =0 ; + + i = head; +do { +if (unlikely (i >= num)) { +fprintf (stderr,"Desc index is %u > %u, head = %u\n" , + i, num, head); +exit (1 ); + } +if (unlikely (++found > num)) { +fprintf (stderr,"Loop detected: last one at %u " +"vq size %u head %u\n" , + i, num, head); +exit (1 ); + } + desc = vring->vr.desc[i]; +if (desc.flags &VRING_DESC_F_INDIRECT ) { +if (!get_indirect (vring, iov, iov_end, out_num, in_num, &desc)) { +return -ENOBUFS ;/* not enough iovecs, stop for now */ + } +continue ; + } + +/* If there are not enough iovecs left, stop for now. The caller +* should check if there are more descs available once they have dealt +* with the current set. +*/ +if (iov >= iov_end) { +return -ENOBUFS ; + } + + iov->iov_base =phys_to_host (vring, desc.addr); + iov->iov_len = desc.len; + iov++; + +if (desc.flags &VRING_DESC_F_WRITE ) { +/* If this is an input descriptor, +* increment that count. */ + *in_num +=1 ; + }else { +/* If it's an output descriptor, they're all supposed +* to come before any input descriptors. */ +if (unlikely (*in_num)) { +fprintf (stderr,"Descriptor has out after in: " +"idx %d\n" , i); +exit (1 ); + } + *out_num +=1 ; + } + i = desc.next; + }while (desc.flags &VRING_DESC_F_NEXT ); + +/* On success, increment avail index. */ + vring->last_avail_idx++; +return head; +} + +/* After we've used one of their buffers, we tell them about it. +* +* Stolen from linux-2.6/drivers/vhost/vhost.c. +*/ +void vring_push (Vring *vring,unsigned int head,int len) +{ +struct vring_used_elem *used; +uint16_t new; + +/* The virtqueue contains a ring of used buffers. Get a pointer to the +* next entry in that used ring. */ + used = &vring->vr.used->ring[vring->last_used_idx % vring->vr.num]; + used->id = head; + used->len = len; + +/* Make sure buffer is written before we update index. */ +smp_wmb (); + + new = vring->vr.used->idx = ++vring->last_used_idx; +if (unlikely ((int16_t )(new - vring->signalled_used) < (uint16_t )1 )) { + vring->signalled_used_valid = false; + } +}hw/dataplane/vring.h new file +54
-0@@ -0,0 +1,54 @@ +/* Copyright 2012 Red Hat, Inc. and/or its affiliates +* Copyright IBM, Corp. 2012 +* +* Based on Linux vhost code: +* Copyright (C) 2009 Red Hat, Inc. +* Copyright (C) 2006 Rusty Russell IBM Corporation +* +* Author: Michael S. Tsirkin <[email protected]> +* Stefan Hajnoczi <[email protected]> +* +* Inspiration, some code, and most witty comments come from +* Documentation/virtual/lguest/lguest.c, by Rusty Russell +* +* This work is licensed under the terms of the GNU GPL, version 2. +*/ + +#ifndef VRING_H +#define VRING_H + +#include <linux/virtio_ring.h> +#include "qemu-common.h" +#include "qemu-barrier.h" +#include "memory.h" +#include "hw/virtio.h" + +typedef struct { +void *phys_mem_zero_host_ptr;/* host pointer to guest RAM */ +struct vring vr;/* virtqueue vring mapped to host memory */ +__u16 last_avail_idx;/* last processed avail ring index */ +__u16 last_used_idx;/* last processed used ring index */ +uint16_t signalled_used;/* EVENT_IDX state */ +bool signalled_used_valid; +}Vring ; + +static inline unsigned int vring_get_num (Vring *vring) +{ +return vring->vr.num; +} + +/* Are there more descriptors available? */ +static inline bool vring_more_avail (Vring *vring) +{ +return vring->vr.avail->idx != vring->last_avail_idx; +} + +void vring_setup (Vring *vring,VirtIODevice *vdev,int n); +void vring_set_notification (VirtIODevice *vdev,Vring *vring,bool enable); +bool vring_should_notify (VirtIODevice *vdev,Vring *vring); +int vring_pop (VirtIODevice *vdev,Vring *vring, +struct iovec iov[],struct iovec *iov_end, +unsigned int *out_num,unsigned int *in_num); +void vring_push (Vring *vring,unsigned int head,int len); + +#endif /* VRING_H */ trace-events +3
-0@@ -98,6 +98,9 @@ virtio_blk_rw_complete(void *req, int ret) "req %p ret %d" virtio_blk_handle_write(void *req, uint64_t sector, size_t nsectors) "req %p sector %"PRIu64" nsectors %zu" virtio_blk_handle_read(void *req, uint64_t sector, size_t nsectors) "req %p sector %"PRIu64" nsectors %zu" +# hw/dataplane/vring.c +vring_setup(uint64_t physical, void *desc, void *avail, void *used) "vring physical %#"PRIx64" desc %p avail %p used %p" + # thread-pool.c thread_pool_submit(void *req, void *opaque) "req %p opaque %p" thread_pool_complete(void *req, void *opaque, int ret) "req %p opaque %p ret %d"Signature · 1 line
1.8.0
Re: [Qemu-devel] [PATCH 7/7] virtio-blk: add x-data-plane=on|off performance feature
In reply to Stefan HajnocziQuoted 6 lines · Stefan Hajnoczi
The virtio-blk-data-plane feature is easy to integrate into
hw/virtio-blk.c. The data plane can be started and stopped similar to vhost-net.Users can take advantage of the virtio-blk-data-plane feature using the new -device virtio-blk-pci,x-data-plane=on property.
I don't think this should be a property of virtio-blk-pci but rather a separate device.
It's an alternative interface with a slightly different guest view.
Regards,
Anthony Liguori
Quoted 179 lines
The x-data-plane name was chosen because at this stage the feature is experimental and likely to see changes in the future.
If the VM configuration does not support virtio-blk-data-plane an error message is printed. Although we could fall back to regular virtio-blk, I prefer the explicit approach since it prompts the user to fix their configuration if they want the performance benefit of virtio-blk-data-plane.
Limitations:
* Only format=raw is supported
* Live migration is not supported
* Block jobs, hot unplug, and other operations fail with-EBUSY
* I/O throttling limits are ignored
* Only Linux hosts are supported due to Linux AIO usageSigned-off-by Stefan Hajnoczi <[email protected]>--- hw/virtio-blk.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- hw/virtio-blk.h | 1 + hw/virtio-pci.c | 3 +++ 3 files changed, 62 insertions(+), 1 deletion(-)hw/virtio-blk.c +58
-1@@ -17,6 +17,8 @@#include "hw/block-common.h" #include "blockdev.h" #include "virtio-blk.h" +#include "hw/dataplane/virtio-blk.h" +#include "migration.h" #include "scsi-defs.h" #ifdef __linux__# include <scsi/sg.h> @@ -33,6 +35,8 @@ typedef struct VirtIOBlockVirtIOBlkConf *blk;unsigned short sector_mask;DeviceState *qdev; +VirtIOBlockDataPlane *dataplane; +Error *migration_blocker; } VirtIOBlock;static VirtIOBlock *to_virtio_blk (VirtIODevice *vdev)@@ -407,6 +411,14 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) .num_writes = 0, }; +/* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start +* dataplane here instead of waiting for .set_status(). +*/ +if (s->dataplane) { +virtio_blk_data_plane_start (s->dataplane); +return ; + } +while ((req =virtio_blk_get_request (s))) {virtio_blk_handle_request (req, &mrb); }@@ -446,8 +458,13 @@ static void virtio_blk_dma_restart_cb(void *opaque, int running, {VirtIOBlock *s = opaque; -if (!running) +if (!running) { +/* qemu_drain_all() doesn't know about data plane, quiesce here */ +if (s->dataplane) { +virtio_blk_data_plane_drain (s->dataplane); + }return ; + }if (!s->bh) { s->bh =qemu_bh_new (virtio_blk_dma_restart_bh, s);@@ -538,6 +555,10 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)VirtIOBlock *s =to_virtio_blk (vdev);uint32_t features; +if (s->dataplane && !(status &VIRTIO_CONFIG_S_DRIVER )) { +virtio_blk_data_plane_stop (s->dataplane); + } +if (!(status &VIRTIO_CONFIG_S_DRIVER_OK )) {return ; }@@ -604,6 +625,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) {VirtIOBlock *s;static int virtio_blk_id; +int fd =-1 ;if (!blk->conf.bs) {error_report ("drive property not set" );@@ -619,6 +641,21 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)return NULL ; } +if (blk->data_plane) { +if (blk->scsi) { +error_report ("device is incompatible with x-data-plane, " +"use scsi=off" ); +return NULL ; + } + + fd =raw_get_aio_fd (blk->conf.bs); +if (fd <0 ) { +error_report ("drive is incompatible with x-data-plane, " +"use format=raw,cache=none,aio=native" ); +return NULL ; + } + } + s = (VirtIOBlock *)virtio_common_init ("virtio-blk" ,VIRTIO_ID_BLOCK ,sizeof (struct virtio_blk_config ),sizeof (VirtIOBlock));@@ -636,6 +673,17 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) s->vq =virtio_add_queue (&s->vdev,128 , virtio_blk_handle_output); +if (fd >=0 ) { + s->dataplane =virtio_blk_data_plane_create (&s->vdev, fd); + +/* Prevent block operations that conflict with data plane thread */ +bdrv_set_in_use (s->bs,1 ); + +error_setg (&s->migration_blocker, +"x-data-plane does not support migration" ); +migrate_add_blocker (s->migration_blocker); + } +qemu_add_vm_change_state_handler (virtio_blk_dma_restart_cb, s); s->qdev = dev; register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,@@ -652,6 +700,15 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)void virtio_blk_exit (VirtIODevice *vdev) {VirtIOBlock *s =to_virtio_blk (vdev); + +if (s->dataplane) { +migrate_del_blocker (s->migration_blocker); +error_free (s->migration_blocker); +bdrv_set_in_use (s->bs,0 ); +virtio_blk_data_plane_destroy (s->dataplane); + s->dataplane =NULL ; + } +unregister_savevm (s->qdev,"virtio-blk" , s);blockdev_mark_auto_del (s->bs);virtio_cleanup (vdev);hw/virtio-blk.h +1
-0@@ -105,6 +105,7 @@ struct VirtIOBlkConfchar *serial;uint32_t scsi;uint32_t config_wce; +uint32_t data_plane; };#define DEFINE_VIRTIO_BLK_FEATURES (_state, _field) \hw/virtio-pci.c +3
-0@@ -862,6 +862,9 @@ static Property virtio_blk_properties[] = {#endif DEFINE_PROP_BIT ("config-wce" , VirtIOPCIProxy, blk.config_wce,0 , true),DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE +DEFINE_PROP_BIT ("x-data-plane" , VirtIOPCIProxy, blk.data_plane,0 , false), +#endifDEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_VIRTIO_BLK_FEATURES (VirtIOPCIProxy, host_features), DEFINE_PROP_END_OF_LIST(),Signature · 1 line
1.8.0
Re: [Qemu-devel] [PATCH 7/7] virtio-blk: add x-data-plane=on|off performance feature
In reply to Khoa HuynhQuoted 49 lines · Khoa Huynh
"Michael S. Tsirkin" <[email protected]> wrote on 11/15/2012 12:48:49 PM:
Quoted 33 lines
From: "Michael S. Tsirkin" <[email protected]>
To: Stefan Hajnoczi <[email protected]>,
Cc: [email protected], Anthony Liguori/Austin/IBM@IBMUS, Paolo Bonzini <[email protected]>, Kevin Wolf <[email protected]>, Asias He <[email protected]>, Khoa Huynh/Austin/IBM@IBMUS
Date: 11/15/2012 12:46 PM
Subject: Re: [PATCH 7/7] virtio-blk: add x-data-plane=on|off performance featureQuoted 23 lines · Stefan Hajnoczi
The virtio-blk-data-plane feature is easy to integrate into
hw/virtio-blk.c. The data plane can be started and stopped similar to vhost-net.Users can take advantage of the virtio-blk-data-plane feature using the new -device virtio-blk-pci,x-data-plane=on property.
The x-data-plane name was chosen because at this stage the feature is experimental and likely to see changes in the future.
If the VM configuration does not support virtio-blk-data-plane an error message is printed. Although we could fall back to regular virtio-blk, I prefer the explicit approach since it prompts the user to fix their configuration if they want the performance benefit of virtio-blk-data-plane.
Limitations:
* Only format=raw is supported
* Live migration is not supported
* Block jobs, hot unplug, and other operations fail with-EBUSY
* I/O throttling limits are ignored
* Only Linux hosts are supported due to Linux AIO usageQuoted 6 lines
Quoted 1 line
Signed-off-by Stefan Hajnoczi <[email protected]>Would be very interested in learning about the performance impact of this. How does this compare to current model and to vhost-blk?
I plan to do a complete evaluation of this patchset in the coming days. However, I have done quite a bit of performance testing on earlier versions of the data-plane and vhost-blk code bits. Here's what I found:
1) The existing kvm/qemu code can only handle up to about 150,000 IOPS for a single KVM guest. The bottleneck here is the global qemu mutex.
Quoted 6 lines
2) With performance tuning, I was able to achieve 1.33 million IOPS for a single KVM guest with data-plane. This is very close to the 1.4-million-IOPS
limit of my storage setup.From my POV, if we can get this close to bare metal with
virtio-blk-dataplane, there's absolutely no reason to merge vhost-blk support.
We simply lose too much with a kernel-based solution.
I'm sure there's more we can do to improve the userspace implementation too like a hypercall-based notify and adaptive polling.
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 1/7] raw-posix: add raw_get_aio_fd() for virtio-blk-data-plane
In reply to Anthony LiguoriQuoted 9 lines · Anthony Liguori
Quoted 7 lines · Stefan Hajnoczi
The
raw_get_aio_fd()function allows virtio-blk-data-plane to get the file descriptor of a raw image file with Linux AIO enabled. This interface is really a layering violation that can be resolved once the block layer is able to run outside the global mutex - at that point virtio-blk-data-plane will switch from custom Linux AIO code to using the block layer.
Quoted 8 lines
Quoted 1 line
Signed-off-by Stefan Hajnoczi <[email protected]>I think this creates user confusion because virtio-blk-data-plane can't actually take a BDS.
So why not just make a string 'filename' property and open it directly in virtio-blk-data-plane? Then it's at least clear to the user and management tools what the device is capable of doing.
There are some benefits to raw_get_aio_fd():
1. virtio-blk-data-plane is only a subset virtio-blk implementation, it still needs a regular virtio-blk-pci device (with BDS) in order to run. If we use a filename the user would have to specify it twice.
2. Fetching the file descriptor in this way ensures that the image file is format=raw.
3. virtio-blk-data-plane uses Linux AIO and raw-posix.c has checks which I don't want to duplicate - we can simply check s->use_aio in raw_get_aio_fd() to confirm that Linux AIO can be used.
If we open a file directly then we lose these benefits. Do you still think we should open a filename?
Stefan
Re: [Qemu-devel] [PATCH 7/7] virtio-blk: add x-data-plane=on|off performance feature
In reply to Anthony LiguoriQuoted 11 lines · Anthony Liguori
Quoted 6 lines · Stefan Hajnoczi
The virtio-blk-data-plane feature is easy to integrate into
hw/virtio-blk.c. The data plane can be started and stopped similar to vhost-net.Users can take advantage of the virtio-blk-data-plane feature using the new -device virtio-blk-pci,x-data-plane=on property.
I don't think this should be a property of virtio-blk-pci but rather a separate device.
The hw/virtio-blk.c code still needs to be used since hw/dataplane/virtio-blk.c is only a subset of virtio-blk.
So we're talking about adding a new virtio-blk-data-plane-pci device type to hw/virtio-pci.c?
Stefan
Re: [Qemu-devel] [PATCH 3/7] dataplane: add virtqueue vring code
In reply to Anthony LiguoriQuoted 87 lines · Anthony Liguori
Quoted 71 lines · Stefan Hajnoczi
The virtio-blk-data-plane cannot access memory using the usual QEMU functions since it executes outside the global mutex and the memory APIs are this time are not thread-safe.
This patch introduces a virtqueue module based on the kernel's vhost vring code. The trick is that we map guest memory ahead of time and access it cheaply outside the global mutex.
Once the hardware emulation code can execute outside the global mutex it will be possible to drop this code.
Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/Makefile.objs | 2 +- hw/dataplane/Makefile.objs | 3 + hw/dataplane/vring.c | 321 +++++++++++++++++++++++++++++++++++++++++++++ hw/dataplane/vring.h | 54 ++++++++ trace-events | 3 + 5 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 hw/dataplane/Makefile.objs create mode 100644 hw/dataplane/vring.c create mode 100644 hw/dataplane/vring.hhw/Makefile.objs +1
-1@@ -1,4 +1,4 @@ -common-obj-y = usb/ ide/ +common-obj-y = usb/ ide/ dataplane/ common-obj-y += loader.o common-obj-$(CONFIG_VIRTIO) += virtio-console.o common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.ohw/dataplane/Makefile.objs new file +3
-0@@ -0,0 +1,3 @@ +ifeq ($(CONFIG_VIRTIO), y) +common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o +endifhw/dataplane/vring.c new file +23
-0@@ -0,0 +1,321 @@ +/* Copyright 2012 Red Hat, Inc. +* Copyright IBM, Corp. 2012 +* +* Based on Linux vhost code: +* Copyright (C) 2009 Red Hat, Inc. +* Copyright (C) 2006 Rusty Russell IBM Corporation +* +* Author: Michael S. Tsirkin <[email protected]> +* Stefan Hajnoczi <[email protected]> +* +* Inspiration, some code, and most witty comments come from +* Documentation/virtual/lguest/lguest.c, by Rusty Russell +* +* This work is licensed under the terms of the GNU GPL, version 2. +*/ + +#include "trace.h" +#include "hw/dataplane/vring.h" + +/* Map target physical address to host address +*/ +static inline void *phys_to_host (Vring *vring,hwaddr phys) +{hw/dataplane/vring.c line 33
Quoted 10 lines
hw/dataplane/vring.c new file +10
-0+/* Adjust for 3.6-4 GB PCI memory range */ +if (phys >=0x100000000 ) { + phys -=0x100000000 -0xe0000000 ; + }else if (phys >=0xe0000000 ) { +fprintf (stderr,"phys_to_host bad physical address in " +"PCI range %#lx\n" , phys); +exit (1 ); + } +return vring->phys_mem_zero_host_ptr + phys; +}This is too dirty to merge. This code should use a slot mechanism similar to what vhost uses. Then it has a plausible chance of working on other architectures.
[...]
Quoted 3 lines
You should be able to use a MemoryListener to keep the memory slot table up to date. You'll need to use a mutex to protect it but again since it's mostly uncontended, that shouldn't be a problem.
Anthony, Paolo,
You're right, we should use MemoryListener. Will fix for v2.
Stefan
Re: [Qemu-devel] [PATCH 7/7] virtio-blk: add x-data-plane=on|off performance feature
In reply to Anthony LiguoriIl 15/11/2012 22:08, Anthony Liguori ha scritto:
Quoted 11 lines
Quoted 6 lines · Stefan Hajnoczi
The virtio-blk-data-plane feature is easy to integrate into
hw/virtio-blk.c. The data plane can be started and stopped similar to vhost-net.Users can take advantage of the virtio-blk-data-plane feature using the new -device virtio-blk-pci,x-data-plane=on property.
I don't think this should be a property of virtio-blk-pci but rather a separate device.
Since this is all temporary and we want it to become the default (perhaps keeping the old code for ioeventfd=false only), I don't think it really matters.
Paolo
Re: [Qemu-devel] [PATCH 3/7] dataplane: add virtqueue vring code
In reply to Stefan HajnocziQuoted 5 lines · Stefan Hajnoczi
hw/dataplane/vring.c new file +5
-0+#include "trace.h" +#include "hw/dataplane/vring.h" + +/* Map target physical address to host address +*/
hw/dataplane/vring.c line 31
Quoted 10 lines
hw/dataplane/vring.c new file +10
-0+static inline void *phys_to_host (Vring *vring,hwaddr phys) +{ +/* Adjust for 3.6-4 GB PCI memory range */ +if (phys >=0x100000000 ) { + phys -=0x100000000 -0xe0000000 ; + }else if (phys >=0xe0000000 ) { +fprintf (stderr,"phys_to_host bad physical address in " +"PCI range %#lx\n" , phys); +exit (1 ); + }
I think non-pci virtio also wants to use dataplane. Any chance to move such pci specific things out of the main code?
Christian
Re: [Qemu-devel] [PATCH 3/7] dataplane: add virtqueue vring code
Quoted 12 lines · Christian Borntraeger
Quoted 10 lines · Stefan Hajnoczi
hw/dataplane/vring.c new file +10
-0+#include "trace.h" +#include "hw/dataplane/vring.h" + +/* Map target physical address to host address +*/ +static inline void *phys_to_host (Vring *vring,hwaddr phys) +{ +/* Adjust for 3.6-4 GB PCI memory range */ +if (phys >=0x100000000 ) { + phys -=0x100000000 -0xe0000000 ;
Quoted 8 lines
hw/dataplane/vring.c line 31
Quoted 5 lines
hw/dataplane/vring.c new file +5
-0+ }else if (phys >=0xe0000000 ) { +fprintf (stderr,"phys_to_host bad physical address in " +"PCI range %#lx\n" , phys); +exit (1 ); + }I think non-pci virtio also wants to use dataplane. Any chance to move such pci specific things out of the main code?
Yes, using MemoryListener take care of this. Actually enabling virtio-blk-mmio or virtio-blk-ccw should work as long as those transports provide ioeventfd, irqfd, and use the vring memory layout.
Stefan
Re: [Qemu-devel] [PATCH 1/7] raw-posix: add raw_get_aio_fd() for virtio-blk-data-plane
In reply to Stefan HajnocziIl 16/11/2012 07:15, Stefan Hajnoczi ha scritto:
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
So why not just make a string 'filename' property and open it directly in virtio-blk-data-plane? Then it's at least clear to the user and management tools what the device is capable of doing.
There are some benefits to
raw_get_aio_fd():1. virtio-blk-data-plane is only a subset virtio-blk implementation, it still needs a regular virtio-blk-pci device (with BDS) in order to run. If we use a filename the user would have to specify it twice.
Quoted 6 lines
2. Fetching the file descriptor in this way ensures that the image file is format=raw.
3. virtio-blk-data-plane uses Linux AIO and
raw-posix.chas checks which I don't want to duplicate - we can simply checks->use_aioinraw_get_aio_fd()to confirm that Linux AIO can be used.
Agreed. This is not vhost-blk, for which I agree that opening the file would make more sense (so you have no BDS at all). It's just a stopgap measure for something that should become the standard implementation.
Paolo
Re: [Qemu-devel] [PATCH 3/7] dataplane: add virtqueue vring code
In reply to Stefan HajnocziQuoted 68 lines · Stefan Hajnoczi
The virtio-blk-data-plane cannot access memory using the usual QEMU functions since it executes outside the global mutex and the memory APIs are this time are not thread-safe.
This patch introduces a virtqueue module based on the kernel's vhost vring code. The trick is that we map guest memory ahead of time and access it cheaply outside the global mutex.
Once the hardware emulation code can execute outside the global mutex it will be possible to drop this code.
Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/Makefile.objs | 2 +- hw/dataplane/Makefile.objs | 3 + hw/dataplane/vring.c | 321 +++++++++++++++++++++++++++++++++++++++++++++ hw/dataplane/vring.h | 54 ++++++++ trace-events | 3 + 5 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 hw/dataplane/Makefile.objs create mode 100644 hw/dataplane/vring.c create mode 100644 hw/dataplane/vring.hhw/Makefile.objs +1
-1@@ -1,4 +1,4 @@ -common-obj-y = usb/ ide/ +common-obj-y = usb/ ide/ dataplane/ common-obj-y += loader.o common-obj-$(CONFIG_VIRTIO) += virtio-console.o common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.ohw/dataplane/Makefile.objs new file +3
-0@@ -0,0 +1,3 @@ +ifeq ($(CONFIG_VIRTIO), y) +common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o +endifhw/dataplane/vring.c new file +20
-0@@ -0,0 +1,321 @@ +/* Copyright 2012 Red Hat, Inc. +* Copyright IBM, Corp. 2012 +* +* Based on Linux vhost code: +* Copyright (C) 2009 Red Hat, Inc. +* Copyright (C) 2006 Rusty Russell IBM Corporation +* +* Author: Michael S. Tsirkin <[email protected]> +* Stefan Hajnoczi <[email protected]> +* +* Inspiration, some code, and most witty comments come from +* Documentation/virtual/lguest/lguest.c, by Rusty Russell +* +* This work is licensed under the terms of the GNU GPL, version 2. +*/ + +#include "trace.h" +#include "hw/dataplane/vring.h" + +/* Map target physical address to host address
hw/dataplane/vring.c line 30
Quoted 10 lines
hw/dataplane/vring.c new file +10
-0+*/ +static inline void *phys_to_host (Vring *vring,hwaddr phys) +{ +/* Adjust for 3.6-4 GB PCI memory range */ +if (phys >=0x100000000 ) { + phys -=0x100000000 -0xe0000000 ; + }else if (phys >=0xe0000000 ) { +fprintf (stderr,"phys_to_host bad physical address in " +"PCI range %#lx\n" , phys); +exit (1 );
Exiting is rather drastic. Is this guest's error or QEMU's?
Quoted 166 lines
hw/dataplane/vring.c new file +166
-0+ } +return vring->phys_mem_zero_host_ptr + phys; +} + +/* Setup for cheap target physical to host address conversion +* +* This is a hack for direct access to guest memory, we're not really allowed +* to do this. +*/ +static void setup_phys_to_host (Vring *vring) +{ +hwaddr len =4096 ;/* RAM is really much larger but we cheat */ + vring->phys_mem_zero_host_ptr =cpu_physical_memory_map (0 , &len,0 ); +if (!vring->phys_mem_zero_host_ptr) { +fprintf (stderr,"setup_phys_to_host failed\n" ); +exit (1 ); + } +} + +/* Map the guest's vring to host memory +* +* This is not allowed but we know the ring won't move. +*/ +void vring_setup (Vring *vring,VirtIODevice *vdev,int n) +{ +setup_phys_to_host (vring); + +vring_init (&vring->vr,virtio_queue_get_num (vdev, n), +phys_to_host (vring,virtio_queue_get_ring_addr (vdev, n)),4096 ); + + vring->last_avail_idx =0 ; + vring->last_used_idx =0 ; + vring->signalled_used =0 ; + vring->signalled_used_valid = false; + +trace_vring_setup (virtio_queue_get_ring_addr (vdev, n), + vring->vr.desc, vring->vr.avail, vring->vr.used); +} + +/* Toggle guest->host notifies */ +void vring_set_notification (VirtIODevice *vdev,Vring *vring,bool enable) +{ +if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { +if (enable) { +vring_avail_event (&vring->vr) = vring->vr.avail->idx; + } + }else if (enable) { + vring->vr.used->flags &= ~VRING_USED_F_NO_NOTIFY ; + }else { + vring->vr.used->flags |=VRING_USED_F_NO_NOTIFY ; + } +} + +/* This is stolen from linux/drivers/vhost/vhost.c:vhost_notify() */ +bool vring_should_notify (VirtIODevice *vdev,Vring *vring) +{ +uint16_t old, new; +bool v; +/* Flush out used index updates. This is paired +* with the barrier that the Guest executes when enabling +* interrupts. */ +smp_mb (); + +if ((vdev->guest_features &VIRTIO_F_NOTIFY_ON_EMPTY ) && +unlikely (vring->vr.avail->idx == vring->last_avail_idx)) { +return true; + } + +if (!(vdev->guest_features &VIRTIO_RING_F_EVENT_IDX )) { +return !(vring->vr.avail->flags &VRING_AVAIL_F_NO_INTERRUPT ); + } + old = vring->signalled_used; + v = vring->signalled_used_valid; + new = vring->signalled_used = vring->last_used_idx; + vring->signalled_used_valid = true; + +if (unlikely (!v)) { +return true; + } + +return vring_need_event (vring_used_event (&vring->vr), new, old); +} + +/* This is stolen from linux-2.6/drivers/vhost/vhost.c. */ +static bool get_indirect (Vring *vring, +struct iovec iov[],struct iovec *iov_end, +unsigned int *out_num,unsigned int *in_num, +struct vring_desc *indirect) +{ +struct vring_desc desc; +unsigned int i =0 , count, found =0 ; + +/* Sanity check */ +if (unlikely (indirect->len %sizeof desc)) { +fprintf (stderr,"Invalid length in indirect descriptor: " +"len 0x%llx not multiple of 0x%zx\n" , + (unsigned long long )indirect->len, +sizeof desc); +exit (1 ); + } + + count = indirect->len /sizeof desc; +/* Buffers are chained via a 16 bit next field, so +* we can have at most 2^16 of these. */ +if (unlikely (count >USHRT_MAX +1 )) { +fprintf (stderr,"Indirect buffer length too big: %d\n" , + indirect->len); +exit (1 ); + } + +/* Point to translate indirect desc chain */ + indirect =phys_to_host (vring, indirect->addr); + +/* We will use the result as an address to read from, so most +* architectures only need a compiler barrier here. */ +barrier ();/* read_barrier_depends(); */ + +do { +if (unlikely (++found > count)) { +fprintf (stderr,"Loop detected: last one at %u " +"indirect size %u\n" , + i, count); +exit (1 ); + } + + desc = *indirect++; +if (unlikely (desc.flags &VRING_DESC_F_INDIRECT )) { +fprintf (stderr,"Nested indirect descriptor\n" ); +exit (1 ); + } + +/* Stop for now if there are not enough iovecs available. */ +if (iov >= iov_end) { +return false; + } + + iov->iov_base =phys_to_host (vring, desc.addr); + iov->iov_len = desc.len; + iov++; + +/* If this is an input descriptor, increment that count. */ +if (desc.flags &VRING_DESC_F_WRITE ) { + *in_num +=1 ; + }else { +/* If it's an output descriptor, they're all supposed +* to come before any input descriptors. */ +if (unlikely (*in_num)) { +fprintf (stderr,"Indirect descriptor " +"has out after in: idx %d\n" , i); +exit (1 ); + } + *out_num +=1 ; + } + i = desc.next; + }while (desc.flags &VRING_DESC_F_NEXT ); +return true; +} + +/* This looks in the virtqueue and for the first available buffer, and converts +* it to an iovec for convenient access. Since descriptors consist of some +* number of output then some number of input descriptors, it's actually two +* iovecs, but we pack them into one and note how many of each there were. +* +* This function returns the descriptor number found, or vq->num (which is +* never a valid descriptor number) if none was found. A negative code is +* returned on error.
hw/dataplane/vring.c line 206
Quoted 10 lines
hw/dataplane/vring.c new file +10
-0+* +* Stolen from linux-2.6/drivers/vhost/vhost.c. +*/ +int vring_pop (VirtIODevice *vdev,Vring *vring, +struct iovec iov[],struct iovec *iov_end, +unsigned int *out_num,unsigned int *in_num) +{ +struct vring_desc desc; +unsigned int i, head, found =0 , num = vring->vr.num; +__u16 avail_idx, last_avail_idx;
Please use uint16_t in QEMU code.
Quoted 193 lines
hw/dataplane/vring.c new file +115
-0+ +/* Check it isn't doing very strange things with descriptor numbers. */ + last_avail_idx = vring->last_avail_idx; + avail_idx = vring->vr.avail->idx; + +if (unlikely ((__u16)(avail_idx - last_avail_idx) > num)) { +fprintf (stderr,"Guest moved used index from %u to %u\n" , + last_avail_idx, avail_idx); +exit (1 ); + } + +/* If there's nothing new since last we looked. */ +if (avail_idx == last_avail_idx) { +return -EAGAIN ; + } + +/* Only get avail ring entries after they have been exposed by guest. */ +smp_rmb (); + +/* Grab the next descriptor number they're advertising, and increment +* the index we've seen. */ + head = vring->vr.avail->ring[last_avail_idx % num]; + +/* If their number is silly, that's an error. */ +if (unlikely (head >= num)) { +fprintf (stderr,"Guest says index %u > %u is available\n" , + head, num); +exit (1 ); + } + +if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { +vring_avail_event (&vring->vr) = vring->vr.avail->idx; + } + +/* When we start there are none of either input nor output. */ + *out_num = *in_num =0 ; + + i = head; +do { +if (unlikely (i >= num)) { +fprintf (stderr,"Desc index is %u > %u, head = %u\n" , + i, num, head); +exit (1 ); + } +if (unlikely (++found > num)) { +fprintf (stderr,"Loop detected: last one at %u " +"vq size %u head %u\n" , + i, num, head); +exit (1 ); + } + desc = vring->vr.desc[i]; +if (desc.flags &VRING_DESC_F_INDIRECT ) { +if (!get_indirect (vring, iov, iov_end, out_num, in_num, &desc)) { +return -ENOBUFS ;/* not enough iovecs, stop for now */ + } +continue ; + } + +/* If there are not enough iovecs left, stop for now. The caller +* should check if there are more descs available once they have dealt +* with the current set. +*/ +if (iov >= iov_end) { +return -ENOBUFS ; + } + + iov->iov_base =phys_to_host (vring, desc.addr); + iov->iov_len = desc.len; + iov++; + +if (desc.flags &VRING_DESC_F_WRITE ) { +/* If this is an input descriptor, +* increment that count. */ + *in_num +=1 ; + }else { +/* If it's an output descriptor, they're all supposed +* to come before any input descriptors. */ +if (unlikely (*in_num)) { +fprintf (stderr,"Descriptor has out after in: " +"idx %d\n" , i); +exit (1 ); + } + *out_num +=1 ; + } + i = desc.next; + }while (desc.flags &VRING_DESC_F_NEXT ); + +/* On success, increment avail index. */ + vring->last_avail_idx++; +return head; +} + +/* After we've used one of their buffers, we tell them about it. +* +* Stolen from linux-2.6/drivers/vhost/vhost.c. +*/ +void vring_push (Vring *vring,unsigned int head,int len) +{ +struct vring_used_elem *used; +uint16_t new; + +/* The virtqueue contains a ring of used buffers. Get a pointer to the +* next entry in that used ring. */ + used = &vring->vr.used->ring[vring->last_used_idx % vring->vr.num]; + used->id = head; + used->len = len; + +/* Make sure buffer is written before we update index. */ +smp_wmb (); + + new = vring->vr.used->idx = ++vring->last_used_idx; +if (unlikely ((int16_t )(new - vring->signalled_used) < (uint16_t )1 )) { + vring->signalled_used_valid = false; + } +}hw/dataplane/vring.h new file +54
-0@@ -0,0 +1,54 @@ +/* Copyright 2012 Red Hat, Inc. and/or its affiliates +* Copyright IBM, Corp. 2012 +* +* Based on Linux vhost code: +* Copyright (C) 2009 Red Hat, Inc. +* Copyright (C) 2006 Rusty Russell IBM Corporation +* +* Author: Michael S. Tsirkin <[email protected]> +* Stefan Hajnoczi <[email protected]> +* +* Inspiration, some code, and most witty comments come from +* Documentation/virtual/lguest/lguest.c, by Rusty Russell +* +* This work is licensed under the terms of the GNU GPL, version 2. +*/ + +#ifndef VRING_H +#define VRING_H + +#include <linux/virtio_ring.h> +#include "qemu-common.h" +#include "qemu-barrier.h" +#include "memory.h" +#include "hw/virtio.h" + +typedef struct { +void *phys_mem_zero_host_ptr;/* host pointer to guest RAM */ +struct vring vr;/* virtqueue vring mapped to host memory */ +__u16 last_avail_idx;/* last processed avail ring index */ +__u16 last_used_idx;/* last processed used ring index */ +uint16_t signalled_used;/* EVENT_IDX state */ +bool signalled_used_valid; +}Vring ; + +static inline unsigned int vring_get_num (Vring *vring) +{ +return vring->vr.num; +} + +/* Are there more descriptors available? */ +static inline bool vring_more_avail (Vring *vring) +{ +return vring->vr.avail->idx != vring->last_avail_idx; +} + +void vring_setup (Vring *vring,VirtIODevice *vdev,int n); +void vring_set_notification (VirtIODevice *vdev,Vring *vring,bool enable); +bool vring_should_notify (VirtIODevice *vdev,Vring *vring); +int vring_pop (VirtIODevice *vdev,Vring *vring, +struct iovec iov[],struct iovec *iov_end, +unsigned int *out_num,unsigned int *in_num); +void vring_push (Vring *vring,unsigned int head,int len); + +#endif /* VRING_H */ trace-events +3
-1@@ -98,6 +98,9 @@ virtio_blk_rw_complete(void *req, int ret) "req %p ret %d" virtio_blk_handle_write(void *req, uint64_t sector, size_t nsectors) "req %p sector %"PRIu64" nsectors %zu" virtio_blk_handle_read(void *req, uint64_t sector, size_t nsectors) "req %p sector %"PRIu64" nsectors %zu" +# hw/dataplane/vring.c +vring_setup(uint64_t physical, void *desc, void *avail, void *used) "vring physical %#"PRIx64" desc %p avail %p used %p" + # thread-pool.c thread_pool_submit(void *req, void *opaque) "req %p opaque %p" thread_pool_complete(void *req, void *opaque, int ret) "req %p opaque %p ret %d" --1.8.0
Re: [Qemu-devel] [PATCH 3/7] dataplane: add virtqueue vring code
Quoted 73 lines · Blue Swirl
Quoted 72 lines · Stefan Hajnoczi
The virtio-blk-data-plane cannot access memory using the usual QEMU functions since it executes outside the global mutex and the memory APIs are this time are not thread-safe.
This patch introduces a virtqueue module based on the kernel's vhost vring code. The trick is that we map guest memory ahead of time and access it cheaply outside the global mutex.
Once the hardware emulation code can execute outside the global mutex it will be possible to drop this code.
Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/Makefile.objs | 2 +- hw/dataplane/Makefile.objs | 3 + hw/dataplane/vring.c | 321 +++++++++++++++++++++++++++++++++++++++++++++ hw/dataplane/vring.h | 54 ++++++++ trace-events | 3 + 5 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 hw/dataplane/Makefile.objs create mode 100644 hw/dataplane/vring.c create mode 100644 hw/dataplane/vring.hhw/Makefile.objs +1
-1@@ -1,4 +1,4 @@ -common-obj-y = usb/ ide/ +common-obj-y = usb/ ide/ dataplane/ common-obj-y += loader.o common-obj-$(CONFIG_VIRTIO) += virtio-console.o common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.ohw/dataplane/Makefile.objs new file +3
-0@@ -0,0 +1,3 @@ +ifeq ($(CONFIG_VIRTIO), y) +common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += vring.o +endifhw/dataplane/vring.c new file +24
-0@@ -0,0 +1,321 @@ +/* Copyright 2012 Red Hat, Inc. +* Copyright IBM, Corp. 2012 +* +* Based on Linux vhost code: +* Copyright (C) 2009 Red Hat, Inc. +* Copyright (C) 2006 Rusty Russell IBM Corporation +* +* Author: Michael S. Tsirkin <[email protected]> +* Stefan Hajnoczi <[email protected]> +* +* Inspiration, some code, and most witty comments come from +* Documentation/virtual/lguest/lguest.c, by Rusty Russell +* +* This work is licensed under the terms of the GNU GPL, version 2. +*/ + +#include "trace.h" +#include "hw/dataplane/vring.h" + +/* Map target physical address to host address +*/ +static inline void *phys_to_host (Vring *vring,hwaddr phys) +{ +/* Adjust for 3.6-4 GB PCI memory range */
Quoted 8 lines
hw/dataplane/vring.c line 30
Quoted 6 lines
hw/dataplane/vring.c new file +6
-0+if (phys >=0x100000000 ) { + phys -=0x100000000 -0xe0000000 ; + }else if (phys >=0xe0000000 ) { +fprintf (stderr,"phys_to_host bad physical address in " +"PCI range %#lx\n" , phys); +exit (1 );Exiting is rather drastic. Is this guest's error or QEMU's?
This can be triggered by the guest - the guest could pass an invalid physical memory address. I agree it's better to have an error state but hw/virtio.c doesn't do this any better today either. I think the safest option is to enter an error state where we ignore the vring until the next (guest-initiated) reset.
Quoted 9 lines
hw/dataplane/vring.c line 206
Quoted 7 lines
hw/dataplane/vring.c new file +7
-0+int vring_pop (VirtIODevice *vdev,Vring *vring, +struct iovec iov[],struct iovec *iov_end, +unsigned int *out_num,unsigned int *in_num) +{ +struct vring_desc desc; +unsigned int i, head, found =0 , num = vring->vr.num; +__u16 avail_idx, last_avail_idx;Please use
uint16_tin QEMU code.
Sure, will convert to QEMU types.
Stefan
Re: [Qemu-devel] [PATCH 7/7] virtio-blk: add x-data-plane=on|off performance feature
In reply to Stefan HajnocziAm 16.11.2012 07:22, schrieb Stefan Hajnoczi:
Quoted 10 lines · Anthony Liguori
Quoted 9 lines
Quoted 6 lines · Stefan Hajnoczi
The virtio-blk-data-plane feature is easy to integrate into
hw/virtio-blk.c. The data plane can be started and stopped similar to vhost-net.Users can take advantage of the virtio-blk-data-plane feature using the new -device virtio-blk-pci,x-data-plane=on property.
Quoted 8 lines
Quoted 2 lines
I don't think this should be a property of virtio-blk-pci but rather a separate device.
The
hw/virtio-blk.ccode still needs to be used sincehw/dataplane/virtio-blk.cis only a subset of virtio-blk.So we're talking about adding a new virtio-blk-data-plane-pci device type to
hw/virtio-pci.c?
A new device sounds wrong to me, it's the very same thing from a guest perspective. Which makes me wonder if in the final version it shouldn't be a -blockdev option rather than a -device one...
Kevin
Re: [Qemu-devel] [PATCH 7/7] virtio-blk: add x-data-plane=on|off performance feature
Il 19/11/2012 11:38, Kevin Wolf ha scritto:
Quoted 17 lines
Am 16.11.2012 07:22, schrieb Stefan Hajnoczi:
Quoted 16 lines · Anthony Liguori
Quoted 11 lines
Quoted 6 lines · Stefan Hajnoczi
The virtio-blk-data-plane feature is easy to integrate into
hw/virtio-blk.c. The data plane can be started and stopped similar to vhost-net.Users can take advantage of the virtio-blk-data-plane feature using the new -device virtio-blk-pci,x-data-plane=on property.
I don't think this should be a property of virtio-blk-pci but rather a separate device.
The
hw/virtio-blk.ccode still needs to be used sincehw/dataplane/virtio-blk.cis only a subset of virtio-blk.
Quoted 6 lines
Quoted 2 lines
So we're talking about adding a new virtio-blk-data-plane-pci device type to
hw/virtio-pci.c?A new device sounds wrong to me, it's the very same thing from a guest perspective. Which makes me wonder if in the final version it shouldn't be a -blockdev option rather than a -device one...
In the final version it shouldn't be an option at all. :)
Paolo
Hello Stefan,
Quoted 22 lines · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.
Quoted 4 lines
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=on
Is this the latest dataplane bits:
(git://github.com/stefanha/qemu.git virtio-blk-data-plane)
commit 7872075c24fa01c925d4f41faa9d04ce69bf5328
Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100
virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Command line I used:
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \
-drive file=/root/img/sid.img,if=ide \
-drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -device virtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \
-L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -m 2048 -smp 4 -cpu qemu64,+x2apic -M pc
Quoted 78 lines
Limitations:
* Only format=raw is supported
* Live migration is not supported
* Block jobs, hot unplug, and other operations fail with-EBUSY
* I/O throttling limits are ignored
* Only Linux hosts are supported due to Linux AIO usageThe code has reached a stage where I feel it is ready to merge. Users have been playing with it for some time and want the significant performance boost.
We are refactoring QEMU to get rid of the global mutex. I believe that virtio-blk-data-plane can eventually become the default mode of operation.
Instead of waiting for global mutex removal efforts to finish, I want to use virtio-blk-data-plane as an example device for AioContext and threaded hw dispatch refactoring. This means:
1. When the block layer can bind to an AioContext and execute I/O outside the global mutex, virtio-blk-data-plane can use this (and gain image format support).
2. When hw dispatch no longer needs the global mutex we can use
hw/virtio.cagain and perhaps run a pool of iothreads instead of dedicated data plane threads.But in the meantime, I have cleaned up the virtio-blk-data-plane code so that it can be merged as an experimental feature.
Changes from the RFC v9:
* Add x-data-plane=on|off option and coexist with regular virtio-blk code
* Create thread from BH so it inherits iothread cpusets
* Drain requests onvm_stop()so stopped guest does not access image file
* Add migration blocker
* Addbdrv_in_use()to prevent block jobs and other operations that can interfere
* Drop IOQueue request merging for simplicity
* Drop ioctl interrupt injection and always use irqfd for simplicity
* Major cleanup to split up source files
* Rebase from qemu-kvm.git onto qemu.git
* Address Michael Tsirkin's review commentsStefan Hajnoczi (7):
raw-posix: addraw_get_aio_fd()for virtio-blk-data-plane
configure: addCONFIG_VIRTIO_BLK_DATA_PLANE
dataplane: add virtqueue vring code
dataplane: add event loop
dataplane: add Linux AIO request queue
dataplane: add virtio-blk data plane code
virtio-blk: add x-data-plane=on|off performance featureblock.h | 9 + block/raw-posix.c | 34 ++++ configure | 21 +++ hw/Makefile.objs | 2 +- hw/dataplane/Makefile.objs | 3 + hw/dataplane/event-poll.c | 109 ++++++++++++ hw/dataplane/event-poll.h | 40 +++++ hw/dataplane/ioq.c | 118 +++++++++++++ hw/dataplane/ioq.h | 57 +++++++ hw/dataplane/virtio-blk.c | 414 +++++++++++++++++++++++++++++++++++++++++++++ hw/dataplane/virtio-blk.h | 41 +++++ hw/dataplane/vring.c | 321 +++++++++++++++++++++++++++++++++++ hw/dataplane/vring.h | 54 ++++++ hw/virtio-blk.c | 59 ++++++- hw/virtio-blk.h | 1 + hw/virtio-pci.c | 3 + trace-events | 9 + 17 files changed, 1293 insertions(+), 2 deletions(-) create mode 100644 hw/dataplane/Makefile.objs create mode 100644 hw/dataplane/event-poll.c create mode 100644 hw/dataplane/event-poll.h create mode 100644 hw/dataplane/ioq.c create mode 100644 hw/dataplane/ioq.h create mode 100644 hw/dataplane/virtio-blk.c create mode 100644 hw/dataplane/virtio-blk.h create mode 100644 hw/dataplane/vring.c create mode 100644 hw/dataplane/vring.h
Signature · 1 line
Asias
Quoted 55 lines · Asias He
Hello Stefan,
Quoted 22 lines · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.Quoted 4 lines
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=onIs this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Command line I used:
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -m
Quoted 1 line
2048 -smp 4 -cpu qemu64,+x2apic -M pc
Was just about to send out the latest patch series which addresses review comments, so I have tested the latest code (61b70fef489ce51ecd18d69afb9622c110b9315c).
I was unable to reproduce a ramdisk performance regression on Linux 3.6.6-3.fc18.x86_64 with Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz with 8 GB RAM.
The ramdisk is 4 GB and I used your QEMU command-line with a RHEL 6.3 guest.
Summary results:
x-data-plane-on: iops=132856 aggrb=1039.1MB/s
x-data-plane-off: iops=126236 aggrb=988.40MB/s
virtio-blk-data-plane is ~5% faster in this benchmark.
fio jobfile:
[global]
filename=/dev/vda
blocksize=8k
ioengine=libaio
direct=1
iodepth=8
runtime=120
time_based=1
[reads]
readwrite=randread
numjobs=4
Perf top (data-plane-on):
3.71% [kvm] [k] kvm_arch_vcpu_ioctl_run 3.27% [kernel] [k] memset <--- ramdisk 2.98% [kernel] [k] do_blockdev_direct_IO 2.82% [kvm_intel] [k] vmx_vcpu_run 2.66% [kernel] [k] _raw_spin_lock_irqsave 2.06% [kernel] [k] put_compound_page 2.06% [kernel] [k] __get_page_tail 1.83% [i915] [k] __gen6_gt_force_wake_mt_get 1.75% [kernel] [k] _raw_spin_unlock_irqrestore 1.33% qemu-system-x86_64 [.] vring_pop <--- virtio-blk-data-plane 1.19% [kernel] [k] compound_unlock_irqrestore 1.13% [kernel] [k] gup_huge_pmd 1.11% [kernel] [k] __audit_syscall_exit 1.07% [kernel] [k] put_page_testzero 1.01% [kernel] [k] fget 1.01% [kernel] [k] do_io_submit
Since the ramdisk (memset and page-related functions) is so prominent in perf top, I also tried a 1-job 8k dd sequential write test on a Samsung 830 Series SSD where virtio-blk-data-plane was 9% faster than virtio-blk. Optimizing against ramdisk isn't a good idea IMO because it acts very differently from real hardware where the driver relies on mmio, DMA, and interrupts (vs synchronous memcpy/memset).
Full results:
$ cat data-plane-off reads: (g=0): rw=randread, bs=8K-8K/8K-8K, ioengine=libaio, iodepth=8 ... reads: (g=0): rw=randread, bs=8K-8K/8K-8K, ioengine=libaio, iodepth=8 fio 1.57 Starting 4 processes
reads: (groupid=0, jobs=1): err= 0: pid=1851
read : io=29408MB, bw=250945KB/s, iops=31368 , runt=120001msec
slat (usec): min=2 , max=27829 , avg=11.06, stdev=78.05
clat (usec): min=1 , max=28028 , avg=241.41, stdev=388.47
lat (usec): min=33 , max=28035 , avg=253.17, stdev=396.66
bw (KB/s) : min=197141, max=335365, per=24.78%, avg=250797.02,
stdev=29376.35
cpu : usr=6.55%, sys=31.34%, ctx=310932, majf=0, minf=41
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued r/w/d: total=3764202/0/0, short=0/0/0
lat (usec): 2=0.01%, 4=0.01%, 20=0.01%, 50=1.78%, 100=27.11%
lat (usec): 250=38.97%, 500=27.11%, 750=2.09%, 1000=0.71%
lat (msec): 2=1.32%, 4=0.70%, 10=0.20%, 20=0.01%, 50=0.01%
reads: (groupid=0, jobs=1): err= 0: pid=1852
read : io=29742MB, bw=253798KB/s, iops=31724 , runt=120001msec
slat (usec): min=2 , max=17007 , avg=10.61, stdev=67.51
clat (usec): min=1 , max=41531 , avg=239.00, stdev=379.03
lat (usec): min=32 , max=41547 , avg=250.33, stdev=385.21
bw (KB/s) : min=194336, max=347497, per=25.02%, avg=253204.25,
stdev=31172.37
cpu : usr=6.66%, sys=32.58%, ctx=327250, majf=0, minf=41
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued r/w/d: total=3806999/0/0, short=0/0/0
lat (usec): 2=0.01%, 20=0.01%, 50=1.54%, 100=26.45%, 250=40.04%
lat (usec): 500=27.15%, 750=1.95%, 1000=0.71%
lat (msec): 2=1.29%, 4=0.68%, 10=0.18%, 20=0.01%, 50=0.01%
reads: (groupid=0, jobs=1): err= 0: pid=1853
read : io=29859MB, bw=254797KB/s, iops=31849 , runt=120001msec
slat (usec): min=2 , max=16821 , avg=11.35, stdev=76.54
clat (usec): min=1 , max=17659 , avg=237.25, stdev=375.31
lat (usec): min=31 , max=17673 , avg=249.27, stdev=383.62
bw (KB/s) : min=194864, max=345280, per=25.15%, avg=254534.63,
stdev=30549.32
cpu : usr=6.52%, sys=31.84%, ctx=303763, majf=0, minf=39
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued r/w/d: total=3821989/0/0, short=0/0/0
lat (usec): 2=0.01%, 10=0.01%, 20=0.01%, 50=2.09%, 100=29.19%
lat (usec): 250=37.31%, 500=26.41%, 750=2.08%, 1000=0.71%
lat (msec): 2=1.32%, 4=0.70%, 10=0.20%, 20=0.01%
reads: (groupid=0, jobs=1): err= 0: pid=1854
read : io=29598MB, bw=252565KB/s, iops=31570 , runt=120001msec
slat (usec): min=2 , max=26413 , avg=11.21, stdev=78.32
clat (usec): min=16 , max=27993 , avg=239.56, stdev=381.67
lat (usec): min=34 , max=28006 , avg=251.49, stdev=390.13
bw (KB/s) : min=194256, max=369424, per=24.94%, avg=252462.86,
stdev=29420.58
cpu : usr=6.57%, sys=31.33%, ctx=305623, majf=0, minf=41
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued r/w/d: total=3788507/0/0, short=0/0/0
lat (usec): 20=0.01%, 50=2.13%, 100=28.30%, 250=37.74%, 500=26.66%
lat (usec): 750=2.17%, 1000=0.75%
lat (msec): 2=1.35%, 4=0.70%, 10=0.19%, 20=0.01%, 50=0.01%Run status group 0 (all jobs):
READ: io=118607MB, aggrb=988.40MB/s, minb=256967KB/s,
maxb=260912KB/s, mint=120001msec, maxt=120001msec
Disk stats (read/write):
vda: ios=15148328/0, merge=0/0, ticks=1550570/0, in_queue=1536232, util=96.56%
$ cat data-plane-on reads: (g=0): rw=randread, bs=8K-8K/8K-8K, ioengine=libaio, iodepth=8 ... reads: (g=0): rw=randread, bs=8K-8K/8K-8K, ioengine=libaio, iodepth=8 fio 1.57 Starting 4 processes
reads: (groupid=0, jobs=1): err= 0: pid=1796
read : io=32081MB, bw=273759KB/s, iops=34219 , runt=120001msec
slat (usec): min=1 , max=20404 , avg=21.08, stdev=125.49
clat (usec): min=10 , max=135743 , avg=207.62, stdev=532.90
lat (usec): min=21 , max=136055 , avg=229.60, stdev=556.82
bw (KB/s) : min=56480, max=951952, per=25.49%, avg=271488.81,
stdev=149773.57
cpu : usr=7.01%, sys=43.26%, ctx=336854, majf=0, minf=41
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued r/w/d: total=4106413/0/0, short=0/0/0
lat (usec): 20=0.01%, 50=2.46%, 100=61.13%, 250=21.58%, 500=3.11%
lat (usec): 750=3.04%, 1000=3.88%
lat (msec): 2=4.50%, 4=0.13%, 10=0.11%, 20=0.06%, 50=0.01%
lat (msec): 250=0.01%
reads: (groupid=0, jobs=1): err= 0: pid=1797
read : io=30104MB, bw=256888KB/s, iops=32110 , runt=120001msec
slat (usec): min=1 , max=17595 , avg=22.20, stdev=120.29
clat (usec): min=13 , max=136264 , avg=221.21, stdev=528.19
lat (usec): min=22 , max=136280 , avg=244.35, stdev=551.73
bw (KB/s) : min=57312, max=838880, per=23.93%, avg=254798.51,
stdev=139546.57
cpu : usr=6.82%, sys=41.87%, ctx=360348, majf=0, minf=41
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued r/w/d: total=3853351/0/0, short=0/0/0
lat (usec): 20=0.01%, 50=2.10%, 100=58.47%, 250=22.38%, 500=3.68%
lat (usec): 750=3.69%, 1000=4.52%
lat (msec): 2=4.87%, 4=0.14%, 10=0.11%, 20=0.05%, 250=0.01%
reads: (groupid=0, jobs=1): err= 0: pid=1798
read : io=31698MB, bw=270487KB/s, iops=33810 , runt=120001msec
slat (usec): min=1 , max=17457 , avg=20.93, stdev=125.33
clat (usec): min=16 , max=134663 , avg=210.19, stdev=535.77
lat (usec): min=21 , max=134671 , avg=232.02, stdev=559.27
bw (KB/s) : min=57248, max=841952, per=25.29%, avg=269330.21,
stdev=148661.08
cpu : usr=6.92%, sys=42.81%, ctx=337799, majf=0, minf=39
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued r/w/d: total=4057340/0/0, short=0/0/0
lat (usec): 20=0.01%, 50=1.98%, 100=62.00%, 250=20.70%, 500=3.22%
lat (usec): 750=3.23%, 1000=4.16%
lat (msec): 2=4.41%, 4=0.13%, 10=0.10%, 20=0.06%, 250=0.01%
reads: (groupid=0, jobs=1): err= 0: pid=1799
read : io=30913MB, bw=263789KB/s, iops=32973 , runt=120000msec
slat (usec): min=1 , max=17565 , avg=21.52, stdev=120.17
clat (usec): min=15 , max=136064 , avg=215.53, stdev=529.56
lat (usec): min=27 , max=136070 , avg=237.99, stdev=552.50
bw (KB/s) : min=57632, max=900896, per=24.74%, avg=263431.57,
stdev=148379.15
cpu : usr=6.90%, sys=42.56%, ctx=348217, majf=0, minf=41
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued r/w/d: total=3956830/0/0, short=0/0/0
lat (usec): 20=0.01%, 50=1.76%, 100=59.96%, 250=22.21%, 500=3.45%
lat (usec): 750=3.35%, 1000=4.33%
lat (msec): 2=4.65%, 4=0.13%, 10=0.11%, 20=0.05%, 250=0.01%Run status group 0 (all jobs):
READ: io=124796MB, aggrb=1039.1MB/s, minb=263053KB/s,
maxb=280328KB/s, mint=120000msec, maxt=120001msec
Disk stats (read/write):
vda: ios=15942789/0, merge=0/0, ticks=336240/0, in_queue=317832, util=97.47%
Quoted 49 lines · Stefan Hajnoczi
Quoted 48 lines · Asias He
Hello Stefan,
Quoted 22 lines · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.Quoted 4 lines
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=onIs this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Command line I used:
Quoted 12 lines
Quoted 8 lines
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -m2048 -smp 4 -cpu qemu64,+x2apic -M pc
Was just about to send out the latest patch series which addresses review comments, so I have tested the latest code (
61b70fef489ce51ecd18d69afb9622c110b9315c).
Rebased onto qemu.git/master before sending out. The commit ID is now:cf6ed6406543ecc43895012a9ac9665e3753d5e8
https://github.com/stefanha/qemu/commits/virtio-blk-data-plane
Stefan
Asias He <[email protected]> wrote on 11/20/2012 03:02:07 AM:
Quoted 8 lines
From: Asias He <[email protected]>
To: Stefan Hajnoczi <[email protected]>,
Cc: [email protected], Anthony Liguori/Austin/IBM@IBMUS, Paolo Bonzini <[email protected]>, Kevin Wolf <[email protected]>, "Michael S. Tsirkin" <[email protected]>, Khoa Huynh/Austin/IBM@IBMUS
Date: 11/20/2012 03:01 AM
Subject: Re: [PATCH 0/7] virtio: virtio-blk data plane
Quoted 4 lines
Hello Stefan,
Quoted 1 line · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property
that
Quoted 10 lines
Quoted 1 line
enables a high performance I/O codepath. A dedicated thread is
used to process
Quoted 1 line
virtio-blk requests outside the global mutex and without going
through the QEMU
Quoted 3 lines
block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000
IOPS to 600,000
Quoted 2 lines
IOPS for a single VM using virtio-blk-data-plane in July:
Quoted 13 lines
Quoted 3 lines
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at
Linux Plumbers
Quoted 3 lines
Conference 2010. The following slides contain a brief overview:
http://linuxplumbersconf.org/2010/ocw/system/presentations/651/
original/Optimizing_the_QEMU_Storage_Stack.pdf
Quoted 5 lines
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer
using
Quoted 2 lines
Quoted 2 lines
Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated
thread.
Quoted 4 lines
Quoted 4 lines
To try it out:
qemu -drive
if=none,id=drive0,cache=none,aio=native,format=raw,file=...
Quoted 10 lines
Quoted 1 line
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=on
Is this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100
Quoted 7 lines
virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Hi Asias, I'll try this latest patchset next week and will report results as soon as they are available. I am currently on vacation this week due to the Thanksgivings holiday in the US.... (Previously, I was able to get up to 1.33 million IOPS for a single KVM guest using Stefan's previous code.)
Thanks,
-Khoa
Quoted 10 lines
Command line I used:
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -m
Quoted 12 lines
2048 -smp 4 -cpu qemu64,+x2apic -M pc
Quoted 9 lines
Limitations:
* Only format=raw is supported
* Live migration is not supported
* Block jobs, hot unplug, and other operations fail with-EBUSY
* I/O throttling limits are ignored
* Only Linux hosts are supported due to Linux AIO usageThe code has reached a stage where I feel it is ready to merge. Users
have
Quoted 5 lines
Quoted 1 line
been playing with it for some time and want the significant
performance boost.
Quoted 3 lines
We are refactoring QEMU to get rid of the global mutex. I believe that virtio-blk-data-plane can eventually become the default mode of
operation.
Quoted 2 lines
Quoted 2 lines
Instead of waiting for global mutex removal efforts to finish, I want
to use
Quoted 1 line
Quoted 1 line
virtio-blk-data-plane as an example device for AioContext and threaded
hw
Quoted 5 lines
Quoted 3 lines
dispatch refactoring. This means:
1. When the block layer can bind to an AioContext and execute I/O
outside the
Quoted 1 line
global mutex, virtio-blk-data-plane can use this (and gain image
format
Quoted 3 lines
Quoted 3 lines
support).
2. When hw dispatch no longer needs the global mutex we can use
hw/virtio.c
Quoted 1 line
Quoted 1 line
again and perhaps run a pool of iothreads instead of dedicated data
plane
Quoted 8 lines
Quoted 3 lines
threads.
But in the meantime, I have cleaned up the virtio-blk-data-plane
code so that
Quoted 4 lines
it can be merged as an experimental feature.
Changes from the RFC v9:
* Add x-data-plane=on|off option and coexist with regular virtio-blk
code
Quoted 2 lines
Quoted 2 lines
* Create thread from BH so it inherits iothread cpusets
* Drain requests onvm_stop()so stopped guest does not access image
file
Quoted 52 lines
Quoted 2 lines
* Add migration blocker
* Addbdrv_in_use()to prevent block jobs and other operationsthat can interfere
Quoted 15 lines
* Drop IOQueue request merging for simplicity
* Drop ioctl interrupt injection and always use irqfd for simplicity
* Major cleanup to split up source files
* Rebase from qemu-kvm.git onto qemu.git
* Address Michael Tsirkin's review commentsStefan Hajnoczi (7):
raw-posix: addraw_get_aio_fd()for virtio-blk-data-plane
configure: addCONFIG_VIRTIO_BLK_DATA_PLANE
dataplane: add virtqueue vring code
dataplane: add event loop
dataplane: add Linux AIO request queue
dataplane: add virtio-blk data plane code
virtio-blk: add x-data-plane=on|off performance featureQuoted 10 lines
block.h | 9 + block/raw-posix.c | 34 ++++ configure | 21 +++ hw/Makefile.objs | 2 +- hw/dataplane/Makefile.objs | 3 + hw/dataplane/event-poll.c | 109 ++++++++++++ hw/dataplane/event-poll.h | 40 +++++ hw/dataplane/ioq.c | 118 +++++++++++++ hw/dataplane/ioq.h | 57 +++++++ hw/dataplane/virtio-blk.c | 414 +++++++++++++++++++++++++++++++++++++++++++++
Quoted 9 lines
hw/dataplane/virtio-blk.h | 41 +++++ hw/dataplane/vring.c | 321 +++++++++++++++++++++++++++++++++++ hw/dataplane/vring.h | 54 ++++++ hw/virtio-blk.c | 59 ++++++- hw/virtio-blk.h | 1 + hw/virtio-pci.c | 3 + trace-events | 9 + 17 files changed, 1293 insertions(+), 2 deletions(-) create mode 100644 hw/dataplane/Makefile.objsQuoted 9 lines
create mode 100644 hw/dataplane/event-poll.c create mode 100644 hw/dataplane/event-poll.h create mode 100644 hw/dataplane/ioq.c create mode 100644 hw/dataplane/ioq.h create mode 100644 hw/dataplane/virtio-blk.c create mode 100644 hw/dataplane/virtio-blk.h create mode 100644 hw/dataplane/vring.c create mode 100644 hw/dataplane/vring.h--
Asias
Quoted 63 lines · Khoa Huynh
Asias He <[email protected]> wrote on 11/20/2012 03:02:07 AM:
Quoted 8 lines
From: Asias He <[email protected]>
To: Stefan Hajnoczi <[email protected]>,
Cc: [email protected], Anthony Liguori/Austin/IBM@IBMUS, Paolo Bonzini <[email protected]>, Kevin Wolf <[email protected]>, "Michael S. Tsirkin" <[email protected]>, Khoa Huynh/Austin/IBM@IBMUS
Date: 11/20/2012 03:01 AM
Subject: Re: [PATCH 0/7] virtio: virtio-blk data planeQuoted 4 lines
Hello Stefan,
Quoted 1 line · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property
that
Quoted 10 lines
Quoted 1 line
enables a high performance I/O codepath. A dedicated thread is
used to process
Quoted 1 line
virtio-blk requests outside the global mutex and without going
through the QEMU
Quoted 3 lines
block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000
IOPS to 600,000
Quoted 2 lines
IOPS for a single VM using virtio-blk-data-plane in July:
Quoted 13 lines
Quoted 3 lines
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at
Linux Plumbers
Quoted 3 lines
Conference 2010. The following slides contain a brief overview:
http://linuxplumbersconf.org/2010/ocw/system/presentations/651/
original/Optimizing_the_QEMU_Storage_Stack.pdf
Quoted 5 lines
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layerusing
Quoted 2 lines
Quoted 2 lines
Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicatedthread.
Quoted 4 lines
Quoted 4 lines
To try it out:
qemu -drive
if=none,id=drive0,cache=none,aio=native,format=raw,file=...
Quoted 16 lines
Quoted 1 line
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=on
Is this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Quoted 7 lines
Quoted 1 line
Any ideas?
Hi Asias, I'll try this latest patchset next week and will report results as soon as they are available. I am currently on vacation this week due to the Thanksgivings holiday in the US.... (Previously, I was able to get up to 1.33 million IOPS for a single KVM guest using Stefan's previous code.)
Hi Khoa, Thanks! Yes, I saw that number in your slides.
Quoted 115 lines
Thanks,
-KhoaQuoted 10 lines
Command line I used:
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -mQuoted 12 lines
2048 -smp 4 -cpu qemu64,+x2apic -M pc
Quoted 9 lines
Limitations:
* Only format=raw is supported
* Live migration is not supported
* Block jobs, hot unplug, and other operations fail with-EBUSY
* I/O throttling limits are ignored
* Only Linux hosts are supported due to Linux AIO usageThe code has reached a stage where I feel it is ready to merge.
Users have
Quoted 5 lines
Quoted 1 line
been playing with it for some time and want the significant
performance boost.
Quoted 3 lines
We are refactoring QEMU to get rid of the global mutex. I believe that virtio-blk-data-plane can eventually become the default mode of
operation.
Quoted 2 lines
Quoted 2 lines
Instead of waiting for global mutex removal efforts to finish, I
want to use
Quoted 1 line
Quoted 1 line
virtio-blk-data-plane as an example device for AioContext and
threaded hw
Quoted 5 lines
Quoted 3 lines
dispatch refactoring. This means:
1. When the block layer can bind to an AioContext and execute I/O
outside the
Quoted 1 line
global mutex, virtio-blk-data-plane can use this (and gain image
format
Quoted 3 lines
Quoted 3 lines
support).
2. When hw dispatch no longer needs the global mutex we can use
hw/virtio.cQuoted 1 line
Quoted 1 line
again and perhaps run a pool of iothreads instead of dedicated
data plane
Quoted 8 lines
Quoted 3 lines
threads.
But in the meantime, I have cleaned up the virtio-blk-data-plane
code so that
Quoted 4 lines
it can be merged as an experimental feature.
Changes from the RFC v9:
* Add x-data-plane=on|off option and coexist with regularvirtio-blk code
Quoted 2 lines
Quoted 2 lines
* Create thread from BH so it inherits iothread cpusets
* Drain requests onvm_stop()so stopped guest does not accessimage file
Quoted 52 lines
Quoted 2 lines
* Add migration blocker
* Addbdrv_in_use()to prevent block jobs and other operationsthat can interfere
Quoted 15 lines
* Drop IOQueue request merging for simplicity
* Drop ioctl interrupt injection and always use irqfd for simplicity
* Major cleanup to split up source files
* Rebase from qemu-kvm.git onto qemu.git
* Address Michael Tsirkin's review commentsStefan Hajnoczi (7):
raw-posix: addraw_get_aio_fd()for virtio-blk-data-plane
configure: addCONFIG_VIRTIO_BLK_DATA_PLANE
dataplane: add virtqueue vring code
dataplane: add event loop
dataplane: add Linux AIO request queue
dataplane: add virtio-blk data plane code
virtio-blk: add x-data-plane=on|off performance featureQuoted 10 lines
block.h | 9 + block/raw-posix.c | 34 ++++ configure | 21 +++ hw/Makefile.objs | 2 +- hw/dataplane/Makefile.objs | 3 + hw/dataplane/event-poll.c | 109 ++++++++++++ hw/dataplane/event-poll.h | 40 +++++ hw/dataplane/ioq.c | 118 +++++++++++++ hw/dataplane/ioq.h | 57 +++++++ hw/dataplane/virtio-blk.c | 414 +++++++++++++++++++++++++++++++++++++++++++++
Quoted 9 lines
hw/dataplane/virtio-blk.h | 41 +++++ hw/dataplane/vring.c | 321 +++++++++++++++++++++++++++++++++++ hw/dataplane/vring.h | 54 ++++++ hw/virtio-blk.c | 59 ++++++- hw/virtio-blk.h | 1 + hw/virtio-pci.c | 3 + trace-events | 9 + 17 files changed, 1293 insertions(+), 2 deletions(-) create mode 100644 hw/dataplane/Makefile.objsQuoted 9 lines
create mode 100644 hw/dataplane/event-poll.c create mode 100644 hw/dataplane/event-poll.h create mode 100644 hw/dataplane/ioq.c create mode 100644 hw/dataplane/ioq.h create mode 100644 hw/dataplane/virtio-blk.c create mode 100644 hw/dataplane/virtio-blk.h create mode 100644 hw/dataplane/vring.c create mode 100644 hw/dataplane/vring.h--
Asias
Signature · 1 line
Asias
Quoted 62 lines · Stefan Hajnoczi
Quoted 55 lines · Asias He
Hello Stefan,
Quoted 22 lines · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.Quoted 4 lines
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=onIs this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Command line I used:
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -mQuoted 1 line
2048 -smp 4 -cpu qemu64,+x2apic -M pc
Was just about to send out the latest patch series which addresses review comments, so I have tested the latest code (
61b70fef489ce51ecd18d69afb9622c110b9315c).
Quoted 3 lines
I was unable to reproduce a ramdisk performance regression on Linux 3.6.6-3.fc18.x86_64 with Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz with 8 GB RAM.
I am using the latest upstream kernel.
Quoted 40 lines
The ramdisk is 4 GB and I used your QEMU command-line with a RHEL 6.3 guest.
Summary results:
x-data-plane-on: iops=132856 aggrb=1039.1MB/s
x-data-plane-off: iops=126236 aggrb=988.40MB/svirtio-blk-data-plane is ~5% faster in this benchmark.
fio jobfile:
[global]
filename=/dev/vda
blocksize=8k
ioengine=libaio
direct=1
iodepth=8
runtime=120
time_based=1[reads]
readwrite=randread
numjobs=4Perf top (data-plane-on):
3.71% [kvm] [k] kvm_arch_vcpu_ioctl_run 3.27% [kernel] [k] memset <--- ramdisk 2.98% [kernel] [k] do_blockdev_direct_IO 2.82% [kvm_intel] [k] vmx_vcpu_run 2.66% [kernel] [k] _raw_spin_lock_irqsave 2.06% [kernel] [k] put_compound_page 2.06% [kernel] [k] __get_page_tail 1.83% [i915] [k] __gen6_gt_force_wake_mt_get 1.75% [kernel] [k] _raw_spin_unlock_irqrestore 1.33% qemu-system-x86_64 [.] vring_pop <--- virtio-blk-data-plane 1.19% [kernel] [k] compound_unlock_irqrestore 1.13% [kernel] [k] gup_huge_pmd 1.11% [kernel] [k] __audit_syscall_exit 1.07% [kernel] [k] put_page_testzero 1.01% [kernel] [k] fget 1.01% [kernel] [k] do_io_submit
Quoted 6 lines
Since the ramdisk (memset and page-related functions) is so prominent in perf top, I also tried a 1-job 8k dd sequential write test on a Samsung 830 Series SSD where virtio-blk-data-plane was 9% faster than virtio-blk. Optimizing against ramdisk isn't a good idea IMO because it acts very differently from real hardware where the driver relies on mmio, DMA, and interrupts (vs synchronous memcpy/memset).
For the memset in ramdisk, you can simply patch drivers/block/brd.c to do nop instead of memset for testing.
Yes, if you have fast SSD device (sometimes you need multiple which I do not have), it makes more sense to test on real hardware. However, ramdisk test is still useful. It gives rough performance numbers. If A and B are both tested against ramdisk. The difference between A and B are still useful.
Quoted 152 lines
Full results:
$ cat data-plane-off reads: (g=0): rw=randread, bs=8K-8K/8K-8K, ioengine=libaio, iodepth=8 ... reads: (g=0): rw=randread, bs=8K-8K/8K-8K, ioengine=libaio, iodepth=8 fio 1.57 Starting 4 processesreads: (groupid=0, jobs=1): err= 0: pid=1851
read : io=29408MB, bw=250945KB/s, iops=31368 , runt=120001msecslat (usec): min=2 , max=27829 , avg=11.06, stdev=78.05 clat (usec): min=1 , max=28028 , avg=241.41, stdev=388.47 lat (usec): min=33 , max=28035 , avg=253.17, stdev=396.66 bw (KB/s) : min=197141, max=335365, per=24.78%, avg=250797.02, stdev=29376.35 cpu : usr=6.55%, sys=31.34%, ctx=310932, majf=0, minf=41 IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued r/w/d: total=3764202/0/0, short=0/0/0 lat (usec): 2=0.01%, 4=0.01%, 20=0.01%, 50=1.78%, 100=27.11% lat (usec): 250=38.97%, 500=27.11%, 750=2.09%, 1000=0.71% lat (msec): 2=1.32%, 4=0.70%, 10=0.20%, 20=0.01%, 50=0.01% reads: (groupid=0, jobs=1): err= 0: pid=1852 read : io=29742MB, bw=253798KB/s, iops=31724 , runt=120001msec slat (usec): min=2 , max=17007 , avg=10.61, stdev=67.51 clat (usec): min=1 , max=41531 , avg=239.00, stdev=379.03 lat (usec): min=32 , max=41547 , avg=250.33, stdev=385.21 bw (KB/s) : min=194336, max=347497, per=25.02%, avg=253204.25, stdev=31172.37 cpu : usr=6.66%, sys=32.58%, ctx=327250, majf=0, minf=41 IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued r/w/d: total=3806999/0/0, short=0/0/0 lat (usec): 2=0.01%, 20=0.01%, 50=1.54%, 100=26.45%, 250=40.04% lat (usec): 500=27.15%, 750=1.95%, 1000=0.71% lat (msec): 2=1.29%, 4=0.68%, 10=0.18%, 20=0.01%, 50=0.01% reads: (groupid=0, jobs=1): err= 0: pid=1853 read : io=29859MB, bw=254797KB/s, iops=31849 , runt=120001msec slat (usec): min=2 , max=16821 , avg=11.35, stdev=76.54 clat (usec): min=1 , max=17659 , avg=237.25, stdev=375.31 lat (usec): min=31 , max=17673 , avg=249.27, stdev=383.62 bw (KB/s) : min=194864, max=345280, per=25.15%, avg=254534.63, stdev=30549.32 cpu : usr=6.52%, sys=31.84%, ctx=303763, majf=0, minf=39 IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued r/w/d: total=3821989/0/0, short=0/0/0 lat (usec): 2=0.01%, 10=0.01%, 20=0.01%, 50=2.09%, 100=29.19% lat (usec): 250=37.31%, 500=26.41%, 750=2.08%, 1000=0.71% lat (msec): 2=1.32%, 4=0.70%, 10=0.20%, 20=0.01% reads: (groupid=0, jobs=1): err= 0: pid=1854 read : io=29598MB, bw=252565KB/s, iops=31570 , runt=120001msec slat (usec): min=2 , max=26413 , avg=11.21, stdev=78.32 clat (usec): min=16 , max=27993 , avg=239.56, stdev=381.67 lat (usec): min=34 , max=28006 , avg=251.49, stdev=390.13 bw (KB/s) : min=194256, max=369424, per=24.94%, avg=252462.86, stdev=29420.58 cpu : usr=6.57%, sys=31.33%, ctx=305623, majf=0, minf=41 IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued r/w/d: total=3788507/0/0, short=0/0/0 lat (usec): 20=0.01%, 50=2.13%, 100=28.30%, 250=37.74%, 500=26.66% lat (usec): 750=2.17%, 1000=0.75% lat (msec): 2=1.35%, 4=0.70%, 10=0.19%, 20=0.01%, 50=0.01%Run status group 0 (all jobs):
READ: io=118607MB, aggrb=988.40MB/s, minb=256967KB/s,maxb=260912KB/s, mint=120001msec, maxt=120001msec
Disk stats (read/write):
vda: ios=15148328/0, merge=0/0, ticks=1550570/0, in_queue=1536232, util=96.56%$ cat data-plane-on reads: (g=0): rw=randread, bs=8K-8K/8K-8K, ioengine=libaio, iodepth=8 ... reads: (g=0): rw=randread, bs=8K-8K/8K-8K, ioengine=libaio, iodepth=8 fio 1.57 Starting 4 processesreads: (groupid=0, jobs=1): err= 0: pid=1796
read : io=32081MB, bw=273759KB/s, iops=34219 , runt=120001msecslat (usec): min=1 , max=20404 , avg=21.08, stdev=125.49 clat (usec): min=10 , max=135743 , avg=207.62, stdev=532.90 lat (usec): min=21 , max=136055 , avg=229.60, stdev=556.82 bw (KB/s) : min=56480, max=951952, per=25.49%, avg=271488.81, stdev=149773.57 cpu : usr=7.01%, sys=43.26%, ctx=336854, majf=0, minf=41 IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued r/w/d: total=4106413/0/0, short=0/0/0 lat (usec): 20=0.01%, 50=2.46%, 100=61.13%, 250=21.58%, 500=3.11% lat (usec): 750=3.04%, 1000=3.88% lat (msec): 2=4.50%, 4=0.13%, 10=0.11%, 20=0.06%, 50=0.01% lat (msec): 250=0.01% reads: (groupid=0, jobs=1): err= 0: pid=1797 read : io=30104MB, bw=256888KB/s, iops=32110 , runt=120001msec slat (usec): min=1 , max=17595 , avg=22.20, stdev=120.29 clat (usec): min=13 , max=136264 , avg=221.21, stdev=528.19 lat (usec): min=22 , max=136280 , avg=244.35, stdev=551.73 bw (KB/s) : min=57312, max=838880, per=23.93%, avg=254798.51, stdev=139546.57 cpu : usr=6.82%, sys=41.87%, ctx=360348, majf=0, minf=41 IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued r/w/d: total=3853351/0/0, short=0/0/0 lat (usec): 20=0.01%, 50=2.10%, 100=58.47%, 250=22.38%, 500=3.68% lat (usec): 750=3.69%, 1000=4.52% lat (msec): 2=4.87%, 4=0.14%, 10=0.11%, 20=0.05%, 250=0.01% reads: (groupid=0, jobs=1): err= 0: pid=1798 read : io=31698MB, bw=270487KB/s, iops=33810 , runt=120001msec slat (usec): min=1 , max=17457 , avg=20.93, stdev=125.33 clat (usec): min=16 , max=134663 , avg=210.19, stdev=535.77 lat (usec): min=21 , max=134671 , avg=232.02, stdev=559.27 bw (KB/s) : min=57248, max=841952, per=25.29%, avg=269330.21, stdev=148661.08 cpu : usr=6.92%, sys=42.81%, ctx=337799, majf=0, minf=39 IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued r/w/d: total=4057340/0/0, short=0/0/0 lat (usec): 20=0.01%, 50=1.98%, 100=62.00%, 250=20.70%, 500=3.22% lat (usec): 750=3.23%, 1000=4.16% lat (msec): 2=4.41%, 4=0.13%, 10=0.10%, 20=0.06%, 250=0.01% reads: (groupid=0, jobs=1): err= 0: pid=1799 read : io=30913MB, bw=263789KB/s, iops=32973 , runt=120000msec slat (usec): min=1 , max=17565 , avg=21.52, stdev=120.17 clat (usec): min=15 , max=136064 , avg=215.53, stdev=529.56 lat (usec): min=27 , max=136070 , avg=237.99, stdev=552.50 bw (KB/s) : min=57632, max=900896, per=24.74%, avg=263431.57, stdev=148379.15 cpu : usr=6.90%, sys=42.56%, ctx=348217, majf=0, minf=41 IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=100.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued r/w/d: total=3956830/0/0, short=0/0/0 lat (usec): 20=0.01%, 50=1.76%, 100=59.96%, 250=22.21%, 500=3.45% lat (usec): 750=3.35%, 1000=4.33% lat (msec): 2=4.65%, 4=0.13%, 10=0.11%, 20=0.05%, 250=0.01%Run status group 0 (all jobs):
READ: io=124796MB, aggrb=1039.1MB/s, minb=263053KB/s,maxb=280328KB/s, mint=120000msec, maxt=120001msec
Disk stats (read/write):
vda: ios=15942789/0, merge=0/0, ticks=336240/0, in_queue=317832, util=97.47%
Signature · 1 line
Asias
Quoted 63 lines · Stefan Hajnoczi
Quoted 49 lines · Stefan Hajnoczi
Quoted 48 lines · Asias He
Hello Stefan,
Quoted 22 lines · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.Quoted 4 lines
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=onIs this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Command line I used:
Quoted 12 lines
Quoted 8 lines
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -m2048 -smp 4 -cpu qemu64,+x2apic -M pc
Was just about to send out the latest patch series which addresses review comments, so I have tested the latest code (
61b70fef489ce51ecd18d69afb9622c110b9315c).
Quoted 6 lines
Rebased onto qemu.git/master before sending out. The commit ID is now:
cf6ed6406543ecc43895012a9ac9665e3753d5e8https://github.com/stefanha/qemu/commits/virtio-blk-data-plane
Stefan
Ok, thanks. /me trying
Signature · 1 line
Asias
Quoted 64 lines · Asias He
Quoted 63 lines · Stefan Hajnoczi
Quoted 61 lines · Stefan Hajnoczi
Quoted 55 lines · Asias He
Hello Stefan,
Quoted 22 lines · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.Quoted 4 lines
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=onIs this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Command line I used:
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -mQuoted 1 line
2048 -smp 4 -cpu qemu64,+x2apic -M pc
Was just about to send out the latest patch series which addresses review comments, so I have tested the latest code (
61b70fef489ce51ecd18d69afb9622c110b9315c).
Quoted 8 lines
Quoted 6 lines
Rebased onto qemu.git/master before sending out. The commit ID is now:
cf6ed6406543ecc43895012a9ac9665e3753d5e8https://github.com/stefanha/qemu/commits/virtio-blk-data-plane
Stefan
Ok, thanks. /me trying
Hi Stefan,
If I enable the merge in guest the IOPS for seq read/write goes up to ~400K/300K. If I disable the merge in guest the IOPS drops to ~17K/24K for seq read/write (which is similar to the result I posted yesterday, with merge disalbed). Could you please also share the numbers for rand read and write in your setup?
1.(With merge enabled in guest + dataplane on)
echo noop > /sys/block/vda/queue/scheduler
echo 0 > /sys/block/vda/queue/nomerges
-------------------------------------
read : io=0 B, bw=1575.2MB/s, iops=403453 , runt= 10396msec
write: io=0 B, bw=1224.1MB/s, iops=313592 , runt= 13375msec read : io=0 B, bw=99534KB/s, iops=24883 , runt=168558msec
write: io=0 B, bw=197695KB/s, iops=49423 , runt= 84864msec
clat (usec): min=102 , max=395042 , avg=2167.18, stdev=4307.91
clat (usec): min=89 , max=636874 , avg=2728.93, stdev=6777.71
clat (usec): min=285 , max=4737.1K, avg=39939.42, stdev=87137.41
clat (usec): min=74 , max=1408.1K, avg=18575.50, stdev=47752.13
cpu : usr=79.16%, sys=261.43%, ctx=1837824, majf=0, minf=58
cpu : usr=73.61%, sys=251.80%, ctx=1585892, majf=0, minf=7
cpu : usr=17.03%, sys=71.03%, ctx=6427788, majf=0, minf=6
cpu : usr=25.51%, sys=88.46%, ctx=5117624, majf=0, minf=1 vda: ios=5037311/5303500, merge=3351489/3084584,
ticks=30674372/15110818, in_queue=45816533, util=97.50%
41: 40099 40163 40110 40157 PCI-MSI-edge
virtio0-requests
41: interrupt in total: 160529
fio --exec_prerun="echo 3 > /proc/sys/vm/drop_caches" --group_reporting --ioscheduler=noop --thread --bs=4k --size=512MB --direct=1 --numjobs=16 --ioengine=libaio --iodepth=64 --loops=3 --ramp_time=0 --filename=/dev/vda --name=seq-read --stonewall --rw=read --name=seq-write --stonewall --rw=write --name=rnd-read --stonewall --rw=randread --name=rnd-write --stonewall --rw=randwrite
2.(With merge diabled in guest + dataplane on) echo noop > /sys/block/vda/queue/scheduler
echo 2 > /sys/block/vda/queue/nomerges
-------------------------------------
read : io=0 B, bw=69185KB/s, iops=17296 , runt=242497msec
write: io=0 B, bw=96219KB/s, iops=24054 , runt=174365msec read : io=0 B, bw=90866KB/s, iops=22716 , runt=184637msec
write: io=0 B, bw=202018KB/s, iops=50504 , runt= 83048msec
clat (usec): min=98 , max=1719.7K, avg=57623.32, stdev=84730.86
clat (usec): min=0 , max=1372.8K, avg=41286.47, stdev=73252.45
clat (usec): min=82 , max=1308.8K, avg=43828.82, stdev=73483.73
clat (usec): min=0 , max=1239.6K, avg=18445.77, stdev=49099.15
cpu : usr=10.12%, sys=72.64%, ctx=7942850, majf=0, minf=62
cpu : usr=14.72%, sys=78.99%, ctx=7358973, majf=0, minf=3
cpu : usr=16.34%, sys=72.60%, ctx=7394674, majf=0, minf=5
cpu : usr=29.69%, sys=83.41%, ctx=5262809, majf=0, minf=4 vda: ios=8389288/8388552, merge=0/0, ticks=76013872/44425860,
in_queue=120493774, util=99.58%
41: 89414 89456 89504 89534 PCI-MSI-edge
virtio0-requests
41: interrupt in total: 357908
fio --exec_prerun="echo 3 > /proc/sys/vm/drop_caches" --group_reporting --ioscheduler=noop --thread --bs=4k --size=512MB --direct=1 --numjobs=16 --ioengine=libaio --iodepth=64 --loops=3 --ramp_time=0 --filename=/dev/vda --name=seq-read --stonewall --rw=read --name=seq-write --stonewall --rw=write --name=rnd-read --stonewall --rw=randread --name=rnd-write --stonewall --rw=randwrite
3.(With merge enabled in guest + dataplane off)
-------------------------------------
read : io=0 B, bw=810220KB/s, iops=202554 , runt= 20707msec
write: io=0 B, bw=999.97MB/s, iops=255984 , runt= 16385msec read : io=0 B, bw=338066KB/s, iops=84516 , runt= 49627msec
write: io=0 B, bw=455420KB/s, iops=113854 , runt= 36839msec
clat (usec): min=0 , max=26340 , avg=5019.36, stdev=2185.04
clat (usec): min=58 , max=21572 , avg=3972.33, stdev=1708.00
clat (usec): min=34 , max=90185 , avg=11879.72, stdev=8054.58
clat (usec): min=189 , max=122825 , avg=8822.87, stdev=4608.65
cpu : usr=44.89%, sys=141.08%, ctx=1611401, majf=0, minf=54
cpu : usr=58.46%, sys=177.50%, ctx=1582260, majf=0, minf=0
cpu : usr=21.09%, sys=63.61%, ctx=7609871, majf=0, minf=2
cpu : usr=28.88%, sys=73.51%, ctx=8140689, majf=0, minf=10 vda: ios=5222932/5209798, merge=3164880/3163834,
ticks=10133305/7618081, in_queue=17773509, util=99.46%
41: 286378 284870 285478 285759 PCI-MSI-edge
virtio0-requests
41: interrupt in total: 1142485
fio --exec_prerun="echo 3 > /proc/sys/vm/drop_caches" --group_reporting --ioscheduler=noop --thread --bs=4k --size=512MB --direct=1 --numjobs=16 --ioengine=libaio --iodepth=64 --loops=3 --ramp_time=0 --filename=/dev/vda --name=seq-read --stonewall --rw=read --name=seq-write --stonewall --rw=write --name=rnd-read --stonewall --rw=randread --name=rnd-write --stonewall --rw=randwrite
4.(With merge disabled in guest + dataplane off)
-------------------------------------
read : io=0 B, bw=331147KB/s, iops=82786 , runt= 50664msec
write: io=0 B, bw=431802KB/s, iops=107950 , runt= 38854msec read : io=0 B, bw=376424KB/s, iops=94105 , runt= 44570msec
write: io=0 B, bw=373200KB/s, iops=93300 , runt= 44955msec
clat (usec): min=84 , max=99635 , avg=12075.27, stdev=7899.12
clat (usec): min=97 , max=84882 , avg=9289.49, stdev=5688.96
clat (usec): min=56 , max=76176 , avg=10662.84, stdev=6375.63
clat (usec): min=158 , max=112216 , avg=10762.62, stdev=6412.89
cpu : usr=15.16%, sys=59.67%, ctx=8007217, majf=0, minf=62
cpu : usr=26.45%, sys=99.42%, ctx=7477108, majf=0, minf=8
cpu : usr=29.52%, sys=85.40%, ctx=7889672, majf=0, minf=2
cpu : usr=30.71%, sys=86.54%, ctx=7893782, majf=0, minf=2 vda: ios=8389195/8374171, merge=0/0, ticks=15202863/12550941,
in_queue=27840167, util=99.63%
41: 179902 179182 179232 179539 PCI-MSI-edge
virtio0-requests
41: interrupt in total: 717855
fio --exec_prerun="echo 3 > /proc/sys/vm/drop_caches" --group_reporting --ioscheduler=noop --thread --bs=4k --size=512MB --direct=1 --numjobs=16 --ioengine=libaio --iodepth=64 --loops=3 --ramp_time=0 --filename=/dev/vda --name=seq-read --stonewall --rw=read --name=seq-write --stonewall --rw=write --name=rnd-read --stonewall --rw=randread --name=rnd-write --stonewall --rw=randwrite
Signature · 1 line
Asias
Quoted 74 lines · Asias He
Quoted 64 lines · Asias He
Quoted 63 lines · Stefan Hajnoczi
Quoted 61 lines · Stefan Hajnoczi
Quoted 55 lines · Asias He
Hello Stefan,
Quoted 22 lines · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.Quoted 4 lines
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=onIs this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Command line I used:
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -mQuoted 1 line
2048 -smp 4 -cpu qemu64,+x2apic -M pc
Was just about to send out the latest patch series which addresses review comments, so I have tested the latest code (
61b70fef489ce51ecd18d69afb9622c110b9315c).Quoted 8 lines
Quoted 6 lines
Rebased onto qemu.git/master before sending out. The commit ID is now:
cf6ed6406543ecc43895012a9ac9665e3753d5e8https://github.com/stefanha/qemu/commits/virtio-blk-data-plane
Stefan
Ok, thanks. /me trying
Quoted 7 lines
Hi Stefan,
If I enable the merge in guest the IOPS for seq read/write goes up to ~400K/300K. If I disable the merge in guest the IOPS drops to ~17K/24K for seq read/write (which is similar to the result I posted yesterday, with merge disalbed). Could you please also share the numbers for rand read and write in your setup?
Thanks for running the test. Please send your rand read/write fio jobfile so I can run the exact same test.
BTW I was running the default F18 (host) and RHEL 6.3 (guest) I/O schedulers in my test yesterday.
Stefan
Quoted 83 lines · Stefan Hajnoczi
Quoted 74 lines · Asias He
Quoted 64 lines · Asias He
Quoted 63 lines · Stefan Hajnoczi
Quoted 61 lines · Stefan Hajnoczi
Quoted 55 lines · Asias He
Hello Stefan,
Quoted 22 lines · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.Quoted 4 lines
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=onIs this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Command line I used:
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -mQuoted 1 line
2048 -smp 4 -cpu qemu64,+x2apic -M pc
Was just about to send out the latest patch series which addresses review comments, so I have tested the latest code (
61b70fef489ce51ecd18d69afb9622c110b9315c).Quoted 8 lines
Quoted 6 lines
Rebased onto qemu.git/master before sending out. The commit ID is now:
cf6ed6406543ecc43895012a9ac9665e3753d5e8https://github.com/stefanha/qemu/commits/virtio-blk-data-plane
Stefan
Ok, thanks. /me trying
Quoted 7 lines
Hi Stefan,
If I enable the merge in guest the IOPS for seq read/write goes up to ~400K/300K. If I disable the merge in guest the IOPS drops to ~17K/24K for seq read/write (which is similar to the result I posted yesterday, with merge disalbed). Could you please also share the numbers for rand read and write in your setup?
Quoted 5 lines
Thanks for running the test. Please send your rand read/write fio jobfile so I can run the exact same test.
BTW I was running the default F18 (host) and RHEL 6.3 (guest) I/O schedulers in my test yesterday.
Sure, this is the script I used to run the test in guest.
# cat run.sh #!/bin/sh
cat > all.fio <<EOF
[global]
exec_prerun="echo 3 > /proc/sys/vm/drop_caches"group_reporting
ioscheduler=noop
thread
bs=4k
size=512MB
direct=1
filename=/dev/vda
numjobs=16
ioengine=libaio
iodepth=64
loops=3
ramp_time=0
[seq-read]
stonewall
rw=read
[seq-write]
stonewall
rw=write
[rnd-read]
stonewall
rw=randread
[rnd-write]
stonewall
rw=randwrite
EOF
echo noop > /sys/block/vda/queue/scheduler
echo 2 > /sys/block/vda/queue/nomerges
echo 0 > /sys/block/vda/queue/nomerges
fio all.fio --output=f.log
echo
echo -------------------------------------
cat f.log|grep iops cat f.log|grep clat |grep avg cat f.log|grep cpu cat f.log|grep ios |grep in_queue
cat /proc/interrupts |grep requests |grep virtio |grep 41\:
cat /proc/stat |grep ^intr | awk '{print " 41: interrupt in total: "$44}' fio all.fio --showcmd
Signature · 1 line
Asias
Quoted 84 lines · Asias He
Quoted 83 lines · Stefan Hajnoczi
Quoted 81 lines · Asias He
Quoted 64 lines · Asias He
Quoted 63 lines · Stefan Hajnoczi
Quoted 61 lines · Stefan Hajnoczi
Quoted 55 lines · Asias He
Hello Stefan,
Quoted 22 lines · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.Quoted 4 lines
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=onIs this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Command line I used:
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -mQuoted 1 line
2048 -smp 4 -cpu qemu64,+x2apic -M pc
Was just about to send out the latest patch series which addresses review comments, so I have tested the latest code (
61b70fef489ce51ecd18d69afb9622c110b9315c).Quoted 8 lines
Quoted 6 lines
Rebased onto qemu.git/master before sending out. The commit ID is now:
cf6ed6406543ecc43895012a9ac9665e3753d5e8https://github.com/stefanha/qemu/commits/virtio-blk-data-plane
Stefan
Ok, thanks. /me trying
Hi Stefan,
If I enable the merge in guest the IOPS for seq read/write goes up to ~400K/300K. If I disable the merge in guest the IOPS drops to ~17K/24K for seq read/write (which is similar to the result I posted yesterday, with merge disalbed). Could you please also share the numbers for rand read and write in your setup?
Quoted 7 lines
Quoted 5 lines
Thanks for running the test. Please send your rand read/write fio jobfile so I can run the exact same test.
BTW I was running the default F18 (host) and RHEL 6.3 (guest) I/O schedulers in my test yesterday.
Sure, this is the script I used to run the test in guest.
Thanks, will give this a try!
Stefan
Quoted 116 lines · Asias He
Quoted 62 lines · Stefan Hajnoczi
Quoted 55 lines · Asias He
Hello Stefan,
Quoted 22 lines · Stefan Hajnoczi
This series adds the -device virtio-blk-pci,x-data-plane=on property that enables a high performance I/O codepath. A dedicated thread is used to process virtio-blk requests outside the global mutex and without going through the QEMU block layer.
Khoa Huynh <[email protected]> reported an increase from 140,000 IOPS to 600,000 IOPS for a single VM using virtio-blk-data-plane in July:
http://comments.gmane.org/gmane.comp.emulators.kvm.devel/94580
The virtio-blk-data-plane approach was originally presented at Linux Plumbers Conference 2010. The following slides contain a brief overview:
The basic approach is:
1. Each virtio-blk device has a thread dedicated to handling ioeventfd signalling when the guest kicks the virtqueue.
2. Requests are processed without going through the QEMU block layer using Linux AIO directly.
3. Completion interrupts are injected via irqfd from the dedicated thread.Quoted 4 lines
To try it out:
qemu -drive if=none,id=drive0,cache=none,aio=native,format=raw,file=...
-device virtio-blk-pci,drive=drive0,scsi=off,x-data-plane=onIs this the latest dataplane bits:
(git://github.com/stefanha/qemu.gitvirtio-blk-data-plane)commit
7872075c24fa01c925d4f41faa9d04ce69bf5328Author: Stefan Hajnoczi <[email protected]> Date: Wed Nov 14 15:45:38 2012 +0100virtio-blk: add x-data-plane=on|off performance feature
With this commit on a ramdisk based box, I am seeing about 10K IOPS with x-data-plane on and 90K IOPS with x-data-plane off.
Any ideas?
Command line I used:
IMG=/dev/ram0
x86_64-softmmu/qemu-system-x86_64 \(quoted diff) +0
-2-drive file=/root/img/sid.img,if=ide \ -drive file=${IMG},if=none,cache=none,aio=native,id=disk1 -devicevirtio-blk-pci,x-data-plane=off,drive=disk1,scsi=off \
(quoted diff) +0
-2-kernel $KERNEL -append "root=/dev/sdb1 console=tty0" \ -L /tmp/qemu-dataplane/share/qemu/ -nographic -vnc :0 -enable-kvm -mQuoted 1 line
2048 -smp 4 -cpu qemu64,+x2apic -M pc
Was just about to send out the latest patch series which addresses review comments, so I have tested the latest code (
61b70fef489ce51ecd18d69afb9622c110b9315c).Quoted 3 lines
I was unable to reproduce a ramdisk performance regression on Linux 3.6.6-3.fc18.x86_64 with Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz with 8 GB RAM.
I am using the latest upstream kernel.
Quoted 40 lines
The ramdisk is 4 GB and I used your QEMU command-line with a RHEL 6.3 guest.
Summary results:
x-data-plane-on: iops=132856 aggrb=1039.1MB/s
x-data-plane-off: iops=126236 aggrb=988.40MB/svirtio-blk-data-plane is ~5% faster in this benchmark.
fio jobfile:
[global]
filename=/dev/vda
blocksize=8k
ioengine=libaio
direct=1
iodepth=8
runtime=120
time_based=1[reads]
readwrite=randread
numjobs=4Perf top (data-plane-on):
3.71% [kvm] [k] kvm_arch_vcpu_ioctl_run 3.27% [kernel] [k] memset <--- ramdisk 2.98% [kernel] [k] do_blockdev_direct_IO 2.82% [kvm_intel] [k] vmx_vcpu_run 2.66% [kernel] [k] _raw_spin_lock_irqsave 2.06% [kernel] [k] put_compound_page 2.06% [kernel] [k] __get_page_tail 1.83% [i915] [k] __gen6_gt_force_wake_mt_get 1.75% [kernel] [k] _raw_spin_unlock_irqrestore 1.33% qemu-system-x86_64 [.] vring_pop <--- virtio-blk-data-plane 1.19% [kernel] [k] compound_unlock_irqrestore 1.13% [kernel] [k] gup_huge_pmd 1.11% [kernel] [k] __audit_syscall_exit 1.07% [kernel] [k] put_page_testzero 1.01% [kernel] [k] fget 1.01% [kernel] [k] do_io_submitQuoted 6 lines
Since the ramdisk (memset and page-related functions) is so prominent in perf top, I also tried a 1-job 8k dd sequential write test on a Samsung 830 Series SSD where virtio-blk-data-plane was 9% faster than virtio-blk. Optimizing against ramdisk isn't a good idea IMO because it acts very differently from real hardware where the driver relies on mmio, DMA, and interrupts (vs synchronous memcpy/memset).
Quoted 8 lines
For the memset in ramdisk, you can simply patch
drivers/block/brd.cto do nop instead of memset for testing.Yes, if you have fast SSD device (sometimes you need multiple which I do not have), it makes more sense to test on real hardware. However, ramdisk test is still useful. It gives rough performance numbers. If A and B are both tested against ramdisk. The difference between A and B are still useful.
Optimizing the difference between A and B on ramdisk is only guaranteed to optimize the ramdisk case. On real hardware the bottleneck might be elsewhere and we'd be chasing the wrong lead.
I don't think it's a waste of time but I think to stay healthy we need to focus on real disks and SSDs most of the time.
Stefan