Commit Graph
67 Commits
Author SHA1 Message Date
Asias He a67da3beff kvm tools: Add initial virtio-scsi support
This patch brings virito-scsi support to kvm tool.

With the introduce of tcm_vhost (vhost-scsi)

   tcm_vhost: Initial merge for vhost level target fabric driver

we can implement virito-scsi by simply having vhost-scsi to handle the
SCSI command.

Howto use:
1) Setup the tcm_vhost target through /sys/kernel/config

   [Stefan Hajnoczi, Thanks for the script to setup tcm_vhost]

   ** Setup wwpn and tpgt
   $ wwpn="naa.0"
   $ tpgt=/sys/kernel/config/target/vhost/$wwpn/tpgt_0
   $ nexus=$tpgt/nexus
   $ mkdir -p $tpgt
   $ echo -n $wwpn > $nexus

   ** Setup lun using /dev/ram
   $ n=0
   $ lun=$tpgt/lun/lun_${n}
   $ data=/sys/kernel/config/target/core/iblock_0/data_${n}
   $ ram=/dev/ram${n}
   $ mkdir -p $lun
   $ mkdir -p $data
   $ echo -n udev_path=${ram} > $data/control
   $ echo -n 1 > $data/enable
   $ ln -s $data $lun

2) Run kvm tool with the new disk option '-d scsi:$wwpn:$tpgt', e.g
   $ lkvm run -k /boot/bzImage -d ~/img/sid.img -d scsi:naa.0:0

Signed-off-by: Asias He <asias.hejun@gmail.com>
Cc: Nicholas A. Bellinger <nab@linux-iscsi.org>
Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 5236b50516 kvm tools: Enable O_DIRECT support
With Direct I/O, file reads and writes go directly from the applications
to the storage device, bypassing the operating system read and write
caches. This is useful for applications that manage their own caches.

Open a disk image with O_DIRECT:
   $ lkvm run -d ~/img/test.img,direct

The original readonly flag is still supported.
Open a disk image with O_DIRECT and readonly:
   $ lkvm run -d ~/img/test.img,direct,ro

Signed-off-by: Asias He <asias.hejun@gmail.com>
Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 97f16d6688 kvm tools: Introduce struct disk_image_params
Introduce struct disk_image_params to contain all the disk image parameters.
This is useful for adding more disk image parameters, e.g. disk image
cache mode.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He fea74936f1 kvm tools: Increase AIO_MAX to 256
The queue size for virtio_blk is 256 and AIO_MAX is 32, we might be
short of available aio events if guest issues > 32 requests
simultaneously. Following error is observed when guest running stressed
I/O workload.

  Info: disk_image__read error: total=-11

To fix this, let's increase the aio events limit.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He b7c2f3bc49 kvm tools: Code cleanup for disk/raw.c
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 449ca0aefe kvm tools: Code cleanup for disk/qcow.c
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 54c84566ec kvm tools: Code cleanup for disk/core.c
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He dcd3cd8e4e kvm tools: Simplify disk read write function name
We read and write in sectors by default. It makes little sense to add
the extra _sector string for read and write ops/function name.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Asias He 58fd2b7b27 kvm tools: Make raw block device work
Previously, we use mmaped host root partition as guest's root
filesystem. As virtio-9p based root filesystem is supported,
mmaped host root partition approach is not used anymore.

It is useful to use raw block device as guest's disk backend for some
user. e.g. bypass host's fs layer.

This patch makes raw block device work as disk image, user can do
read/write on raw block device, by using DISK_IMAGE_REGULAR instead of
DISK_IMAGE_MMAP for block device

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Sasha Levin 9f9207c5ad kvm tools: Fixes for disk image module
Fixes include:
 - Error handling
 - Cleanup
 - Standard init/uninit

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
2015-06-01 16:39:51 +01:00
Cyrill Gorcunov 599ed2a84c kvm tools: Rename pr_error to pr_err to follow kernel convention
The kernel already has pr_err helper lets do the same.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Sasha Levin 3a60be0694 kvm tools: Trivial cleanup
Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Lan Tianyu 2d2179c1d1 kvm tools, qcow: Add support for growing refcount blocks
This patch enables allocating new refcount blocks and so then kvm tools
could expand qcow2 image much larger.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Asias He 51476e4751 kvm tools: Drop write operation in ro_ops_nowrite
It is supposed to have no write ops in ro_ops_nowrite disk operation.
However, there is one. Let's remove it.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:49 +01:00
Asias He 54e0fcf4f6 kvm tools: Remove unnecessary assignment in disk/raw.c
ro_ops is never used after the assignment, so no need to do the
assignment.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:49 +01:00
Asias He 618cbb7c90 kvm tools: Get multiple io events at a time
This patch reduces the number of calls to io_getevents() by getting
multiple io events at a time instead of one in disk image thread.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:49 +01:00
Lan Tianyu e184700adb kvm tools, qcow: Add the support for copy-on-write cluster
When meeting request to write the cluster without copied flag,
allocate a new cluster and write original data with modification
to the new cluster. This also adds support for the writing operation
of the qcow2 compressed image. After testing, image file can pass
through "qemu-img check". The performance is needed to be improved.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:49 +01:00
Sasha Levin 7dd5639103 kvm tools: Use correct config defines
For some reason some of the defines were set to HAS_VIRTIO instead of HAS_AIO.

This broke raw blk device.

Reported-and-tested-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 59e8453a72 kvm tools: Remove async flag from QCOW
QCOW disk image async flag was erroneously enabled, while QCOW doesn't support
async ops yet.

This has caused a hang when booting QCOW images.

Reported-and-tested-by: Richard -rw- Weinberger <richard.weinberger@gmail.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin f41a132b0a kvm tools: Use native vectored AIO in virtio-blk
This patch hooks AIO support into virtio-blk, allowing for faster IO.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
[ penberg@kernel.org: wrap libaio include with CONFIG_HAS_AIO ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 8b52f877bf kvm tools: Split io request from completion
This patch splits IO request processing from completion notification.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 70e1ec58c5 kvm tools: Remove qcow nowrite function
It is no longer needed due to previous changes.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 5af21162e5 kvm tools: Add optional callback on disk op completion
This patch adds an optional callback to be called when a disk op completes.

Currently theres not much use for it, but it is the infrastructure for adding
aio support.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin b41ca15a23 kvm tools: Modify behaviour on missing ops ptr
In case a read or write op ptr is missing simply ignore it instead of
critically failing. This provides an easier way to prevent read or write
in specific scenarios.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 9d15c39a6e kvm tools: Modify disk ops usage
This patch modifies the definition and usage of ops for read only, mmap and
regular IO.

There is no longer a mix between iov and mmap, and read only no longer implies
mmap (although it will try to use it first).

This allows for more flexibility defining different ops for different
scenarios.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 2534c9b641 kvm tools: Remove the non-iov interface from disk image ops
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 38c396e485 kvm tools: Switch to using an enum for disk image types
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Lan Tianyu af68c51ae7 kvm tools: Add support for the read operation of qcow and qcow2 compressed image
This patch adds the decompression operation when confirming the qcow or
qcow2 image is compressed. This patch also divides the read cluster
fucntion into two which are respective for qcow and qcow2 in order to be
convenient to support these two kind images. Add some macros for qcow.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
[ penberg@kernel.org: make zlib optional ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Pekka Enberg 3ecac800ec kvm tools, qcow: Add support for writing to zero refcount clusters
This patch adds support for writing to zero refcount clusters. Refcount blocks
are cached in like L2 tables and flushed upon VIRTIO_BLK_T_FLUSH and when
evicted from the LRU cache.

With this patch applied, 'qemu-img check' no longer complains about referenced
clusters with zero reference count after

  dd if=/dev/zero of=/mnt/tmp

where '/mnt' is freshly generated QCOW2 image.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 17f68274f5 kvm tools, qcow: Force read-only mode for QCOW images
The QCOW write support isn't stable enough for wide-spread use so force
read-only mode for QCOW images.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg e94cdf08a3 kvm tools, qcow: Rename L2 table lookup functions
In preparation for refcount block caching, rename L2 table lookup functions to
use less generic names.

Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 7b4eb53047 kvm tools, qcow: Move L2 cache to 'struct qcow_l1_table'
In preparation for refcount block cache, move L2 cache data structures to
'struct qcow_l1_table'.

Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 3fb67b939e kvm tools, qcow: Unify L1 and L2 variable names
This patch unifies qcow_read_cluster() and qcow_write_cluster() L1 and L2 table
variable names to make the code more readable.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 473aaa2d4c kvm tools: Rename 'struct qcow_table' to 'struct qcow_l1_table'
This patch renames the ambiguous 'struct qcow_table' to 'struct qcow_l1_table'
in preparation for introducing 'struct qcow_refcount_table'.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Sasha Levin eab301d059 kvm tools: Fix warning on 32bit
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 121dd76e2b kvm tools, qcow: Fix copy-on-write image corruption
We don't handle refcount table properly so make sure we only write to clusters
that have the "copied" flag set.

Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Sasha Levin ff6462e808 kvm tools: Implement VIRTIO_BLK_T_GET_ID
Return device id when requested by virtio-blk.
Device id is currently based on the device information and the inode
number of the underlying disk image.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg b2ebe61b25 kvm tools, qcow: I/O error on compressed sectors
We currently don't support compressed sectors in QCOW images so warn the user
about it and return a I/O error.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg aff88976e8 kvm tools, qcow: Flush only dirty L2 tables
This patch improves qcow_l2_cache_write() to only flush dirty L2 tables.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg a4e46515fd kvm tools, qcow: Delayed L2 table writeout
This patch delays writeout for new L2 tables like we do for L1 tables. If a L2
table has non-allocated clusters, we mark that in the in-memory L2 table but
don't actually write it to disk until the L2 table is thrown out of LRU cache
or when qcow_disk_flush() is called. That makes writes to new clusters volatile
before VIRTIO_BLK_T_FLUSH is issued without corrupting the QCOW image on I/O
error.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 4bd7e48bc8 kvm tools, qcow: Use big endian order for L2 table entries
Don't keep the in-memory array in CPU byte order to simplify delayed L2 table
writeout.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 6fe151ae1d kvm tools, qcow: Don't fdatasync() L2 table writeout
There's now now point in making sure new L2 tables actually hit the disk before
we write out data to clusters because they are not visible on-disk until
qcow_disk_flush() is called which flushes the L1 table.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 73984b1184 kvm tools, qcow: Delayed L1 table writeout
This patch moves L1 table writeout to qcow_disk_flush(). The rationale here is
that while writes to clusters that don't have L2 table allocated on-disk are
volatile until VIRTIO_BLK_T_FLUSH is issued, we never corrupt the disk image.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 659f418616 kvm tools, qcow: Introduce qcow_disk_flush()
This patch introduces a QCOW specific qcow_disk_flush() in preparation for
delaying QCOW metadata writeout until VIRTIO_BLK_T_FLUSH time.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg c0799eb9f2 kvm tools, qcow: Fix locking issues
The virtio_blk_do_io() function can enter the QCOW code through
disk_image__{read,write,flush}() from multiple threads because it uses a thread
pool for I/O requests. Thus, use locking to make the QCOW2 code thread-safe.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg fe8bdde0bd kvm tools, qcow: Use 'struct qcow_l2_table' instead of untyped array
This patch converts disk/qcow.c to use 'struct qcow_l2_table' for tracking
dirty L2 tables later on in this series.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 473d58ff6e kvm tools, qcow: Rename struct qcow_l2_cache to struct qcow_l2_table
This patch renames 'struct qcow_l2_cache' to 'struct qcow_l2_table' in
preparation for replacing the untyped L2 table arrays with the struct.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Pekka Enberg 7d94a719bd kvm tools, qcow: Use fdatasync() instead of sync_file_range()
As explained by Christoph Hellwig, sync_file_range() is not sufficient to
guarantee that Qcow image metadata is never corrupted:

  On Thu, Jun 16, 2011 at 12:34:04PM +0300, Pekka Enberg wrote:
  > Hi Christoph,
  >
  > On Thu, Jun 16, 2011 at 09:21:03AM +0300, Pekka Enberg wrote:
  > >> And btw, we use sync_file_range()
  >
  > On Thu, Jun 16, 2011 at 12:24 PM, Christoph Hellwig <hch@infradead.org> wrote:
  > > Which doesn't help you at all. ?sync_file_range is just a hint for VM
  > > writeback, but never commits filesystem metadata nor the physical
  > > disk's write cache. ?In short it's a completely dangerous interface, and
  > > that is pretty well documented in the man page.
  >
  > Doh - I didn't read it carefully enough and got hung up with:
  >
  >     Therefore, unless the application is strictly performing overwrites of
  >     already-instantiated disk blocks, there are no guarantees that the data will
  >     be available after a crash.
  >
  > without noticing that it obviously doesn't work with filesystems like
  > btrfs that do copy-on-write.

  You also missed:

  " This system call does not flush disk write caches and thus does not
    provide any data integrity on systems with volatile disk write
    caches."

  so it's not safe if you either have a cache, or are using btrfs, or
  are using a sparse image, or are using an image preallocated using
  fallocate/posix_fallocate.

  > What's the right thing to do here? Is fdatasync() sufficient?

  Yes.

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:45 +01:00
Prasad Joshi aa400b0039 kvm tools: Add IO delay option
Add a command line debug option to add a fix amount of delay in read and
write operation.

From Ingo "the delays are *constant* [make sure you use a high-res timers
kernel], so they do not result in nearly as much measurement noise as real
block IO does.
[...]
This way you are basically 'emulating' a real disk drive but you will
emulate uniform latencies, which makes measurements a lot more
reliable - while still relevant to the end result."

Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:45 +01:00
Prasad Joshi 3309045f38 kvm tools: Add QCOW level2 caching support
QCOW uses two tables level1 (L1) table and level2 (L2) table. The L1 table
points to offset of L2 table. When a QCOW image is probed, the L1 table is
cached in the memory to avoid reading it from disk on every access. This
caching improves the performance.

The similar performance improvement can be observed when L2 tables are cached.
It is impossible to cache all of the L2 tables because of the memory
constraint. The patch adds L2 table caching capability for up to 32 L2 tables,
it uses combination of RB tree and List to manage the L2 cached tables. The
link list implementation helps in building simple LRU structure and RB tree
helps to search cached table efficiently.

To calculate the performance numbers, the VM was started with following
command line arguments

$ ./kvm run -d /dev/shm/kvm_ubuntu_server.qcow2 --params "root=/dev/vda1" \
> -m 2048

Without Cache
=============
$ fio fio-mixed.job
[...]
fio-sync: (groupid=3, jobs=1): err= 0: pid=563
  read : io=102400KB, bw=31239KB/s, iops=429 , runt=  3278msec
    clat (usec): min=4 , max=31668 , avg=1663.94, stdev=1810.37
     lat (usec): min=281 , max=658022 , avg=162456.88, stdev=242272.58
    bw (KB/s) : min=21536, max=29322, per=20.77%, avg=25956.50, stdev=2755.33
  write: io=34688KB, bw=13235KB/s, iops=183 , runt=  2621msec
    clat (usec): min=77 , max=1619 , avg=431.80, stdev=343.81
     lat (usec): min=78 , max=1620 , avg=433.11, stdev=343.83
    bw (KB/s) : min=11168, max=14447, per=26.34%, avg=13246.00, stdev=1293.73
[...]
Run status group 0 (all jobs):
   READ: io=409600KB, aggrb=74594KB/s, minb=19096KB/s, maxb=20917KB/s,
		mint=5013msec, maxt=5491msec
  WRITE: io=139552KB, aggrb=42624KB/s, minb=10263KB/s, maxb=14463KB/s,
		mint=2414msec, maxt=3274msec

Run status group 1 (all jobs):
   READ: io=409600KB, aggrb=146442KB/s, minb=37489KB/s, maxb=48680KB/s,
		mint=2154msec, maxt=2797msec
  WRITE: io=133296KB, aggrb=59613KB/s, minb=15328KB/s, maxb=16774KB/s,
		mint=2041msec, maxt=2236msec

Run status group 2 (all jobs):
   READ: io=409600KB, aggrb=7178KB/s, minb=1837KB/s, maxb=1840KB/s,
		mint=56961msec, maxt=57057msec
  WRITE: io=139136KB, aggrb=2446KB/s, minb=600KB/s, maxb=661KB/s,
		mint=56238msec, maxt=56880msec

Run status group 3 (all jobs):
   READ: io=409600KB, aggrb=124954KB/s, minb=31988KB/s, maxb=37704KB/s,
		mint=2781msec, maxt=3278msec
  WRITE: io=137936KB, aggrb=50286KB/s, minb=12447KB/s, maxb=13885KB/s,
		mint=2621msec, maxt=2743msec

Disk stats (read/write):
  vda: ios=118760/16273, merge=0/107354, ticks=159260/658290, in_queue=817410,
		util=94.37%
[...]

With Cache
==========
$ fio fio-mixed.job
[...]
fio-sync: (groupid=3, jobs=1): err= 0: pid=573
  read : io=102400KB, bw=76704KB/s, iops=1018 , runt=  1335msec
    clat (usec): min=0 , max=66131 , avg=591.46, stdev=2582.59
     lat (usec): min=66 , max=123396 , avg=25609.49, stdev=38397.57
    bw (KB/s) : min=58208, max=59584, per=34.55%, avg=58896.00, stdev=972.98
  write: io=35600KB, bw=29373KB/s, iops=381 , runt=  1212msec
    clat (usec): min=11 , max=2661 , avg=169.58, stdev=191.60
     lat (usec): min=11 , max=2663 , avg=170.91, stdev=191.78
    bw (KB/s) : min=27104, max=37664, per=29.98%, avg=32384.00, stdev=7467.05
[...]
Run status group 0 (all jobs):
   READ: io=409600KB, aggrb=140562KB/s, minb=35984KB/s, maxb=44450KB/s,
		mint=2359msec, maxt=2914msec
  WRITE: io=138816KB, aggrb=124722KB/s, minb=31502KB/s, maxb=40180KB/s,
		mint=893msec, maxt=1113msec

Run status group 1 (all jobs):
   READ: io=409600KB, aggrb=231151KB/s, minb=59174KB/s, maxb=96111KB/s,
		mint=1091msec, maxt=1772msec
  WRITE: io=141936KB, aggrb=137268KB/s, minb=32340KB/s, maxb=44496KB/s,
		mint=813msec, maxt=1034msec

Run status group 2 (all jobs):
   READ: io=409600KB, aggrb=9211KB/s, minb=2358KB/s, maxb=2363KB/s,
		mint=44367msec, maxt=44468msec
  WRITE: io=129808KB, aggrb=2931KB/s, minb=707KB/s, maxb=797KB/s,
		mint=43331msec, maxt=44285msec

Run status group 3 (all jobs):
   READ: io=409600KB, aggrb=170453KB/s, minb=43636KB/s, maxb=78545KB/s,
		mint=1335msec, maxt=2403msec
  WRITE: io=138256KB, aggrb=108012KB/s, minb=27648KB/s, maxb=37931KB/s,
		mint=879msec, maxt=1280msec

Disk stats (read/write):
  vda: ios=120698/16690, merge=0/114742, ticks=113170/304480, in_queue=417560,
		util=93.26%
[...]

Summary
=======
Read  bandwidth increased by 1.2 to 1.8 times
Write bandwidth increased by 1.1 to 2.9 times
Read  latency   decreased by small margin of 0.2
Write latency   decreased by 0.4

Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:44 +01:00