]> git.proxmox.com Git - mirror_zfs.git/commit - module/zfs/vdev_raidz.c
Add TRIM support
authorBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 29 Mar 2019 16:13:20 +0000 (09:13 -0700)
committerGitHub <noreply@github.com>
Fri, 29 Mar 2019 16:13:20 +0000 (09:13 -0700)
commit1b939560be5c51deecf875af9dada9d094633bf7
tree2a780b838134636ddbc65f89d227e37c74abe17b
parentf94b3cbf43d62f4962e71cfe7ba8c6f0602e2a45
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.

Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Reviewed-by: Tim Chase <tim@chase2k.com>
Reviewed-by: Matt Ahrens <mahrens@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Contributions-by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Contributions-by: Tim Chase <tim@chase2k.com>
Contributions-by: Chunwei Chen <tuxoko@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #8419
Closes #598
91 files changed:
cmd/zpool/zpool_main.c
cmd/ztest/ztest.c
config/kernel-blk-queue-discard.m4 [new file with mode: 0644]
config/kernel.m4
configure.ac
include/libzfs.h
include/libzfs_core.h
include/linux/blkdev_compat.h
include/spl/sys/Makefile.am
include/spl/sys/dkioc_free_util.h [deleted file]
include/sys/Makefile.am
include/sys/fs/zfs.h
include/sys/metaslab.h
include/sys/metaslab_impl.h
include/sys/spa.h
include/sys/spa_impl.h
include/sys/sysevent/eventdefs.h
include/sys/txg.h
include/sys/vdev.h
include/sys/vdev_impl.h
include/sys/vdev_initialize.h
include/sys/vdev_trim.h [new file with mode: 0644]
include/sys/zfs_context.h
include/sys/zfs_debug.h
include/sys/zio.h
include/sys/zio_impl.h
include/sys/zio_priority.h
lib/libzfs/libzfs_pool.c
lib/libzfs/libzfs_util.c
lib/libzfs_core/libzfs_core.c
lib/libzpool/Makefile.am
man/man5/zfs-module-parameters.5
man/man8/zpool.8
module/zcommon/zpool_prop.c
module/zfs/Makefile.in
module/zfs/dmu.c
module/zfs/metaslab.c
module/zfs/spa.c
module/zfs/spa_misc.c
module/zfs/spa_stats.c
module/zfs/txg.c
module/zfs/vdev.c
module/zfs/vdev_disk.c
module/zfs/vdev_file.c
module/zfs/vdev_initialize.c
module/zfs/vdev_label.c
module/zfs/vdev_queue.c
module/zfs/vdev_raidz.c
module/zfs/vdev_removal.c
module/zfs/vdev_trim.c [new file with mode: 0644]
module/zfs/zfs_ioctl.c
module/zfs/zfs_sysfs.c
module/zfs/zio.c
tests/runfiles/linux.run
tests/test-runner/bin/zts-report.py
tests/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c
tests/zfs-tests/include/libtest.shlib
tests/zfs-tests/tests/functional/Makefile.am
tests/zfs-tests/tests/functional/cli_root/Makefile.am
tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg
tests/zfs-tests/tests/functional/cli_root/zpool_trim/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_attach_detach_add_remove.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_import_export.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_multiple.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_offline_export_import_online.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_online_offline.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_partial.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_rate.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_rate_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_secure.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_split.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_suspend_resume.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_unsupported_vdevs.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_verify_checksums.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_verify_trimmed.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/trim/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/trim/autotrim_config.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/trim/autotrim_integrity.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/trim/autotrim_trim_integrity.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/trim/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/trim/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/trim/trim.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/trim/trim.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/trim/trim_config.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/trim/trim_integrity.ksh [new file with mode: 0755]