ZFS on Linux now supports TRIM

drescherjm

[H]F Junkie
Joined
Nov 19, 2008
Messages
14,941
The patch to add TRIM was merged yesterday to the master branch. Not sure if it will be in 0.8 or not. 0.8 has been in the rc stage for a few months.

Add TRIM support

UNMAP/TRIM support is a frequently-requested feature to help
prevent performance from degrading on SSDs and on various other
SAN-like storage back-ends. By issuing UNMAP/TRIM commands for
sectors which are no longer allocated the underlying device can
often more efficiently manage itself.

This TRIM implementation is modeled on the `zpool initialize`
feature which writes a pattern to all unallocated space in the
pool. The new `zpool trim` command uses the same vdev_xlate()
code to calculate what sectors are unallocated, the same per-
vdev TRIM thread model and locking, and the same basic CLI for
a consistent user experience. The core difference is that
instead of writing a pattern it will issue UNMAP/TRIM commands
for those extents.

The zio pipeline was updated to accommodate this by adding a new
ZIO_TYPE_TRIM type and associated spa taskq. This new type makes
is straight forward to add the platform specific TRIM/UNMAP calls
to vdev_disk.c and vdev_file.c. These new ZIO_TYPE_TRIM zios are
handled largely the same way as ZIO_TYPE_READs or ZIO_TYPE_WRITEs.
This makes it possible to largely avoid changing the pipieline,
one exception is that TRIM zio's may exceed the 16M block size
limit since they contain no data.

In addition to the manual `zpool trim` command, a background
automatic TRIM was added and is controlled by the 'autotrim'
property. It relies on the exact same infrastructure as the
manual TRIM. However, instead of relying on the extents in a
metaslab's ms_allocatable range tree, a ms_trim tree is kept
per metaslab. When 'autotrim=on', ranges added back to the
ms_allocatable tree are also added to the ms_free tree. The
ms_free tree is then periodically consumed by an autotrim
thread which systematically walks a top level vdev's metaslabs.

Since the automatic TRIM will skip ranges it considers too small
there is value in occasionally running a full `zpool trim`. This
may occur when the freed blocks are small and not enough time
was allowed to aggregate them. An automatic TRIM and a manual
`zpool trim` may be run concurrently, in which case the automatic
TRIM will yield to the manual TRIM.

https://github.com/zfsonlinux/zfs/commit/1b939560be5c51deecf875af9dada9d094633bf7
 
I installed it last night on my home gentoo box using the -9999 ebuilds but did not test. I think I am going to wait a month or so before issuing a manual trim.

Code:
 zpool trim [-d] [-c | -s] pool [device...]
             Initiates an immediate on-demand TRIM operation for all of the free space in a pool.  This operation informs the underlying storage devices of all blocks in the pool which are no
             longer allocated and allows thinly provisioned devices to reclaim the space.

             A manual on-demand TRIM operation can be initiated irrespective of the autotrim pool property setting.  See the documentation for the autotrim property above for the types of vdev
             devices which can be trimmed.

             -d --secure
                     Causes a secure TRIM to be initiated.  When performing a secure TRIM, the device guarantees that data stored on the trimmed blocks has been erased.  This requires support
                     from the device and is not supported by all SSDs.

             -r --rate rate
                     Controls the rate at which the TRIM operation progresses.  Without this option TRIM is executed as quickly as possible. The rate, expressed in bytes per second, is applied
                     on a per-vdev basis and may be set differently for each leaf vdev.

             -c, --cancel
                     Cancel trimming on the specified devices, or all eligible devices if none are specified.  If one or more target devices are invalid or are not currently being trimmed, the
                     command will fail and no cancellation will occur on any device.

             -s --suspend
                     Suspend trimming on the specified devices, or all eligible devices if none are specified.  If one or more target devices are invalid or are not currently being trimmed, the
                     command will fail and no suspension will occur on any device.  Trimming can then be resumed by running zpool trim with no flags on the relevant target devices.


Thankfully autotrim defaults to off.


Code:
jmd1 /home/jdrescher # zpool get all | grep trim
zfs_root  autotrim                       off                            default
 
Last edited:
I installed it last night on my home gentoo box using the -9999 ebuilds but did not test. I think I am going to wait a month or so before issuing a manual trim.

Brave, brave soul!

I'm over here befuddled as to how to install ZFS on the RHEL 8.0 Beta... having to roll back to 7.6 for now, I'll play with it in a VM later.
 
Back
Top