Use Host I/O Cache as default option

Here you can provide suggestions on how to improve the product, website, etc.
Post Reply
hamishmb
Posts: 12
Joined: 30. Jan 2020, 01:01
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Linux, Windows

Use Host I/O Cache as default option

Post by hamishmb »

Is there any possibility that the "Use Host I/O Cache" option could be made the default for new storage controllers during setup and configuration?

VM performance on a rust drive without this is abysmal, and it is also fairly slow even on an SSD with this option disabled - making it the default would certainly reduce the number of steps needed to get a performant VM.

For reference, I'm running on a AMD Ryzen 3600 CPU with Linux Mint 20.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Use Host I/O Cache as default option

Post by scottgus1 »

See https://www.virtualbox.org/manual/ch05.html#iocaching. There can be some possible negative effects of using the host I/O cache.

FWIW on my guests, where I don't think I ever fool with that setting, "Use Host I/O Cache" is enabled on floppy and IDE controllers, and disabled on SATA controllers.
hamishmb
Posts: 12
Joined: 30. Jan 2020, 01:01
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Linux, Windows

Re: Use Host I/O Cache as default option

Post by hamishmb »

Ah, I thought there was probably a reason.

This part: "Oracle VM VirtualBox uses its own small cache to buffer writes" interests me, because it's mostly write operations that are slow without it for me - up to an order of magnitude slower (with virtual SATA & NVMe controllers).

Could this perhaps be added as an opt-in preference instead? That would make my life quite a lot easier in some scenarios where I have to remember to go enable all of them to avoid problems on other peoples machines before exporting some VMs.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Use Host I/O Cache as default option

Post by fth0 »

FWIW, I've been using the Host I/O Cache for SATA controllers at least for half a year now. One of my VMs is running 24/7, albeit not being disk intensive, and didn't have any problems yet, but I have backups of all important data of course. socratis has also often suggested using the Host I/O Cache when users complained about slow VMs, often with success.

If the Host I/O Cache is disabled, VirtualBox automatically uses its small cache to buffer writes (5 MB), and vice versa. In my experience, VMs not using the Host I/O Cache are much slower when being located on a HDD on the host, and even noticeably slower when being located on a SSD on the host.
hamishmb
Posts: 12
Joined: 30. Jan 2020, 01:01
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Linux, Windows

Re: Use Host I/O Cache as default option

Post by hamishmb »

Your experience sounds very similar to mine. I don't know exactly how long I've been turning that option on, but again probably around 6 months at least.

What Host OS are you using, out of interest?
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Use Host I/O Cache as default option

Post by fth0 »

macOS High Sierra 10.13.6, Linux Mint 20, Windows 10 2004.
hamishmb
Posts: 12
Joined: 30. Jan 2020, 01:01
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Linux, Windows

Re: Use Host I/O Cache as default option

Post by hamishmb »

Also out of interest, do you have issues with Host I/O Cache turned off? I seem to experience lockups with it turned off if nonrotational VDI option is on and discard= on in Linux guests. (Report at: https://www.virtualbox.org/ticket/20000)
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Use Host I/O Cache as default option

Post by fth0 »

There is no discard= on: There is discard="true" in the .vbox file, the Linux mount option discard, and the Linux fstrim command. All three have different meanings, and there are even more factors that influence what happens when. What exactly are you doing?

Without using the Host I/O Cache, I had issues with Windows guests that automatically behave similar to a Linux guest with the (deprecated) Linux mount option discard set. I didn't further investigate, though.
hamishmb
Posts: 12
Joined: 30. Jan 2020, 01:01
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Linux, Windows

Re: Use Host I/O Cache as default option

Post by hamishmb »

I'm, using the nonrotational and discard options in the .vbox file, the Linux mount option discard, and occasionally running fstrim (largely not needed IIRC due to having discard=on as a mount option).

Seems to work better than my old solution with zerofree, but only with Host I/O cache on.

I found Windows guests just locked up very frequently when I used the VirtualBox nonrotational and discard options. I don't know what Host I/O cache was set to for that, though, because it was a while ago.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Use Host I/O Cache as default option

Post by fth0 »

Yes, that's the same effect I've noticed.

Some general background (without claim of completeness ;)):

In a simple scenario without virtualization (PC with Linux OS on SSD), using the Linux mount option discard is deprecated because TRIMming can block the SSD device for quite a long time (up to minutes), with all sorts of unexpected consequences. For this reason, many Linux distributions favor using fstrim via cron, preferably at times when the PC is idle.

In a VirtualBox scenario the whole topic is much more complicated: The host has some disk drive (HDD or SSD), with or without TRIM support, that contains the VDI file. VirtualBox provides a virtual hard drive (HDD or SSD) to the guest OS, with or without TRIM support. The guest OS uses TRIMming one way or the other. Note that a TRIM command from the guest OS does not trigger a TRIM command on a host SSD device! And note that I didn't say anything about the disk caches (in the host OS, in VirtualBox and in the guest OS) up to here. ;)
hamishmb
Posts: 12
Joined: 30. Jan 2020, 01:01
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Linux, Windows

Re: Use Host I/O Cache as default option

Post by hamishmb »

Yeah, that sounds right.

Upon further investigation, it seems that IDE controllers do use the Host IO cache by default, but SATA & NVMe do not. I wonder why this is.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Use Host I/O Cache as default option

Post by fth0 »

hamishmb wrote:Upon further investigation, it seems that IDE controllers do use the Host IO cache by default, but SATA & NVMe do not. I wonder why this is.
This is explained in the VirtualBox User Manual: 5.7. Host Input/Output Caching.
necros2014
Posts: 17
Joined: 15. Jul 2014, 14:32

Re: Use Host I/O Cache as default option

Post by necros2014 »

+1
Compileplspls
Posts: 6
Joined: 3. Mar 2021, 11:37

Re: Use Host I/O Cache as default option

Post by Compileplspls »

fth0 wrote:
hamishmb wrote:Upon further investigation, it seems that IDE controllers do use the Host IO cache by default, but SATA & NVMe do not. I wonder why this is. This is explained in the VirtualBox User Manual:
Thanks a lot!
Post Reply