TRIM/UNMAP Zvol over iSCSI

Solution 1:

What you're asking is highly iSCSI target implementation specific. Most of them don't do 1:1 SCSI command mapping, so if iSCSI target emulates hard disk - it won't bypass unrecognized commands (incl. UNMAP of course) to underlying storage @ back-end UNLESS you'll explicitly ask iSCSI target to do so. With TGT you ment'd you specify "thin_provisioning=1" for your virtual LUN in config file.

Solution 2:

TRIM is enabled by default to run weekly in Ubuntu 20.04 so there should be no problem even if you run it manually. You can check this in the fstrim.service and fstrim.timer just in case: https://askubuntu.com/questions/1034169/is-trim-enabled-on-my-ubuntu-18-04-installation

However, this indeed looks like you need to enable UNMAP on the target as already mentioned. Since many SATA SSDs had issues with UNMAP, it was disabled in LIO by default: http://www.linux-iscsi.org/Doc/LIO%20Admin%20Manual.pdf.

On the side note, of course, things are getting a lot easier when an iSCSI target natively supports TRIM/UNMAP with no further tinkering. Here is an example: https://forums.starwindsoftware.com/viewtopic.php?f=5&t=5343


Solution 3:

LIO disables UNMAP by default. If you want to enable it you should set the emulate_tpu attribute on the target.