[libvirt-users] How to set QEMU qcow2 l2-cache-size using libvirt xml?

Frank Myhr fmyhr at fhmtech.com
Mon Sep 19 15:32:26 UTC 2016

QEMU's default qcow2 L2 cache size is too small for large images (and small cluster sizes), resulting in very bad performance.

shows huge performance hit for a 20GB qcow2 with default 64kB cluster size:

L2 Cache, MiB   Average IOPS
1 (default)             5100
1.5                     7300
2                      12700
2.5                    63600

The above link also gives the formula:
optimal L2 cache size = L2 table size = (8 Byte) * (disk size) / (cluster size)

and the QEMU command line for setting L2 cache size, which is not persistent, but must be specified at each invocation:
qemu-system-x86_64 -drive file=hd.qcow2,l2-cache-size=2621440

I'd like to set the l2-cache-size in libvirt xml, but cannot make out how to do it.
There are only hints in the comments at the above link and at

and an earlier unanswered question on this list

Has anyone successfully done this, and could you please give an example of the actual libvirt xml used?


More information about the libvirt-users mailing list