mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-18 10:21:01 +03:00
1b939560be
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
128 lines
4.2 KiB
C
128 lines
4.2 KiB
C
/*
|
|
* CDDL HEADER START
|
|
*
|
|
* The contents of this file are subject to the terms of the
|
|
* Common Development and Distribution License (the "License").
|
|
* You may not use this file except in compliance with the License.
|
|
*
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
* See the License for the specific language governing permissions
|
|
* and limitations under the License.
|
|
*
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
*
|
|
* CDDL HEADER END
|
|
*/
|
|
|
|
/*
|
|
* Copyright (c) 2012, 2017 by Delphix. All rights reserved.
|
|
* Copyright (c) 2017 Datto Inc.
|
|
* Copyright 2017 RackTop Systems.
|
|
* Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
|
|
*/
|
|
|
|
#ifndef _LIBZFS_CORE_H
|
|
#define _LIBZFS_CORE_H
|
|
|
|
#include <libnvpair.h>
|
|
#include <sys/param.h>
|
|
#include <sys/types.h>
|
|
#include <sys/fs/zfs.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
int libzfs_core_init(void);
|
|
void libzfs_core_fini(void);
|
|
|
|
/*
|
|
* NB: this type should be kept binary compatible with dmu_objset_type_t.
|
|
*/
|
|
enum lzc_dataset_type {
|
|
LZC_DATSET_TYPE_ZFS = 2,
|
|
LZC_DATSET_TYPE_ZVOL
|
|
};
|
|
|
|
int lzc_remap(const char *fsname);
|
|
int lzc_snapshot(nvlist_t *, nvlist_t *, nvlist_t **);
|
|
int lzc_create(const char *, enum lzc_dataset_type, nvlist_t *, uint8_t *,
|
|
uint_t);
|
|
int lzc_clone(const char *, const char *, nvlist_t *);
|
|
int lzc_promote(const char *, char *, int);
|
|
int lzc_destroy_snaps(nvlist_t *, boolean_t, nvlist_t **);
|
|
int lzc_bookmark(nvlist_t *, nvlist_t **);
|
|
int lzc_get_bookmarks(const char *, nvlist_t *, nvlist_t **);
|
|
int lzc_destroy_bookmarks(nvlist_t *, nvlist_t **);
|
|
int lzc_load_key(const char *, boolean_t, uint8_t *, uint_t);
|
|
int lzc_unload_key(const char *);
|
|
int lzc_change_key(const char *, uint64_t, nvlist_t *, uint8_t *, uint_t);
|
|
int lzc_initialize(const char *, pool_initialize_func_t, nvlist_t *,
|
|
nvlist_t **);
|
|
int lzc_trim(const char *, pool_trim_func_t, uint64_t, boolean_t,
|
|
nvlist_t *, nvlist_t **);
|
|
|
|
int lzc_snaprange_space(const char *, const char *, uint64_t *);
|
|
|
|
int lzc_hold(nvlist_t *, int, nvlist_t **);
|
|
int lzc_release(nvlist_t *, nvlist_t **);
|
|
int lzc_get_holds(const char *, nvlist_t **);
|
|
|
|
enum lzc_send_flags {
|
|
LZC_SEND_FLAG_EMBED_DATA = 1 << 0,
|
|
LZC_SEND_FLAG_LARGE_BLOCK = 1 << 1,
|
|
LZC_SEND_FLAG_COMPRESS = 1 << 2,
|
|
LZC_SEND_FLAG_RAW = 1 << 3,
|
|
};
|
|
|
|
int lzc_send(const char *, const char *, int, enum lzc_send_flags);
|
|
int lzc_send_resume(const char *, const char *, int,
|
|
enum lzc_send_flags, uint64_t, uint64_t);
|
|
int lzc_send_space(const char *, const char *, enum lzc_send_flags, uint64_t *);
|
|
|
|
struct dmu_replay_record;
|
|
|
|
int lzc_receive(const char *, nvlist_t *, const char *, boolean_t, boolean_t,
|
|
int);
|
|
int lzc_receive_resumable(const char *, nvlist_t *, const char *, boolean_t,
|
|
boolean_t, int);
|
|
int lzc_receive_with_header(const char *, nvlist_t *, const char *, boolean_t,
|
|
boolean_t, boolean_t, int, const struct dmu_replay_record *);
|
|
int lzc_receive_one(const char *, nvlist_t *, const char *, boolean_t,
|
|
boolean_t, boolean_t, int, const struct dmu_replay_record *, int,
|
|
uint64_t *, uint64_t *, uint64_t *, nvlist_t **);
|
|
int lzc_receive_with_cmdprops(const char *, nvlist_t *, nvlist_t *,
|
|
uint8_t *, uint_t, const char *, boolean_t, boolean_t, boolean_t, int,
|
|
const struct dmu_replay_record *, int, uint64_t *, uint64_t *,
|
|
uint64_t *, nvlist_t **);
|
|
|
|
boolean_t lzc_exists(const char *);
|
|
|
|
int lzc_rollback(const char *, char *, int);
|
|
int lzc_rollback_to(const char *, const char *);
|
|
|
|
int lzc_rename(const char *, const char *);
|
|
int lzc_destroy(const char *);
|
|
|
|
int lzc_channel_program(const char *, const char *, uint64_t,
|
|
uint64_t, nvlist_t *, nvlist_t **);
|
|
int lzc_channel_program_nosync(const char *, const char *, uint64_t,
|
|
uint64_t, nvlist_t *, nvlist_t **);
|
|
|
|
int lzc_sync(const char *, nvlist_t *, nvlist_t **);
|
|
int lzc_reopen(const char *, boolean_t);
|
|
|
|
int lzc_pool_checkpoint(const char *);
|
|
int lzc_pool_checkpoint_discard(const char *);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _LIBZFS_CORE_H */
|