Jump to content

VM's Hosted on SSD - TRIM?


Recommended Posts

I have a couple Windows 7 VM's hosting various things. I turned off Disk Defragment because I'm not sure if it sees the virtual drive as an SSD or not and I'd rather err on the side of caution. When it comes to TRIM though, do I need to figure out how to get Windows to TRIM or will my Dynamix SSD TRIM plugin take care of all my virtual drives?

Link to comment

Hopefully @johnnie.black will chime in, but from what I'm reading with a quick google, you would need to change the virtio interface to scsi in the VM image controller definition, first making sure the virtio-scsi driver is available in the guest. After the guest is successfully using virtio-scsi, and you have edited the xml properly, the guest should be able to pass the trim command through to the host device. I'm not altogether clear on whether qcow2 is the only image format supported for this or if a sparse raw image that unraid creates by default will work.

https://blog.zencoffee.org/2016/05/trim-support-kvm-virtual-machines/

 

Trimming the host device with the dynamix plugin will work fine, except that the contents of the virtual disk will not get processed and over time you will probably need to "re-sparsify" the guest disk file and then trim. https://www.jamescoyle.net/how-to/323-reclaim-disk-space-from-a-sparse-image-file-qcow2-vmdk

Link to comment

So I did some investigating as like I said I'd never considered this, but I'm glad DDock brought this up.

 

By default trim doesn't work, since the vdisk on a SSD is detected by Windows as and hard disk drive, not SSD, but following up on what jonathanm posted I found that using the virtio-scsi controller together with discard='unmap' (image can remain raw, no need to use qcow2) will make Windows defrag detect the disk as a "Thin provisioned drive" and this way Windows will discard all unused space on the vdisk, this free space will then be trimmed by the dynamix trim plugin.

 

Example, my Win 8.1 VM, before trim:

 

(allocation - capacity)

50G -rwxrwxrwx 1 root users 60G Apr 26 12:15 vdisk1.img*

 

after trim:

31G -rwxrwxrwx 1 root users 60G Apr 26 12:15 vdisk1.img*

 

So besides trim not working on the vdisk it was wasting about 20GB.

 

 

 

Edited by johnnie.black
Link to comment

Cool, thanks for the replies. I will have to play with this. Just a thought I had and I'm not that experienced with the nitty gritty of VM's and such. I will look into this and hopefully get it working this weekend. I was going through and thinning out all the fluff (services and other features I do not use) and saw disk defragmenter. I figured unRAID would see the file as a "blob" like any encrypted container, but I wanted to check. Thanks again for the information.

Link to comment
On 4/26/2017 at 7:44 AM, johnnie.black said:

So I did some investigating as like I said I'd never considered this, but I'm glad DDock brought this up.

 

By default trim doesn't work, since the vdisk on a SSD is detected by Windows as and hard disk drive, not SSD, but following up on what jonathanm posted I found that using the virtio-scsi controller together with discard='unmap' (image can remain raw, no need to use qcow2) will make Windows defrag detect the disk as a "Thin provisioned drive" and this way Windows will discard all unused space on the vdisk, this free space will then be trimmed by the dynamix trim plugin.

 

Example, my Win 8.1 VM, before trim:

 

(allocation - capacity)

50G -rwxrwxrwx 1 root users 60G Apr 26 12:15 vdisk1.img*

 

after trim:

31G -rwxrwxrwx 1 root users 60G Apr 26 12:15 vdisk1.img*

 

So besides trim not working on the vdisk it was wasting about 20GB.

 

 

 

How did you manage to convert / get Windows to boot after this?  I've changed the controller type, added the controller (and set an appropriate bus#), and windows starts, but then winds up in a boot loop (and ultimately wants to repair the installation)?  Or was this a new install (hard to determine from your post detailing the before / after allocation size).  BTW, windows is detecting my vdisk as an SSD (Win10 Creators edition), but am unable to manually optimize the drive

Edited by Squid
Link to comment
15 minutes ago, Squid said:

How did you manage to convert / get Windows to boot after this?  I've changed the controller type, added the controller (and set an appropriate bus#), and windows starts, but then winds up in a boot loop (and ultimately wants to repair the installation)?  Or was this a new install (hard to determine from your post detailing the before / after allocation size).  BTW, windows is detecting my vdisk as an SSD (Win10 Creators edition), but am unable to manually optimize the drive

 

First only add the controller to the XML, boot Windows and install the driver, it install as "virtio scsi pass-trough controller", shutdown vm and now change the disk line.

 

Fist time booting Windows will crash, due to Windows fast startup, but let it reboot and from now on will boot correctly.

  • Upvote 1
Link to comment
37 minutes ago, johnnie.black said:

 

First only add the controller to the XML, boot Windows and install the driver, it install as "virtio scsi pass-trough controller", shutdown vm and now change the disk line.

 

Fist time booting Windows will crash, due to Windows fast startup, but let it reboot and from now on will boot correctly.

You da man!!!  :D

Untitled.thumb.png.c943708b56d38be364e3e6180546d1f0.png

down to

Untitled.thumb.png.354dffaa8b518f0d58902da8b16bb9c0.png

Link to comment

I'm glad I brought it up. Just a thought I had one day at work. I haven't been able to test it out yet, I have a drive that is possibly failing, so I have been keeping it easy on my server. Drives came in today to replace and I will test it this weekend. I'm sure it will work since other have had success.

Link to comment

I'm still learning, and I've got things kinda working. Added:

 

    <controller type='scsi' index='0' model='virtio-scsi'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </controller>

Changed the slot to one that was not used by anything else, but now my network controller is no longer functioning, can someone please explain to me what I did wrong. Is it something to do with the function= argument.

Link to comment
1 minute ago, DoeBoye said:

Is this only a Windows 7/8 issue? My Windows 10 VM identifies my drive as an SSD without modifying my xml in the above fashion. Do I still need to do this modification?

So did mine, but the vdisk would never release the unused space back to the cache drive without the changes, effectively meaning that trim would never work.

  • Upvote 1
Link to comment
2 minutes ago, DoeBoye said:

Is this only a Windows 7/8 issue? My Windows 10 VM identifies my drive as an SSD without modifying my xml in the above fashion. Do I still need to do this modification?

 

If it's identified as an SSD trim is probably working but won't recover the unused space.

  • Upvote 1
Link to comment
Just now, Squid said:

So did mine, but the vdisk would never release the unused space back to the cache drive without the changes, effectively meaning that trim would never work.

 

 

1 minute ago, johnnie.black said:

 

If it's identified as an SSD trim is probably working but won't recover the unused space.

 

Good to know! I'll implement this change tonight! :)

 

Thanks gents!

Link to comment
Just now, johnnie.black said:

 

If it's identified as an SSD trim is probably working but won't recover the unused space.

But wouldn't the trim ultimately have to operate at the vdisk level?  If the blocks are never released from the vdisk, then ultimately the blocks are still in use on the cache drive, and trim won't operate.

Link to comment
Just now, Squid said:

But wouldn't the trim ultimately have to operate at the vdisk level?  If the blocks are never released from the vdisk, then ultimately the blocks are still in use on the cache drive, and trim won't operate.

 

If Windows detects an SSD it should issue the trim commands and the SSD should do them, but difficult to be sure, using the other method the unused space is unallocated and trimmed by linux/fstrim.

Link to comment

I made the required changes last night to the xml, and it looks like all systems are a go! Win10 sees the drive as a "thin provisioned drive" now, and has successfully run "optimize" on it.

 

The only difference for me was it took a couple of boots before it stopped blue screening. Also, for some odd reason, it forgot all my files on my desktop after the switch to the scsi controller, but I created a blank txt file on the desktop, and they all magically reappeared. Very odd...

 

Unfortunately, I took a picture of the cache drive's used space before making the change, forgetting that I had moved the VM to a separate UnassignedDevices ssd, so I don't know exactly how much space was freed :(  Doh!

 

Thanks folks!

Link to comment

So I got everything working last weekend, so I thought. I was converting all my VM's and as of now it seems that Windows is unable to optimize the drives. When I defragmented using the GUI, it would Trim and then say "Needs optimization (42% space efficiency) every time I clicked optimize.  I've tried a couple other defrag commands in command prompt like /x which consolidates free space. This did run for awhile and seemed to do something, but still would not optimize properly via the GUI. I ran the command defrag c: and it did something, but did not reduce the file size of the image at all. Is there something else I am missing. Is it maybe when I setup the VM's, I set a hard size? Thanks for any imput.

needsoptimized.PNG

cmddefrag.PNG

aftercmddefrag.PNGcontroller.PNG

disk.PNG

Edited by DDock
ocd
Link to comment
42 minutes ago, DDock said:

I've tried a couple other defrag commands in command prompt like /x which consolidates free space

 

Drive optimization only needs to be used once after the controller change to recover the unused space, after that all space is automatically recovered after any file deletion, no point in running optimize.

 

As for the low space efficiency don't know, mine all are above 75%, maybe if you have a lot of small files is less efficient, not sure.

Link to comment

I understand. But sadly I have not reclaimed any free space on my SSD after the changes. These were all steps to try and troubleshoot why my vdisk.img has not shrunk in size at all. I did bump up all my space to 75gb after I took those images on the 3 Windows VM's I have, so the used space all show 78gb used within windows. Within unRAID, the VM's show they have all 75GB allocated, which I would think it would shrink if it was reducing the size appropriately. These were originally Windows 7 machines that were upgraded to 10, if that makes a difference.

allocation.PNG

Link to comment
6 minutes ago, DDock said:

I understand. But sadly I have not reclaimed any free space on my SSD after the changes. These were all steps to try and troubleshoot why my vdisk.img has not shrunk in size at all. I did bump up all my space to 75gb after I took those images on the 3 Windows VM's I have, so the used space all show 78gb used within windows. Within unRAID, the VM's show they have all 75GB allocated, which I would think it would shrink if it was reducing the size appropriately. These were originally Windows 7 machines that were upgraded to 10, if that makes a difference.

 

What filesystem is your cache?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...