fsync in virtual machine

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

fsync in virtual machine

Wietse Venema
I updated the list of Postfix requirements, with the following note:

* In a virtual machine when Postfix flushes a file with fsync(),
  the file information must not be cached in volatile hypervisor
  memory[1]. Instead the information must be written to disk (or
  to persistent cache) before fsync() returns in the virtual machine.

Where [1] links to http://communities.vmware.com/thread/332142.
This thread discusses some practical mail server experiences.

Below are a few tips that I found with a quick search.

* For XEN, good results are reported with the phy: driver (see
  http://lists.xen.org/archives/html/xen-devel/2012-04/threads.html#00438).

* With KVM and QEMU, one would set "cache=none" to bypass the write
  cache in the physical host and make fsync() work as expected in
  a virtual machine.

Comments are welcome, especially on how to make fsync() work as
expected with VMware, VirtualBox and other hypervisors.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: fsync in virtual machine

Michael Tokarev
On 16.08.2012 16:57, Wietse Venema wrote:
[]
> * With KVM and QEMU, one would set "cache=none" to bypass the write
>   cache in the physical host and make fsync() work as expected in
>   a virtual machine.

FWIW, with QEMU (kvm is just an "accelerator" for qemu, the
device model/emulation is exactly the same), cache flushes
are supported with all cache modes except of "unsafe" (which
is names that way for exactly this reason: flushes are
ignored).  So it is okay to run virtual machines with any
cache mode (except of the obvious).

Contrary to common misunderstanding, cache=none does NOT disable
write cache.  Only the default (up to current 1.1 version)
cache=writethrough disables write caching completely.  Instead,
cache=none disables filesystem cache or pagecache on the host
(hypervisor) only -- there's a cache in devices lower the
stack (disk drives etc).  So disk flushes are still needed
and are properly implemented.

cache=none corresponds to O_DIRECT (direct i/o, bypassing
buffer cache), and cache=writethrough corresponds to O_SYNC.

(there's anothe cache mode in recent qemu, directsync, which
combines O_DIRECT and O_SYNC).

/mjt