From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:50830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzUoz-0005AP-HJ for qemu-devel@nongnu.org; Mon, 20 Feb 2012 10:06:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RzUos-0002yk-KP for qemu-devel@nongnu.org; Mon, 20 Feb 2012 10:06:33 -0500 Received: from mail-pw0-f45.google.com ([209.85.160.45]:53789) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzUos-0002yO-Ec for qemu-devel@nongnu.org; Mon, 20 Feb 2012 10:06:26 -0500 Received: by pbbro12 with SMTP id ro12so7790025pbb.4 for ; Mon, 20 Feb 2012 07:06:25 -0800 (PST) Message-ID: <4F42616D.30800@codemonkey.ws> Date: Mon, 20 Feb 2012 09:06:21 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <4F425643.2@shiftmail.org> In-Reply-To: <4F425643.2@shiftmail.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] Is cache=writeback safe yet? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Virtbie Cc: Kevin Wolf , qemu-devel@nongnu.org On 02/20/2012 08:18 AM, Virtbie wrote: > Dear qemuers, > thanks for your exellent software. > > I would like to use cache=writeback, but I still can't understand if this is > safe or not in case of power loss. "Safe" is too simplistic of a view. The documentation in qemu-options.hx probably needs to be revisited. cache=writeback emulates a large disk cache much the same as every modern hard drive has a builtin cache. The only real difference is that the host cache is very, very large. Some modern file systems did not take the necessary steps to ensure consistency when a volatile write cache is present (ext3 up until very recently when barrier=1 became default). In practice, this didn't create a huge issue because disk write caches are flushed often. Ted T'so has written a lot about the practical bits here. But since the host cache is very large, and may not be flushed for many minutes after the initial write, this can exacerbate the problem. In short, if you're using a recent kernel with ext3 or ext4, cache=writeback is absolutely safe. If you're using an older version of ext3, cache=writeback is still safe but ext3 itself isn't. cache=writeback can make the situation worse. cache=writethrough presents a non-volatile cache which makes even older ext3 filesystems safe. Regards, Anthony Liguori > In particular with virtio-blk on bare LVM device. > > Qemu manpage still says cache=writeback isn't safe, but I seem to find some > discordant information reading around. > > Is the WCE+volatile flag exposed to the guest already? I am logging into a > 2.6.38 guest and trying to find an indicator of disk cache in > /sys/block/vda/device but I am not able to. There is an obscure very long > "features" bitmask which I don't know what it shows. I think this mode is not > safe until WBC is exposed, AFAIU, right? > > > Also please have a look at this: > https://events.linuxfoundation.org/slides/2011/linuxcon-japan/lcj2011_hajnoczi.pdf > page "Caching modes in Qemu" > In the table it is written that writeback has "Guest disk write cache = on". > Does that mean that the guest can commit to real platters by issuing a flush on > the virtual device? > So the problem lies in the fact that no guest will ever spontaneously issue the > flush because they don't see a wce=1? > > > There is another thing I don't understand: > I think I read somewhere that cache=none is safer than cache=writeback. Is that > true? I think that both have a writeback cache, one is in the physical disks > attached to the host, the other is in the host's page cache, so they should have > about the same level of safety. What do you think? > > > Lastly, regarding the newly introduced cache=directsync. Do I understand > correctly that it is supposed to be as safe as cache=writeback but also as slow > as cache=writeback, for writes, and in addition it cannot use the host pagecache > for reads, is that correct? > > > BTW I also wanted to say I very much like the simplification proposed by Anthony > Liguori on 06/29/2011: > >> Thinking twice about this, shouldn't we just move to a simplified model: >> >> -drive file=foo.img,cache=[on|off],hd0 -device virtio-blk-pci,drive=hd0,wce=1 > > splitting the cache features in two (host side / guest side) would very much > clarify what is happening in Qemu, for us ignorant users. > > > Thank you > Vb. >