KVM and ZVol TRIM/DISCARD passthrough handling clarification

Hi

I need to get some clarification on TRIM handling in KVM virtualmachines on TrueNAS and how the commands are intercepted and passed to ZFS.

In this forum thread a user (hege) points out that

OK, I figured this one out. Based on this post, the qemu driver needs the discard option set.

and submits it as a bug at JIRA

https://ixsystems.atlassian.net/browse/NAS-122018

This bug was closed with the resolution of Suggestion Not Accepted

A user (@essinghigh) asked if this bug had been looked at and @HoneyBadger responded with:

It’s been merged for the Dragonfish beta on Log in with Atlassian account - let me see if I can prod for a backport to Cobia.
https://ixsystems.atlassian.net/browse/NAS-125642

My Questions

Because the original JRIA issue is closed I cannot ask there and I do not have permission to look at the Dragonfish Beta issue I would like to get the following question answered to clear up how TRIM is implemented in KVM.

  1. Does unmap/trim get passed and utilised for both thick and thin ZVols?
  2. Will this change be applied to existing VM configs and will they need a reboot?
  3. Did this get backported to Cobia?
  4. did the detect-zeroes=detect-zeroes feature get added?, I think this is useful for when ZVols use compression. see the QEMU Man page

Thanks for any information.

Last I checked, TRIM was not passed through and I also wanted that feature.

In theory it’d allow the zvol allocations to be released.

And this would then allow the pool trim to trim the released blocks too.

@stux

  • When TRIM is passed through from the VM, ZFS should just tag the relevant blocks as unused in ZFS. “Hardware” TRIM should not be required for this
  • Admins can optionally TRIM their pools. There is a lot of discussion as to whether this is useful for SSD/NVMe and ZFS.

Last I checked, TRIM was not passed through and I also wanted that feature.

What version of TrueNAS are you running?

I thought I felt my ears burning. Reading my old threads, I’m so flustered!

discard='unmap' has been in since 24.04.0.

To my knowledge this works for both thick and thin provisioned ZVols (though all of my VM ZVols use sparse/thin provisioning so cannot confirm).

I don’t think it was backported to Cobia as it was treated as more of a feature request than a bug.

I’m also not sure about detect-zeroes. I can’t find any mention of it so would assume not.

2 Likes