DDock Posted April 26, 2017 Share Posted April 26, 2017 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? Quote Link to comment
JonathanM Posted April 26, 2017 Share Posted April 26, 2017 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 Quote Link to comment
JorgeB Posted April 26, 2017 Share Posted April 26, 2017 5 hours ago, jonathanm said: Hopefully @johnnie.black will chime in Not sure about this, never really looked into into, will try to investigate when I can if no one else knows for sure how it works. Quote Link to comment
JorgeB Posted April 26, 2017 Share Posted April 26, 2017 (edited) 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 April 26, 2017 by johnnie.black Quote Link to comment
DDock Posted April 26, 2017 Author Share Posted April 26, 2017 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. Quote Link to comment
Squid Posted April 28, 2017 Share Posted April 28, 2017 (edited) 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 April 28, 2017 by Squid Quote Link to comment
JorgeB Posted April 28, 2017 Share Posted April 28, 2017 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. 1 Quote Link to comment
Squid Posted April 28, 2017 Share Posted April 28, 2017 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!!! down to Quote Link to comment
1812 Posted April 28, 2017 Share Posted April 28, 2017 this should be addd somewhere to something. faq. optimization. something. seems important enough to merit it. Quote Link to comment
DDock Posted April 28, 2017 Author Share Posted April 28, 2017 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. Quote Link to comment
DDock Posted April 29, 2017 Author Share Posted April 29, 2017 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. Quote Link to comment
JorgeB Posted April 29, 2017 Share Posted April 29, 2017 I added a FAQ entry with the instructions, check it out and if any step doesn't work correctly for you post here so I can improve it. 1 Quote Link to comment
DDock Posted April 29, 2017 Author Share Posted April 29, 2017 Got it all working now! Thanks for all the help. Quote Link to comment
bonienl Posted April 30, 2017 Share Posted April 30, 2017 Thanks for the detailed guide johnnie! Have it working too with the additional recovery of space on my cache disk. Now to make it permanently stick in XML Quote Link to comment
DoeBoye Posted May 2, 2017 Share Posted May 2, 2017 (edited) 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? Edited May 2, 2017 by DoeBoye Quote Link to comment
Squid Posted May 2, 2017 Share Posted May 2, 2017 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. 1 Quote Link to comment
JorgeB Posted May 2, 2017 Share Posted May 2, 2017 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. 1 Quote Link to comment
DoeBoye Posted May 2, 2017 Share Posted May 2, 2017 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! Quote Link to comment
Squid Posted May 2, 2017 Share Posted May 2, 2017 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. Quote Link to comment
JorgeB Posted May 2, 2017 Share Posted May 2, 2017 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. Quote Link to comment
DoeBoye Posted May 3, 2017 Share Posted May 3, 2017 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! Quote Link to comment
DDock Posted May 5, 2017 Author Share Posted May 5, 2017 (edited) 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. Edited May 5, 2017 by DDock ocd Quote Link to comment
JorgeB Posted May 5, 2017 Share Posted May 5, 2017 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. Quote Link to comment
DDock Posted May 5, 2017 Author Share Posted May 5, 2017 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. Quote Link to comment
JorgeB Posted May 5, 2017 Share Posted May 5, 2017 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? Quote Link to comment
Recommended Posts
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.