When and how often does ZFS 'autotrim' take place?
ZFS autotrim really is a continuous, opportunistic operation which run after a block/range was freed.
From the man page:
autotrim = on | off
When set to on space which has been recently freed, and is no longer allocated by the pool, will be periodically trimmed ... Automatic TRIM does not immediately reclaim blocks after a free. Instead, it will optimistically delay allowing smaller ranges to be aggregated in to a few larger ones. These can then be issued more efficiently to the storage.
For more details, you can look at these code comments:
Automatic TRIM happens continuously in the background and operates
solely on recently freed blocks (ms_trim not ms_allocatable).
...
While the automatic TRIM process is highly effective it is more likely
than a manual TRIM to encounter tiny ranges. Ranges less than or equal to
'zfs_trim_extent_bytes_min' (32k) are considered too small to efficiently
TRIM and are skipped. This means small amounts of freed space may not
be automatically trimmed.
Use this command to view io requested on pool [tank], including trim.
zpool iostat -r [tank]