how to check default cache mode for disk in kvm

8,281

Solution 1

Here is a way to check some default cache mode. Although it's also kind of documentation, it's "online" and you get the default cache mode of your current QEMU version. As @dokotr5000 said, it depends on the version.

Run "qemu-img -h" and search for the "cache" part. You will find something like the following.

  'cache' is the cache mode used to write the output disk image, the valid
options are: 'none', 'writeback' (default, except for convert), 'writethrough',
'directsync' and 'unsafe' (default for convert)

The cache mode is associated with individual image files. And the default cache mode you get this way is the one to convert or rebase an image file, instead of the mode when you create it. But at least it suggests the favorite default of current version of QEMU, and lets you make an educated guess.

I tried this on Ubunt 12.04, 14.04, and 16.04. All give writeback as default.

Solution 2

That depends on what kvm version and what flavour you run. See e.g. https://www.suse.com/documentation/sles11/book_kvm/data/sect1_1_chapter_book_kvm.html where it says:

cache mode unspecified

In qemu-kvm versions older than v1.2 (eg SLES11 SP2), not specifying a cache mode meant that writethrough would be used as the default.

http://wiki.qemu.org/ChangeLog/1.2#Block_devices states:

Block devices

[...]

  • The default cache mode for images is now writeback.

For some recommendations between the various modes see e.g.

Share:
8,281

Related videos on Youtube

undefine
Author by

undefine

BOFH

Updated on September 18, 2022

Comments

  • undefine
    undefine over 1 year

    KVM/qemu support various types of cache - none, writethrough, writeback.

    How to check which one is default and is used on system when no cache= is specified?

    For RHEL6 i found that it's writethrough - but for example for sles sometimes it's writeback.

  • undefine
    undefine about 9 years
    Interesting links, but... it doesn't answer to question :-) I know that knowing distribution, version of kvm, environment - it's possible to check in documentation (or sources) what is default. But - how to check it "online"? Having only host and running guest.
  • doktor5000
    doktor5000 about 9 years
    Uhmmm by checking the qemu version via e.g. qemu-kvm --version ? If you're below 1.2 then the default is writethrough, starting with 1.2 the default is writeback. If your question is how to query this for a running VM or un the underlying host, that's probably not that easy and highly depends on how you start the VM. Do you use qemu directly, do you use virsh, do you use virt-viewer ... ?
  • doktor5000
    doktor5000 almost 9 years
    Is your question still not fully answered? Please specify what exactly you're missing. For running VMs you could try to query them via QMP (qemu monitor protocol), see some explanations at kashyapc.com/2013/03/31/… or unix.stackexchange.com/a/140927/83329
  • undefine
    undefine almost 9 years
    I have machine with sime running kvm's. I would like to know which cache mode is used, when (for example) definition of disk is: -device virtio-blk-pci,drive=hotdisk-XXX-pci-4,id=hotdisk-XXX-pci-4,‌​bus=pci.0,addr=0x4 -drive file=/var/run/ganeti/instance-disks/XXX:0,format=raw,if=none‌​,id=hotdisk-XXX-pci-‌​4,bus=0,unit=4 (there is no "cache=" definition in it). If there is possible to get this information via monitor or qmp - please give me some details :-) - i don't see such option.
  • undefine
    undefine almost 9 years
    defaults which depends on type of device aren't nice ;) For example - what if i have lvm on raid construct from drbd and iscsi device? It's solid disk? Or not? which cache mode is used then? I try to write to mailing list in freetime, thanks for link.
  • doktor5000
    doktor5000 almost 9 years
    Those defaults apply to all block devices, no matter what the underlying device actually is. I'm not sure I get your point, if you know that the underlying device needs different cache settings then by all means use those. In my answer there are quite some links with information and comparisons on the cache modes and resulting performance / recommendations.