Page 1 of 1

Disk writes caching

Posted: 2. Aug 2009, 12:57
by mar.ste
Referring to some article like http://forums.virtualbox.org/viewtopic. ... 61&start=0 or http://www.opensolaris.org/jive/thread. ... t=0#402221, I was wondering if it's possible to disable completely the host caching and have the guest take control of it (for its part).

Moreover (and more important for people that for example used this to create ZFS pools): are "writetrough" disks subject to disk caching? Does it depends on host OS?

The matter is slightly touched in section 11.1.3 of the v3 manual, but the command suggested (VBoxManage setextradata VMNAME "VBoxInternal/Devices/piix3ide/0/LUN#[x]/Config/IgnoreFlush" 0) "seems" just to be useful with VDI images on IDE drives. Am I correct?

I think this is pretty important for a serious VB use!

Re: Disk writes caching

Posted: 2. Aug 2009, 13:40
by TerryE
The piix3ide IgnoreFlush applies to all IDE attached drives and has a very specific meaning. The default is when the guest OS generates an ATA flush command, the host driver then issues a flush command to the host file system where the VD file is mounted (this is the case for VDI, VHD and VMDKs) This can result in performance hits on the host so the IgnoreFlush suppresses this albeit at the reduction in guest filesystem resilience in the case of a host OS crash (any blocks written to the host file system will still be ultimately flush in any other circumstance).

With the current VBox version it is not possible to bypass the host filesystem / OS caching.

Re: Disk writes caching

Posted: 3. Aug 2009, 00:21
by mar.ste
Thank you Terry for the reply.

Just to understand better, in your reply you didn't mention SATA drives and direct access drives ("writetrough").

In my case I have the combination of the two: 4 SATA drives attached as "raw writetrough disks" to the guest: are these disks behaving differently (in terms of cache) than having the guest OS on a real hw? (I 'm especially wondering why to have an additional management of a writetrough disk)

Re: Disk writes caching

Posted: 3. Aug 2009, 07:34
by TerryE
The reason that I discussed IDE drives is that the piix3ide virtual device implements the IDE3 and IDE4 controllers. The SATA controllers are implemented by a different driver module: AHCI (see http://www.virtualbox.org/svn/vbox/trun ... evAHCI.cpp) which doesn't read the piix3ide configuration. It uses the ahci configuration tree (in the VBox.log file) and if you search for CFGM calls you can see which parameters that it reads.

Both the piix3ide and the AHCI drivers ultimately dispatch to the same host facing disk management driver which are the *HDDCcore.cpp modules again listed in http://www.virtualbox.org/svn/vbox/trun ... s/Storage/. The standard ones are for VDIs, VHDs, VMDKs and Raw (VMDKs) (plus the proprietary ISCSI,) as well as, I see, a new Parallels driver.

So SATA and IDE drivers really refer to the VMM to VM device emulation side. As far as talking to the host File System goes both call the same code to handle a VDI and a different but also common code to handle Raw Partitions. All of these host-side drivers then all call the same RTFileRead / RTFileWrite routines which in the case of both Windows and Linux are implemented by standard (buffered) ReadFile and WriteFile calls (see http://www.virtualbox.org/svn/vbox/trun ... io-win.cpp in the case of Windows). The only real difference with a raw partition is that /dev/sda1, say, is opened rather than /somepath/somefile.vdi (or \\.\PhysicalDrive0 rather than X:\somepath\somefile.vdi in the case of Windows). Neither bypasses the host file system to do true direct I/O to the underlying host device.

Writethrough is a very misleading term because it has a very specific meaning in VirtualBox which is nothing to do with the commonly understood concept of write-through file I/O. It means that the virtual disk is not included in any snapshots, and that any I/O is written to the disk and cannot be discarded as with normal VD snapshots.