2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2022-07-11 21:16:13 +00:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2010-05-28 20:45:14 +00:00
|
|
|
* 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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
|
2016-07-22 15:52:49 +00:00
|
|
|
* Copyright (c) 2016 by Delphix. All rights reserved.
|
2023-11-27 23:43:36 +00:00
|
|
|
* Copyright (c) 2023, Klara Inc.
|
2010-05-28 20:45:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SYS_DDT_H
|
|
|
|
#define _SYS_DDT_H
|
|
|
|
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/fs/zfs.h>
|
|
|
|
#include <sys/zio.h>
|
|
|
|
#include <sys/dmu.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-07-22 15:52:49 +00:00
|
|
|
struct abd;
|
|
|
|
|
ddt: add FDT feature and support for legacy and new on-disk formats
This is the supporting infrastructure for the upcoming dedup features.
Traditionally, dedup objects live directly in the MOS root. While their
details vary (checksum, type and class), they are all the same "kind" of
thing - a store of dedup entries.
The new features are more varied than that, and are better thought of as
a set of related stores for the overall state of a dedup table.
This adds a new feature flag, SPA_FEATURE_FAST_DEDUP. Enabling this will
cause new DDTs to be created as a ZAP in the MOS root, named
DDT-<checksum>. The is used as the root object for the normal type/class
store objects, but will also be a place for any storage required by new
features.
This commit adds two new fields to ddt_t, for version and flags. These
are intended to describe the structure and features of the overall dedup
table, and are stored as-is in the DDT root. In this commit, flags are
always zero, but the intent is that they can be used to hang optional
logic or state onto for new dedup features. Version is always 1.
For a "legacy" dedup table, where no DDT root directory exists, the
version will be 0.
ddt_configure() is expected to determine the version and flags features
currently in operation based on whether or not the fast_dedup feature is
enabled, and from what's available on disk. In this way, its possible to
support both old and new tables.
This also provides a migration path. A legacy setup can be upgraded to
FDT by creating the DDT root ZAP, moving the existing objects into it,
and setting version and flags appropriately. There's no support for that
here, but it would be straightforward to add later and allows the
possibility that newer features could be applied to existing dedup
tables.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Co-authored-by: Allan Jude <allan@klarasystems.com>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Sponsored-by: Klara, Inc.
Sponsored-by: iXsystems, Inc.
Closes #15892
2023-06-20 02:06:13 +00:00
|
|
|
/*
|
|
|
|
* DDT-wide feature flags. These are set in ddt_flags by ddt_configure().
|
|
|
|
*/
|
|
|
|
/* No flags yet. */
|
|
|
|
#define DDT_FLAG_MASK (0)
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
2023-11-27 23:43:36 +00:00
|
|
|
* DDT on-disk storage object types. Each one corresponds to specific
|
|
|
|
* implementation, see ddt_ops_t. The value itself is not stored on disk.
|
|
|
|
*
|
|
|
|
* When searching for an entry, objects types will be searched in this order.
|
|
|
|
*
|
|
|
|
* Note that DDT_TYPES is used as the "no type" for new entries that have not
|
|
|
|
* yet been written to a storage object.
|
2010-05-28 20:45:14 +00:00
|
|
|
*/
|
2023-07-03 02:32:53 +00:00
|
|
|
typedef enum {
|
2023-11-27 23:43:36 +00:00
|
|
|
DDT_TYPE_ZAP = 0, /* ZAP storage object, ddt_zap */
|
2010-05-28 20:45:14 +00:00
|
|
|
DDT_TYPES
|
2023-07-03 02:32:53 +00:00
|
|
|
} ddt_type_t;
|
|
|
|
|
|
|
|
_Static_assert(DDT_TYPES <= UINT8_MAX,
|
|
|
|
"ddt_type_t must fit in a uint8_t");
|
|
|
|
|
|
|
|
/* New and updated entries recieve this type, see ddt_sync_entry() */
|
|
|
|
#define DDT_TYPE_DEFAULT (DDT_TYPE_ZAP)
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
/*
|
2023-11-27 23:43:36 +00:00
|
|
|
* DDT storage classes. Each class has a separate storage object for each type.
|
|
|
|
* The value itself is not stored on disk.
|
|
|
|
*
|
|
|
|
* When search for an entry, object classes will be searched in this order.
|
|
|
|
*
|
|
|
|
* Note that DDT_CLASSES is used as the "no class" for new entries that have not
|
|
|
|
* yet been written to a storage object.
|
2010-05-28 20:45:14 +00:00
|
|
|
*/
|
2023-07-03 02:32:53 +00:00
|
|
|
typedef enum {
|
2023-11-27 23:43:36 +00:00
|
|
|
DDT_CLASS_DITTO = 0, /* entry has ditto blocks (obsolete) */
|
|
|
|
DDT_CLASS_DUPLICATE, /* entry has multiple references */
|
|
|
|
DDT_CLASS_UNIQUE, /* entry has a single reference */
|
2010-05-28 20:45:14 +00:00
|
|
|
DDT_CLASSES
|
2023-07-03 02:32:53 +00:00
|
|
|
} ddt_class_t;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2023-07-03 02:32:53 +00:00
|
|
|
_Static_assert(DDT_CLASSES < UINT8_MAX,
|
|
|
|
"ddt_class_t must fit in a uint8_t");
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
/*
|
2023-11-27 23:43:36 +00:00
|
|
|
* The "key" part of an on-disk entry. This is the unique "name" for a block,
|
|
|
|
* that is, that parts of the block pointer that will always be the same for
|
|
|
|
* the same data.
|
2010-05-28 20:45:14 +00:00
|
|
|
*/
|
2023-07-03 02:43:37 +00:00
|
|
|
typedef struct {
|
2010-05-28 20:45:14 +00:00
|
|
|
zio_cksum_t ddk_cksum; /* 256-bit block checksum */
|
2013-06-11 17:12:34 +00:00
|
|
|
/*
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 17:36:48 +00:00
|
|
|
* Encoded with logical & physical size, encryption, and compression,
|
|
|
|
* as follows:
|
2013-06-11 17:12:34 +00:00
|
|
|
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 17:36:48 +00:00
|
|
|
* | 0 | 0 | 0 |X| comp| PSIZE | LSIZE |
|
2013-06-11 17:12:34 +00:00
|
|
|
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
|
|
|
*/
|
|
|
|
uint64_t ddk_prop;
|
2010-05-28 20:45:14 +00:00
|
|
|
} ddt_key_t;
|
|
|
|
|
2023-11-27 23:43:36 +00:00
|
|
|
/*
|
|
|
|
* Macros for accessing parts of a ddt_key_t. These are similar to their BP_*
|
|
|
|
* counterparts.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
#define DDK_GET_LSIZE(ddk) \
|
|
|
|
BF64_GET_SB((ddk)->ddk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1)
|
|
|
|
#define DDK_SET_LSIZE(ddk, x) \
|
|
|
|
BF64_SET_SB((ddk)->ddk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
|
|
|
|
|
|
|
|
#define DDK_GET_PSIZE(ddk) \
|
|
|
|
BF64_GET_SB((ddk)->ddk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1)
|
|
|
|
#define DDK_SET_PSIZE(ddk, x) \
|
|
|
|
BF64_SET_SB((ddk)->ddk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1, x)
|
|
|
|
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 17:36:48 +00:00
|
|
|
#define DDK_GET_COMPRESS(ddk) BF64_GET((ddk)->ddk_prop, 32, 7)
|
|
|
|
#define DDK_SET_COMPRESS(ddk, x) BF64_SET((ddk)->ddk_prop, 32, 7, x)
|
|
|
|
|
|
|
|
#define DDK_GET_CRYPT(ddk) BF64_GET((ddk)->ddk_prop, 39, 1)
|
|
|
|
#define DDK_SET_CRYPT(ddk, x) BF64_SET((ddk)->ddk_prop, 39, 1, x)
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2023-11-27 23:43:36 +00:00
|
|
|
/*
|
|
|
|
* The "value" part for an on-disk entry. These are the "physical"
|
|
|
|
* characteristics of the stored block, such as its location on disk (DVAs),
|
|
|
|
* birth txg and ref count.
|
|
|
|
*
|
|
|
|
* Note that an entry has an array of four ddt_phys_t, one for each number of
|
|
|
|
* DVAs (copies= property) and another for additional "ditto" copies. Most
|
|
|
|
* users of ddt_phys_t will handle indexing into or counting the phys they
|
|
|
|
* want.
|
|
|
|
*/
|
2023-07-03 02:43:37 +00:00
|
|
|
typedef struct {
|
2010-05-28 20:45:14 +00:00
|
|
|
dva_t ddp_dva[SPA_DVAS_PER_BP];
|
|
|
|
uint64_t ddp_refcnt;
|
|
|
|
uint64_t ddp_phys_birth;
|
|
|
|
} ddt_phys_t;
|
|
|
|
|
Remove dedupditto functionality
If dedup is in use, the `dedupditto` property can be set, causing ZFS to
keep an extra copy of data that is referenced many times (>100x). The
idea was that this data is more important than other data and thus we
want to be really sure that it is not lost if the disk experiences a
small amount of random corruption.
ZFS (and system administrators) rely on the pool-level redundancy to
protect their data (e.g. mirroring or RAIDZ). Since the user/sysadmin
doesn't have control over what data will be offered extra redundancy by
dedupditto, this extra redundancy is not very useful. The bulk of the
data is still vulnerable to loss based on the pool-level redundancy.
For example, if particle strikes corrupt 0.1% of blocks, you will either
be saved by mirror/raidz, or you will be sad. This is true even if
dedupditto saved another 0.01% of blocks from being corrupted.
Therefore, the dedupditto functionality is rarely enabled (i.e. the
property is rarely set), and it fulfills its promise of increased
redundancy even more rarely.
Additionally, this feature does not work as advertised (on existing
releases), because scrub/resilver did not repair the extra (dedupditto)
copy (see https://github.com/zfsonlinux/zfs/pull/8270).
In summary, this seldom-used feature doesn't work, and even if it did it
wouldn't provide useful data protection. It has a non-trivial
maintenance burden (again see https://github.com/zfsonlinux/zfs/pull/8270).
We should remove the dedupditto functionality. For backwards
compatibility with the existing CLI, "zpool set dedupditto" will still
"succeed" (exit code zero), but won't have any effect. For backwards
compatibility with existing pools that had dedupditto enabled at some
point, the code will still be able to understand dedupditto blocks and
free them when appropriate. However, ZFS won't write any new dedupditto
blocks.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Alek Pinchuk <apinchuk@datto.com>
Issue #8270
Closes #8310
2019-06-19 21:54:02 +00:00
|
|
|
/*
|
2023-11-27 23:43:36 +00:00
|
|
|
* Named indexes into the ddt_phys_t array in each entry.
|
|
|
|
*
|
Remove dedupditto functionality
If dedup is in use, the `dedupditto` property can be set, causing ZFS to
keep an extra copy of data that is referenced many times (>100x). The
idea was that this data is more important than other data and thus we
want to be really sure that it is not lost if the disk experiences a
small amount of random corruption.
ZFS (and system administrators) rely on the pool-level redundancy to
protect their data (e.g. mirroring or RAIDZ). Since the user/sysadmin
doesn't have control over what data will be offered extra redundancy by
dedupditto, this extra redundancy is not very useful. The bulk of the
data is still vulnerable to loss based on the pool-level redundancy.
For example, if particle strikes corrupt 0.1% of blocks, you will either
be saved by mirror/raidz, or you will be sad. This is true even if
dedupditto saved another 0.01% of blocks from being corrupted.
Therefore, the dedupditto functionality is rarely enabled (i.e. the
property is rarely set), and it fulfills its promise of increased
redundancy even more rarely.
Additionally, this feature does not work as advertised (on existing
releases), because scrub/resilver did not repair the extra (dedupditto)
copy (see https://github.com/zfsonlinux/zfs/pull/8270).
In summary, this seldom-used feature doesn't work, and even if it did it
wouldn't provide useful data protection. It has a non-trivial
maintenance burden (again see https://github.com/zfsonlinux/zfs/pull/8270).
We should remove the dedupditto functionality. For backwards
compatibility with the existing CLI, "zpool set dedupditto" will still
"succeed" (exit code zero), but won't have any effect. For backwards
compatibility with existing pools that had dedupditto enabled at some
point, the code will still be able to understand dedupditto blocks and
free them when appropriate. However, ZFS won't write any new dedupditto
blocks.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Alek Pinchuk <apinchuk@datto.com>
Issue #8270
Closes #8310
2019-06-19 21:54:02 +00:00
|
|
|
* Note, we no longer generate new DDT_PHYS_DITTO-type blocks. However,
|
|
|
|
* we maintain the ability to free existing dedup-ditto blocks.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
enum ddt_phys_type {
|
|
|
|
DDT_PHYS_DITTO = 0,
|
|
|
|
DDT_PHYS_SINGLE = 1,
|
|
|
|
DDT_PHYS_DOUBLE = 2,
|
|
|
|
DDT_PHYS_TRIPLE = 3,
|
|
|
|
DDT_PHYS_TYPES
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2023-11-27 23:43:36 +00:00
|
|
|
* A "live" entry, holding changes to an entry made this txg, and other data to
|
|
|
|
* support loading, updating and repairing the entry.
|
2010-05-28 20:45:14 +00:00
|
|
|
*/
|
2023-12-05 03:28:39 +00:00
|
|
|
|
|
|
|
/* State flags for dde_flags */
|
ddt: dedup table quota enforcement
This adds two new pool properties:
- dedup_table_size, the total size of all DDTs on the pool; and
- dedup_table_quota, the maximum possible size of all DDTs in the pool
When set, quota will be enforced by checking when a new entry is about
to be created. If the pool is over its dedup quota, the entry won't be
created, and the corresponding write will be converted to a regular
non-dedup write. Note that existing entries can be updated (ie their
refcounts changed), as that reuses the space rather than requiring more.
dedup_table_quota can be set to 'auto', which will set it based on the
size of the devices backing the "dedup" allocation device. This makes it
possible to limit the DDTs to the size of a dedup vdev only, such that
when the device fills, no new blocks are deduplicated.
Sponsored-by: iXsystems, Inc.
Sponsored-By: Klara Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Signed-off-by: Don Brady <don.brady@klarasystems.com>
Co-authored-by: Don Brady <don.brady@klarasystems.com>
Co-authored-by: Rob Wing <rob.wing@klarasystems.com>
Co-authored-by: Sean Eric Fagan <sean.fagan@klarasystems.com>
Closes #15889
2024-07-25 16:47:36 +00:00
|
|
|
#define DDE_FLAG_LOADED (1 << 0) /* entry ready for use */
|
|
|
|
#define DDE_FLAG_OVERQUOTA (1 << 1) /* entry unusable, no space */
|
2023-12-05 03:28:39 +00:00
|
|
|
|
2023-07-03 02:43:37 +00:00
|
|
|
typedef struct {
|
2023-06-09 00:14:42 +00:00
|
|
|
/* key must be first for ddt_key_compare */
|
2023-11-27 23:43:36 +00:00
|
|
|
ddt_key_t dde_key; /* ddt_tree key */
|
|
|
|
ddt_phys_t dde_phys[DDT_PHYS_TYPES]; /* on-disk data */
|
|
|
|
|
|
|
|
/* in-flight update IOs */
|
2010-05-28 20:45:14 +00:00
|
|
|
zio_t *dde_lead_zio[DDT_PHYS_TYPES];
|
2023-11-27 23:43:36 +00:00
|
|
|
|
|
|
|
/* copy of data after a repair read, to be rewritten */
|
2016-07-22 15:52:49 +00:00
|
|
|
struct abd *dde_repair_abd;
|
2023-11-27 23:43:36 +00:00
|
|
|
|
|
|
|
/* storage type and class the entry was loaded from */
|
2023-07-03 02:32:53 +00:00
|
|
|
ddt_type_t dde_type;
|
|
|
|
ddt_class_t dde_class;
|
2023-11-27 23:43:36 +00:00
|
|
|
|
|
|
|
uint8_t dde_flags; /* load state flags */
|
|
|
|
kcondvar_t dde_cv; /* signaled when load completes */
|
ddt: dedup table quota enforcement
This adds two new pool properties:
- dedup_table_size, the total size of all DDTs on the pool; and
- dedup_table_quota, the maximum possible size of all DDTs in the pool
When set, quota will be enforced by checking when a new entry is about
to be created. If the pool is over its dedup quota, the entry won't be
created, and the corresponding write will be converted to a regular
non-dedup write. Note that existing entries can be updated (ie their
refcounts changed), as that reuses the space rather than requiring more.
dedup_table_quota can be set to 'auto', which will set it based on the
size of the devices backing the "dedup" allocation device. This makes it
possible to limit the DDTs to the size of a dedup vdev only, such that
when the device fills, no new blocks are deduplicated.
Sponsored-by: iXsystems, Inc.
Sponsored-By: Klara Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Signed-off-by: Don Brady <don.brady@klarasystems.com>
Co-authored-by: Don Brady <don.brady@klarasystems.com>
Co-authored-by: Rob Wing <rob.wing@klarasystems.com>
Co-authored-by: Sean Eric Fagan <sean.fagan@klarasystems.com>
Closes #15889
2024-07-25 16:47:36 +00:00
|
|
|
uint64_t dde_waiters; /* count of waiters on dde_cv */
|
2023-11-27 23:43:36 +00:00
|
|
|
|
|
|
|
avl_node_t dde_node; /* ddt_tree node */
|
2023-07-03 02:43:37 +00:00
|
|
|
} ddt_entry_t;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
/*
|
2023-11-27 23:43:36 +00:00
|
|
|
* In-core DDT object. This covers all entries and stats for a the whole pool
|
|
|
|
* for a given checksum type.
|
2010-05-28 20:45:14 +00:00
|
|
|
*/
|
2023-07-03 02:43:37 +00:00
|
|
|
typedef struct {
|
2023-11-27 23:43:36 +00:00
|
|
|
kmutex_t ddt_lock; /* protects changes to all fields */
|
|
|
|
|
|
|
|
avl_tree_t ddt_tree; /* "live" (changed) entries this txg */
|
|
|
|
|
ddt: add FDT feature and support for legacy and new on-disk formats
This is the supporting infrastructure for the upcoming dedup features.
Traditionally, dedup objects live directly in the MOS root. While their
details vary (checksum, type and class), they are all the same "kind" of
thing - a store of dedup entries.
The new features are more varied than that, and are better thought of as
a set of related stores for the overall state of a dedup table.
This adds a new feature flag, SPA_FEATURE_FAST_DEDUP. Enabling this will
cause new DDTs to be created as a ZAP in the MOS root, named
DDT-<checksum>. The is used as the root object for the normal type/class
store objects, but will also be a place for any storage required by new
features.
This commit adds two new fields to ddt_t, for version and flags. These
are intended to describe the structure and features of the overall dedup
table, and are stored as-is in the DDT root. In this commit, flags are
always zero, but the intent is that they can be used to hang optional
logic or state onto for new dedup features. Version is always 1.
For a "legacy" dedup table, where no DDT root directory exists, the
version will be 0.
ddt_configure() is expected to determine the version and flags features
currently in operation based on whether or not the fast_dedup feature is
enabled, and from what's available on disk. In this way, its possible to
support both old and new tables.
This also provides a migration path. A legacy setup can be upgraded to
FDT by creating the DDT root ZAP, moving the existing objects into it,
and setting version and flags appropriately. There's no support for that
here, but it would be straightforward to add later and allows the
possibility that newer features could be applied to existing dedup
tables.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Co-authored-by: Allan Jude <allan@klarasystems.com>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Sponsored-by: Klara, Inc.
Sponsored-by: iXsystems, Inc.
Closes #15892
2023-06-20 02:06:13 +00:00
|
|
|
avl_tree_t ddt_repair_tree; /* entries being repaired */
|
|
|
|
|
|
|
|
enum zio_checksum ddt_checksum; /* checksum algorithm in use */
|
|
|
|
spa_t *ddt_spa; /* pool this ddt is on */
|
|
|
|
objset_t *ddt_os; /* ddt objset (always MOS) */
|
2023-11-27 23:43:36 +00:00
|
|
|
|
ddt: add FDT feature and support for legacy and new on-disk formats
This is the supporting infrastructure for the upcoming dedup features.
Traditionally, dedup objects live directly in the MOS root. While their
details vary (checksum, type and class), they are all the same "kind" of
thing - a store of dedup entries.
The new features are more varied than that, and are better thought of as
a set of related stores for the overall state of a dedup table.
This adds a new feature flag, SPA_FEATURE_FAST_DEDUP. Enabling this will
cause new DDTs to be created as a ZAP in the MOS root, named
DDT-<checksum>. The is used as the root object for the normal type/class
store objects, but will also be a place for any storage required by new
features.
This commit adds two new fields to ddt_t, for version and flags. These
are intended to describe the structure and features of the overall dedup
table, and are stored as-is in the DDT root. In this commit, flags are
always zero, but the intent is that they can be used to hang optional
logic or state onto for new dedup features. Version is always 1.
For a "legacy" dedup table, where no DDT root directory exists, the
version will be 0.
ddt_configure() is expected to determine the version and flags features
currently in operation based on whether or not the fast_dedup feature is
enabled, and from what's available on disk. In this way, its possible to
support both old and new tables.
This also provides a migration path. A legacy setup can be upgraded to
FDT by creating the DDT root ZAP, moving the existing objects into it,
and setting version and flags appropriately. There's no support for that
here, but it would be straightforward to add later and allows the
possibility that newer features could be applied to existing dedup
tables.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Co-authored-by: Allan Jude <allan@klarasystems.com>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Sponsored-by: Klara, Inc.
Sponsored-by: iXsystems, Inc.
Closes #15892
2023-06-20 02:06:13 +00:00
|
|
|
uint64_t ddt_dir_object; /* MOS dir holding ddt objects */
|
|
|
|
uint64_t ddt_version; /* DDT version */
|
|
|
|
uint64_t ddt_flags; /* FDT option flags */
|
2023-11-27 23:43:36 +00:00
|
|
|
|
|
|
|
/* per-type/per-class entry store objects */
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t ddt_object[DDT_TYPES][DDT_CLASSES];
|
2023-11-27 23:43:36 +00:00
|
|
|
|
|
|
|
/* object ids for whole-ddt and per-type/per-class stats */
|
|
|
|
uint64_t ddt_stat_object;
|
|
|
|
ddt_object_t ddt_object_stats[DDT_TYPES][DDT_CLASSES];
|
|
|
|
|
|
|
|
/* type/class stats by power-2-sized referenced blocks */
|
2010-05-28 20:45:14 +00:00
|
|
|
ddt_histogram_t ddt_histogram[DDT_TYPES][DDT_CLASSES];
|
|
|
|
ddt_histogram_t ddt_histogram_cache[DDT_TYPES][DDT_CLASSES];
|
2023-07-03 02:43:37 +00:00
|
|
|
} ddt_t;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
/*
|
2023-11-27 23:43:36 +00:00
|
|
|
* In-core and on-disk bookmark for DDT walks. This is a cursor for ddt_walk(),
|
|
|
|
* and is stable across calls, even if the DDT is updated, the pool is
|
|
|
|
* restarted or loaded on another system, or OpenZFS is upgraded.
|
2010-05-28 20:45:14 +00:00
|
|
|
*/
|
2023-07-03 02:43:37 +00:00
|
|
|
typedef struct {
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t ddb_class;
|
|
|
|
uint64_t ddb_type;
|
|
|
|
uint64_t ddb_checksum;
|
|
|
|
uint64_t ddb_cursor;
|
|
|
|
} ddt_bookmark_t;
|
|
|
|
|
|
|
|
extern void ddt_bp_fill(const ddt_phys_t *ddp, blkptr_t *bp,
|
|
|
|
uint64_t txg);
|
|
|
|
extern void ddt_bp_create(enum zio_checksum checksum, const ddt_key_t *ddk,
|
|
|
|
const ddt_phys_t *ddp, blkptr_t *bp);
|
|
|
|
|
|
|
|
extern void ddt_phys_fill(ddt_phys_t *ddp, const blkptr_t *bp);
|
|
|
|
extern void ddt_phys_clear(ddt_phys_t *ddp);
|
|
|
|
extern void ddt_phys_addref(ddt_phys_t *ddp);
|
|
|
|
extern void ddt_phys_decref(ddt_phys_t *ddp);
|
|
|
|
extern ddt_phys_t *ddt_phys_select(const ddt_entry_t *dde, const blkptr_t *bp);
|
|
|
|
|
|
|
|
extern void ddt_histogram_add(ddt_histogram_t *dst, const ddt_histogram_t *src);
|
|
|
|
extern void ddt_histogram_stat(ddt_stat_t *dds, const ddt_histogram_t *ddh);
|
|
|
|
extern boolean_t ddt_histogram_empty(const ddt_histogram_t *ddh);
|
|
|
|
extern void ddt_get_dedup_object_stats(spa_t *spa, ddt_object_t *ddo);
|
ddt: dedup table quota enforcement
This adds two new pool properties:
- dedup_table_size, the total size of all DDTs on the pool; and
- dedup_table_quota, the maximum possible size of all DDTs in the pool
When set, quota will be enforced by checking when a new entry is about
to be created. If the pool is over its dedup quota, the entry won't be
created, and the corresponding write will be converted to a regular
non-dedup write. Note that existing entries can be updated (ie their
refcounts changed), as that reuses the space rather than requiring more.
dedup_table_quota can be set to 'auto', which will set it based on the
size of the devices backing the "dedup" allocation device. This makes it
possible to limit the DDTs to the size of a dedup vdev only, such that
when the device fills, no new blocks are deduplicated.
Sponsored-by: iXsystems, Inc.
Sponsored-By: Klara Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Signed-off-by: Don Brady <don.brady@klarasystems.com>
Co-authored-by: Don Brady <don.brady@klarasystems.com>
Co-authored-by: Rob Wing <rob.wing@klarasystems.com>
Co-authored-by: Sean Eric Fagan <sean.fagan@klarasystems.com>
Closes #15889
2024-07-25 16:47:36 +00:00
|
|
|
extern uint64_t ddt_get_ddt_dsize(spa_t *spa);
|
2010-05-28 20:45:14 +00:00
|
|
|
extern void ddt_get_dedup_histogram(spa_t *spa, ddt_histogram_t *ddh);
|
|
|
|
extern void ddt_get_dedup_stats(spa_t *spa, ddt_stat_t *dds_total);
|
|
|
|
|
|
|
|
extern uint64_t ddt_get_dedup_dspace(spa_t *spa);
|
|
|
|
extern uint64_t ddt_get_pool_dedup_ratio(spa_t *spa);
|
2024-07-26 16:16:18 +00:00
|
|
|
extern int ddt_get_pool_dedup_cached(spa_t *spa, uint64_t *psize);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
extern ddt_t *ddt_select(spa_t *spa, const blkptr_t *bp);
|
|
|
|
extern void ddt_enter(ddt_t *ddt);
|
|
|
|
extern void ddt_exit(ddt_t *ddt);
|
2013-11-19 21:34:46 +00:00
|
|
|
extern void ddt_init(void);
|
|
|
|
extern void ddt_fini(void);
|
2010-05-28 20:45:14 +00:00
|
|
|
extern ddt_entry_t *ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add);
|
|
|
|
extern void ddt_remove(ddt_t *ddt, ddt_entry_t *dde);
|
2024-07-26 16:16:18 +00:00
|
|
|
extern void ddt_prefetch(spa_t *spa, const blkptr_t *bp);
|
|
|
|
extern void ddt_prefetch_all(spa_t *spa);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2023-07-03 02:32:53 +00:00
|
|
|
extern boolean_t ddt_class_contains(spa_t *spa, ddt_class_t max_class,
|
2010-05-28 20:45:14 +00:00
|
|
|
const blkptr_t *bp);
|
|
|
|
|
|
|
|
extern ddt_entry_t *ddt_repair_start(ddt_t *ddt, const blkptr_t *bp);
|
|
|
|
extern void ddt_repair_done(ddt_t *ddt, ddt_entry_t *dde);
|
|
|
|
|
2023-06-09 00:14:42 +00:00
|
|
|
extern int ddt_key_compare(const void *x1, const void *x2);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
extern void ddt_create(spa_t *spa);
|
|
|
|
extern int ddt_load(spa_t *spa);
|
|
|
|
extern void ddt_unload(spa_t *spa);
|
|
|
|
extern void ddt_sync(spa_t *spa, uint64_t txg);
|
|
|
|
extern int ddt_walk(spa_t *spa, ddt_bookmark_t *ddb, ddt_entry_t *dde);
|
|
|
|
|
2023-03-10 19:59:53 +00:00
|
|
|
extern boolean_t ddt_addref(spa_t *spa, const blkptr_t *bp);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _SYS_DDT_H */
|