mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
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
This commit is contained in:
@@ -11,7 +11,6 @@ KERNEL_H = \
|
||||
$(top_srcdir)/include/spl/sys/ctype.h \
|
||||
$(top_srcdir)/include/spl/sys/debug.h \
|
||||
$(top_srcdir)/include/spl/sys/disp.h \
|
||||
$(top_srcdir)/include/spl/sys/dkioc_free_util.h \
|
||||
$(top_srcdir)/include/spl/sys/dkio.h \
|
||||
$(top_srcdir)/include/spl/sys/errno.h \
|
||||
$(top_srcdir)/include/spl/sys/fcntl.h \
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
||||
* Copyright (C) 2007 The Regents of the University of California.
|
||||
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
||||
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
||||
* UCRL-CODE-235197
|
||||
*
|
||||
* This file is part of the SPL, Solaris Porting Layer.
|
||||
* For details, see <http://zfsonlinux.org/>.
|
||||
*
|
||||
* The SPL is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SPL_DKIOC_UTIL_H
|
||||
#define _SPL_DKIOC_UTIL_H
|
||||
|
||||
#include <sys/dkio.h>
|
||||
|
||||
typedef struct dkioc_free_list_ext_s {
|
||||
uint64_t dfle_start;
|
||||
uint64_t dfle_length;
|
||||
} dkioc_free_list_ext_t;
|
||||
|
||||
typedef struct dkioc_free_list_s {
|
||||
uint64_t dfl_flags;
|
||||
uint64_t dfl_num_exts;
|
||||
int64_t dfl_offset;
|
||||
|
||||
/*
|
||||
* N.B. this is only an internal debugging API! This is only called
|
||||
* from debug builds of sd for pre-release checking. Remove before GA!
|
||||
*/
|
||||
void (*dfl_ck_func)(uint64_t, uint64_t, void *);
|
||||
void *dfl_ck_arg;
|
||||
|
||||
dkioc_free_list_ext_t dfl_exts[1];
|
||||
} dkioc_free_list_t;
|
||||
|
||||
static inline void dfl_free(dkioc_free_list_t *dfl) {
|
||||
vmem_free(dfl, DFL_SZ(dfl->dfl_num_exts));
|
||||
}
|
||||
|
||||
static inline dkioc_free_list_t *dfl_alloc(uint64_t dfl_num_exts, int flags) {
|
||||
return (vmem_zalloc(DFL_SZ(dfl_num_exts), flags));
|
||||
}
|
||||
|
||||
#endif /* _SPL_DKIOC_UTIL_H */
|
||||
Reference in New Issue
Block a user