Page 1 of 1

undocumented "--discard" option and SSD wear out

Posted: 8. May 2014, 10:23
by raw_spider
Hi Guys,

I have a question regarding the VBoxManage "--discard" option on Windows hosts. I recently upgraded my main system (based on Windows 8.1 x64 Update 1 Enterprise) to use a single large SSD drive. To minimize the write rate and maximize the free space, I have configured my linux guests to recognize and use VDIs as non-rotational media (SSDs) and manually set "discard" to "on" with VBoxManage. After issuing "fstrim /" on linux guests the system VDIs lost most of their weight (awesome x 1), which means the system properly issues trim commands to the VM and the VM properly handles it by trimming the VDI file (awesome x 2).

Now, can someone tell me how is this VDI size trimming feature implemented on Windows? More importantly, does it affect the underlying host SSD wear out rate? The most straightforward implementation I could think of would be to have a "virtual physical block" to VDI block mapping table. If certain VDI block becomes empty and is inside the file, we *copy* the last VDI block into its space and update mapping table accordingly. Then we can trim the VDI image to free unused space. But this copy operation requires erase/write operations and I guess will wear out the SSD more when compared to not enabling "--discard" on the VDI. Did I guess correctly or is there something smarter in works under the hood? I apologize if the question seem too technical. This is my first SSD drive and I am totally paranoid about its premature death :)

Thanks!

Re: undocumented "--discard" option and SSD wear out

Posted: 14. May 2014, 12:18
by klaus
Well, paranoia is never helpful when dealing with reality. There are so many variables other than VirtualBox playing a role that staring at it will probably be not worth it. The SSD specs today are far better than they used to be, especially the amount of data which can be written daily while keeping a reasonable life time. So calm down... SSDs in the end won't be radically different than the good old hard disks, because both will eventually become unusable. It should take quite a few years though in both cases unless your use of the drive is far beyond the specs.

That said, a few words by someone who wasn't involved in the implementation of the --discard option... it is undocumented because it's not sufficiently tested to be certain that it doesn't lose data in some situations. Unless you're willing to help with testing (and accept the risk of data loss) you should stay away from it. The block relocation as part of the discard (to shrink the image) happens instantly when the guest issues the associated trim command, and thus will most likely increase the number of disk updates. What impact it has on the SSD lifetime is very hard to tell, because it all depends on what the filesystem implementation on the host is doing (and what the SSD makes out of it).