Configure virtual disk caching

For intensive I/O workloads, selecting the optimal caching mode can significantly increase the virtual machine (VM) performance.

About this task

The KVM hypervisor provides several virtual disk caching modes:

writethrough
Host page cache is used for reading only. Writes are reported as completed only when the data has been committed to the storage device. The sustained IO performance is decreased but this mode has good write guarantees.
writeback
Host page cache is used for both reading and writing. Writes are reported as complete when data reaches the host’s memory cache, not physical storage. This mode has faster IO performance than writethrough but it is possible to lose data on host failure.
none
Host page cache is bypassed entirely. This mode relies directly on the write queue of the physical disk, so it has a predictable sustained IO performance and offers good write guarantees on a stable guest. It is also a safe cache mode for VM live migration.

Procedure

  1. Shut down the selected VM if it is running.
  2. Edit the XML configuration of the selected VM.
    # virsh edit <vm_name>
  3. Find the disk device and edit the cache option in the driver tag.
    <domain type='kvm'>
      <name>testguest1</name>
      ...
      <devices>
        <disk type='file' device='disk'>
          <driver name='qemu' type='raw' cache='none' io='native' iothread='1'/>
          <source file='/var/lib/libvirt/images/test-disk.raw'/>
          <target dev='vda' bus='virtio'/>
          <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
        </disk>
        ...
      </devices>
      ...
    </domain>