VDI TRIM command doesn't work on 4.2

Discussions related to using VirtualBox on Linux hosts.

VDI TRIM command doesn't work on 4.2

Postby mrp » 26. Sep 2012, 11:45

According to VirtualBox 4.2 changelog a new feature was added: "Storage: implemented support for discarding unused
image blocks through TRIM for SATA and IDE and UNMAP for SCSI when using VDI images".

However I can't get it to work on Ubuntu 12.04 Server guest, Virtualbox 4.2_80737 on Ubuntu host, SATA AHCI controller
with dynamic VDI and SSD option enabled. Kernel is 3.2 and necessary 'discard' options where enabled for ext4 partition
mounts to support TRIM.

As test I create and delete multiple files, totaly about 1GB for one cycle. `df` on guest shows same disk usage which is right.
However VDI file grows by that 1GB after each cycle. I did some investigation and it seems that VirtualBox's SSD drive
doesn't advertise TRIM support. I run
hdparm -I /dev/sda
on guest and these entries are missing:

*	Data Set Management TRIM supported
* Deterministic read data after TRIM


Above lines are available on real SSD disk.
So if these are missing in guest then OS is not sending TRIM commands to VDI disk when files are deleted.
Has somebody any clue how to get TRIM working on VDIs?
mrp
 
Posts: 4
Joined: 26. Sep 2012, 11:06

Re: VDI TRIM command doesn't work on 4.2

Postby aeichner » 26. Sep 2012, 11:51

The discard option is independent from the SSD option. You have to enable discard with
Code: Select all   Expand viewCollapse view
VBoxManage storagetattach <VM name> --storagectl "SATA-Controller" --port <port number of disk image> --discard on
. If it still doesn't work after enabling upload the VM log please.
aeichner
Oracle Corporation
 
Posts: 154
Joined: 31. Aug 2007, 19:12

Re: VDI TRIM command doesn't work on 4.2

Postby mrp » 26. Sep 2012, 17:55

Thanks for quick response. TRIM appears finally in `hdparm` results but "--nonrotational on" is also needed otherwise .vbox file stays the same.
I tested offline with no VM started, this time both on Ubuntu 64bit host and Windows 7 64bit host - same results. Guests are Ubuntu 64 bit. Here is history of my attempts:

Code: Select all   Expand viewCollapse view
n@i:/opt/lisa$ VBoxManage storageattach lisa --storagectl "SATA Controller" --port 0 --type hdd --medium lisa.vdi
n@i:/opt/lisa$ grep "AttachedDevice type=\"HardDisk\"" lisa.vbox
        <AttachedDevice type="HardDisk" port="0" device="0">
n@i:/opt/lisa$ VBoxManage storageattach lisa --storagectl "SATA Controller" --port 0 --type hdd --nonrotational on --medium lisa.vdi
VBoxManage: error: Invalid --nonrotational argument 'on'
n@i:/opt/lisa$ VBoxManage storageattach lisa --storagectl "SATA Controller" --port 0 --type hdd --nonrotational off --medium lisa.vdi
VBoxManage: error: Invalid --nonrotational argument 'off'
n@i:/opt/lisa$ grep "AttachedDevice type=\"HardDisk\"" lisa.vbox
        <AttachedDevice type="HardDisk" port="0" device="0">
n@i:/opt/lisa$ VBoxManage storageattach lisa --storagectl "SATA Controller" --port 0 --type hdd --discard on --medium lisa.vdi
n@i:/opt/lisa$ grep "AttachedDevice type=\"HardDisk\"" lisa.vbox
        <AttachedDevice type="HardDisk" port="0" device="0">
n@i:/opt/lisa$ grep "AttachedDevice type=\"HardDisk\"" lisa.vbox
        <AttachedDevice type="HardDisk" port="0" device="0">
n@i:/opt/lisa$ VBoxManage storageattach lisa --storagectl "SATA Controller" --port 0 --type hdd --discard off --medium lisa.vdi
n@i:/opt/lisa$ grep "AttachedDevice type=\"HardDisk\"" lisa.vbox
        <AttachedDevice type="HardDisk" port="0" device="0">
n@i:/opt/lisa$ VBoxManage storageattach lisa --storagectl "SATA Controller" --port 0 --type hdd --discard on --nonrotational on --medium lisa.vdi
n@i:/opt/lisa$ grep "AttachedDevice type=\"HardDisk\"" lisa.vbox
n@i:/opt/lisa$ grep "AttachedDevice*type=\"HardDisk\"" lisa.vbox
n@i:/opt/lisa$ grep "<AttachedDevice" lisa.vbox
        <AttachedDevice passthrough="false" type="DVD" port="1" device="0"/>
        <AttachedDevice discard="true" type="HardDisk" port="0" device="0">


So `nonrotational` doesn't work alone. Also nonrotational seems to be not set in machine config. When I added the line below manually I got finally what I needed (SSD+TRIM).
Code: Select all   Expand viewCollapse view
<AttachedDevice discard="true" nonrotational="true" type="HardDisk" port="0" device="0">


And another story is UI. I've just found that SSD setting is not stored in .vbox file once VirtualBox UI is closed it is unchecked when opened again. Diff on .vbox file doesn't show anything.
When I check "Solid-state drive" option and click OK in configuration window then following line shows up in VBoxSVC.log:

Code: Select all   Expand viewCollapse view
00:00:36.176000          ERROR [COM]: aRC=VBOX_E_OBJECT_NOT_FOUND (0x80bb0001) aIID={22781af3-1c96-4126-9edf-67a020e0e858} aComponent={SessionMachine} aText={No storage device attached to device slot 0 on port 0 of controller 'SATA Controller'}, preserve=false


While after UI is closed this shows up:
Code: Select all   Expand viewCollapse view
00:04:23.049000 main     ERROR [COM]: aRC=VBOX_E_OBJECT_IN_USE (0x80bb000c) aIID={29989373-b111-4654-8493-2e1176cba890} aComponent={Medium} aText={Medium 'D:\virtualki\XP1\Snapshots/{c119f3c4-1de0-410c-8952-730c514d308f}.vmdk' cannot be closed because it is still attached to 1 virtual machines}, preserve=false
00:04:23.049000 main     ERROR [COM]: aRC=VBOX_E_OBJECT_IN_USE (0x80bb000c) aIID={29989373-b111-4654-8493-2e1176cba890} aComponent={Medium} aText={Medium 'D:\virtualki\XP1\Snapshots/{271e25a0-3fb2-42c5-9e00-c2da82ce7239}.vmdk' cannot be closed because it is still attached to 1 virtual machines}, preserve=false
00:04:23.049000 main     ERROR [COM]: aRC=VBOX_E_OBJECT_IN_USE (0x80bb000c) aIID={29989373-b111-4654-8493-2e1176cba890} aComponent={Medium} aText={Medium 'D:\virtualki\XP1\Snapshots/{b11fa740-ec69-487c-a6ae-6be8636e9bbe}.vmdk' cannot be closed because it is still attached to 1 virtual machines}, preserve=false
00:04:23.049000 main     ERROR [COM]: aRC=VBOX_E_OBJECT_IN_USE (0x80bb000c) aIID={29989373-b111-4654-8493-2e1176cba890} aComponent={Medium} aText={Medium 'D:\virtualki\XP1\Snapshots/{d4fe2f8a-238a-4b50-87da-3880798a4829}.vmdk' cannot be closed because it is still attached to 1 virtual machines}, preserve=false
00:04:23.049000 main     ERROR [COM]: aRC=VBOX_E_OBJECT_IN_USE (0x80bb000c) aIID={29989373-b111-4654-8493-2e1176cba890} aComponent={Medium} aText={Medium 'D:\virtualki\XP1\XP1.vmdk' cannot be closed because it is still attached to 1 virtual machines}, preserve=false
00:04:23.049000 main     ERROR [COM]: aRC=VBOX_E_OBJECT_IN_USE (0x80bb000c) aIID={29989373-b111-4654-8493-2e1176cba890} aComponent={Medium} aText={Medium 'D:\virtualki\Win8\Win8.vdi' cannot be closed because it is still attached to 1 virtual machines}, preserve=false
00:04:23.049000 main     ERROR [COM]: aRC=VBOX_E_OBJECT_IN_USE (0x80bb000c) aIID={29989373-b111-4654-8493-2e1176cba890} aComponent={Medium} aText={Medium 'C:\virtualki_ssd\Xubuntu1204\Snapshots/{c169d365-d82d-47a6-806f-fbbe0457644e}.vdi' cannot be closed because it is still attached to 1 virtual machines}, preserve=false
00:04:23.049000 main     ERROR [COM]: aRC=VBOX_E_OBJECT_IN_USE (0x80bb000c) aIID={29989373-b111-4654-8493-2e1176cba890} aComponent={Medium} aText={Medium 'C:\virtualki_ssd\Xubuntu1204\Snapshots/{5ed0e483-db94-42b9-a54c-24dd5f95b873}.vdi' cannot be closed because it is still attached to 1 virtual machines}, preserve=false
00:04:23.049000 main     ERROR [COM]: aRC=VBOX_E_OBJECT_IN_USE (0x80bb000c) aIID={29989373-b111-4654-8493-2e1176cba890} aComponent={Medium} aText={Medium 'C:\virtualki_ssd\Xubuntu1204\Xubuntu1204.vdi' cannot be closed because it is still attached to 1 virtual machines}, preserve=false
00:04:23.064000 Watcher  ERROR [COM]: aRC=E_ACCESSDENIED (0x80070005) aIID={3b2f08eb-b810-4715-bee0-bb06b9880ad2} aComponent={VirtualBox} aText={The object is not ready}, preserve=false


Above is from Windows host, but same happens on Ubuntu host. Virtual machines are shutdown. Only one VirtualBox 4.2 UI session run and closed.
Problem occurs both with VirtualBox configurations migrated from 4.1 and also with new machines created in 4.2.

SSD and TRIM features are great, I have to test them finally with create-delete file cycle.
I hope configuration and documentation will get more polish in 4.2.1. Thanks.
mrp
 
Posts: 4
Joined: 26. Sep 2012, 11:06

Re: VDI TRIM command doesn't work on 4.2

Postby mrp » 27. Sep 2012, 11:53

Storageattach command messes a little with snapshots (new parallel are created). For now I am just editing .vbox file and adding discard="true" nonrotational="true" to AttachedDevice.
Final test shows that TRIM works:

Code: Select all   Expand viewCollapse view
n@i:/opt/jenkins$ du
4973980    ./Snapshots
260    ./Logs
24603740    .
n@i:/opt/jenkins$ du
4531612    ./Snapshots
260    ./Logs
24161372


Between `du`s I deleted some recently created files. I didn't expect that even snapshot size will drop. This is excellent!
Offline compacting frees some more space without using 'zerofree' tricks. This is killer feature which solves all "VM shrinking" debates.
I think discard and nonrotational should be enabled by default for all dynamic VDIs. For better performance VDI file shrinking could be optional.

Thanks a lot and looking forward for configuration and UI improvements.
mrp
 
Posts: 4
Joined: 26. Sep 2012, 11:06

Re: VDI TRIM command doesn't work on 4.2

Postby Speakus » 19. Nov 2015, 05:42

I tried to start use TRIM for VirtualBox 5.0.10 (last) but have no success.
1. Guest shows that SSD does not have TRIM support
2. 'sudo fstrim -v /' will failed with message "fstrim: /: FITRIM ioctl failed: Operation not supported"
3. just deletin las created files will not cause to decrease size of snapshot path

Can anyone confirm that TRIM still works. Is it 5.0.10 issue?
Speakus
 
Posts: 1
Joined: 19. Nov 2015, 05:37

Re: VDI TRIM command doesn't work on 4.2

Postby davidbaumann » 25. Dec 2015, 18:28

I am using TRIM with 5.0.10 on Ubuntu, and it works (after fstrim / the .vdi was smaller.
But I had to add "discard="true"", as written above.
davidbaumann
 
Posts: 11
Joined: 22. Dec 2015, 16:02
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Any

Re: VDI TRIM command doesn't work on 4.2

Postby davidbaumann » 31. Dec 2015, 01:56

Maybe I have to add something. I am not right sure it really messed up my .vdi, but it's not impossible:

https://forums.virtualbox.org/viewtopic.php?f=2&t=75308
davidbaumann
 
Posts: 11
Joined: 22. Dec 2015, 16:02
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Any

Re: VDI TRIM command doesn't work on 4.2

Postby Rusty X » 9. Jan 2017, 16:46

I couldn't get the discard="true" option to work in VirtualBox 5.1.12 Windows x64 with IDE or SATA controllers, but somehow it started working with a SCSI controller :-)
Rusty X
 
Posts: 4
Joined: 25. Jan 2014, 00:06


Return to VirtualBox on Linux Hosts

Who is online

Users browsing this forum: Gonzalo, socratis and 9 guests