Optimizing VM disks

VM disks have a number of features which can be used to optimize performance

VirtIO disks

VirtIO disks appear as PCI devices and are supported in all modern Operating Systems and enhanced features allowing for higher speed storage access with less overhead. This is achieved by presenting the storage as a native PCI device without attempting to mimic existing device drivers. VirtIO is the default option for VM Squared and provides a combination of ease and speed.

Because each disk occupies one PCI slot the number of disks attached to a single VM is limited to around 8-12 depending on other NICs and controllers. VMs emulate traditional PC hardware which includes a limited number of PCI slots.

VirtIO-SCSI

VirtIO-SCSI disks appear as SCSI devices on a PCI controller and are a slightly newer form of VirtIO disks. Because they emulate SCSI they can provide features such as SCSI Persistent Reservations which allow multiple VMs to share a disk.

TRIM support is also provided, which means that unallocated space on the disk can be freed in VM Squared’s storage allocation. So when a VM deletes large files and a TRIM request is sent, the space is then freed in the Datastore for use by other VMs.

Virtio-SCSI also allows you to attach up to 255 disks to a single VM.

To enable VirtIO-SCSI, make sure your OS supports it (all modern Linux kernels support this) and set the Feature Virtio-scsi Queues under OS & CPU to a non-blank value matching the number of CPU cores to use for I/O. Ideally this should match the number of logical CPUs in the VM.

Virtio SCSI

VM Disk cache types

Cache type can be updated on disks, using the advanced options in the Attach disk or Edit disk dialogues.

Cache types
Disk Cache TypeRead perfWrite perfData integrityNotes
DefaultNormalNormalGoodHost page cache not used
WritethroughGoodSlowerGoodWrites completed only when data is committed to underlying storage devices. Guest virtual storage adapters are informed there is no writeback cache and the guest does not need to send flush commands.
WritebackGoodNormalGoodUses the host page cache. Writes are reported to the guest as complete when they are placed in the host cache. Guest virtual storage adapters are informed of the writeback cache and will therefore send flush commands as needed.
DirectsyncNormalSlowerGoodWrites reported as completed when data has been committed to the underlying storage device. Host cache is bypassed. Similarly to writethrough this mode can be used to deal with guests that do not send flushes when they are needed.
UnsafeGoodGoodPoorSimilar to writeback except that all flush commands from guests virtual storage adatpers are ignored. Implies that the user prioritizes performance gains over risk of data loss during host outages.

There is no free lunch in write cache strategies. Users have the opportunity to send data into a fast write cache but that data could be lost in the event of a power outage. On the other hand, acknowledging every write without flush commands such as Writethrough or Directsync means that async writes which could avoid blocking the system must be acknowledged and are as slow as sync writes.

Warning

Multiple VMs sharing a persistent disk, such as when using a clustered filesystem, should avoid Writeback caching.

Writeback caching can cause data corruption when multiple write caches are held of the same block device. In this cache Directsync is recommended.