Tested on High Sierra and Mojave
I've been looking off and on about how to enable trim support on a disk image in osx. Had a few more minutes today and found it on the Internet (https://serverfault.com/questions/876467/how-to-add-virtual-storage-as-ssd-in-kvm)
Issue: QEMU disks in osx are presented to the OS in a manner which interprets them as a rotational disk, as shown under About This Mac>System Report>SATA/SATA EXPRESS.
Even after forcing trim on all disks via terminal, trim does not work, or even show it as an option. The result is the OS slows over time and disk images bloat.
To correct:
FOR 6.9.2 and below
(if you're worried about potential loss of data, borking a working vm, or other world ending scenarios, make a backup before doing this, and proceed at your own risk.)
With the VM shutdown, edit xml settings, changing the disk image info from
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='writeback'/>
<source file='/mnt/disks/K/G/vdisk.img'/>
<target dev='hda' bus='sata'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
to
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native' discard='unmap'/>
<source file='/mnt/disks/K/G/vdisk.img'/>
<target dev='hda' bus='sata'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
with the changes only happening on the second line. (note: it may be possible to leave cache on write back and not use the io native setting, but I didn't experiment much, just followed working directions on the link)
make this change for any disk images you have that the vm uses.
next scroll to the bottom of the xml and add the following in the QEMU arguments
<qemu:commandline>
<qemu:arg value='-set'/>
<qemu:arg value='device.sata0-0-0.rotation_rate=1'/>
</qemu:commandline>
any other arguments you have will also still need to be included. I do not know if order matters, but mine is at the end of the arguments list.
if you have any other drives, add an additional copy of the argument (both lines) and modify the "device.sata0-0-0.rotat...." accordingly to match your address type listed at the top with the disk image(s). If you only have one, then you can leave it as is, assuming you didn't change the address.
If you did this correctly, the vm will boot normally. But this time will display:
Recognized as an SSD but no trim support. To fix this, you must force trim on all drives. To do this, go to terminal and enter:
sudo trimforce enable
It will then give you some text that makes it seem like your computer will eat itself.
The OS will then sit for a short bit, after which time it will reboot itself. After it restarts, to verify trim support is now enabled, go back to About This Mac>System Report>SATA/SATA EXPRESS.
6.10.0 RC1 and up
Enjoy!