2010-05-29 00:45:14 +04: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-12 00:16:13 +03:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2010-05-29 00:45:14 +04: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 18:52:49 +03:00
|
|
|
* Copyright (c) 2012, 2016 by Delphix. All rights reserved.
|
2023-03-10 22:59:53 +03:00
|
|
|
* Copyright (c) 2022 by Pawel Jakub Dawidek
|
2023-11-28 02:43:36 +03:00
|
|
|
* Copyright (c) 2023, Klara Inc.
|
2010-05-29 00:45:14 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/zfs_context.h>
|
|
|
|
#include <sys/spa.h>
|
|
|
|
#include <sys/spa_impl.h>
|
|
|
|
#include <sys/zio.h>
|
|
|
|
#include <sys/ddt.h>
|
2023-06-30 06:35:18 +03:00
|
|
|
#include <sys/ddt_impl.h>
|
2010-05-29 00:45:14 +04:00
|
|
|
#include <sys/zap.h>
|
|
|
|
#include <sys/dmu_tx.h>
|
|
|
|
#include <sys/arc.h>
|
|
|
|
#include <sys/dsl_pool.h>
|
|
|
|
#include <sys/zio_checksum.h>
|
|
|
|
#include <sys/dsl_scan.h>
|
2016-07-22 18:52:49 +03:00
|
|
|
#include <sys/abd.h>
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2023-11-28 02:43:36 +03:00
|
|
|
/*
|
|
|
|
* # DDT: Deduplication tables
|
|
|
|
*
|
|
|
|
* The dedup subsystem provides block-level deduplication. When enabled, blocks
|
|
|
|
* to be written will have the dedup (D) bit set, which causes them to be
|
|
|
|
* tracked in a "dedup table", or DDT. If a block has been seen before (exists
|
|
|
|
* in the DDT), instead of being written, it will instead be made to reference
|
|
|
|
* the existing on-disk data, and a refcount bumped in the DDT instead.
|
|
|
|
*
|
|
|
|
* ## Dedup tables and entries
|
|
|
|
*
|
|
|
|
* Conceptually, a DDT is a dictionary or map. Each entry has a "key"
|
|
|
|
* (ddt_key_t) made up a block's checksum and certian properties, and a "value"
|
|
|
|
* (one or more ddt_phys_t) containing valid DVAs for the block's data, birth
|
|
|
|
* time and refcount. Together these are enough to track references to a
|
|
|
|
* specific block, to build a valid block pointer to reference that block (for
|
|
|
|
* freeing, scrubbing, etc), and to fill a new block pointer with the missing
|
|
|
|
* pieces to make it seem like it was written.
|
|
|
|
*
|
|
|
|
* There's a single DDT (ddt_t) for each checksum type, held in spa_ddt[].
|
|
|
|
* Within each DDT, there can be multiple storage "types" (ddt_type_t, on-disk
|
|
|
|
* object data formats, each with their own implementations) and "classes"
|
|
|
|
* (ddt_class_t, instance of a storage type object, for entries with a specific
|
|
|
|
* characteristic). An entry (key) will only ever exist on one of these objects
|
|
|
|
* at any given time, but may be moved from one to another if their type or
|
|
|
|
* class changes.
|
|
|
|
*
|
|
|
|
* The DDT is driven by the write IO pipeline (zio_ddt_write()). When a block
|
|
|
|
* is to be written, before DVAs have been allocated, ddt_lookup() is called to
|
|
|
|
* see if the block has been seen before. If its not found, the write proceeds
|
|
|
|
* as normal, and after it succeeds, a new entry is created. If it is found, we
|
|
|
|
* fill the BP with the DVAs from the entry, increment the refcount and cause
|
|
|
|
* the write IO to return immediately.
|
|
|
|
*
|
|
|
|
* Each ddt_phys_t slot in the entry represents a separate dedup block for the
|
|
|
|
* same content/checksum. The slot is selected based on the zp_copies parameter
|
|
|
|
* the block is written with, that is, the number of DVAs in the block. The
|
|
|
|
* "ditto" slot (DDT_PHYS_DITTO) used to be used for now-removed "dedupditto"
|
|
|
|
* feature. These are no longer written, and will be freed if encountered on
|
|
|
|
* old pools.
|
|
|
|
*
|
|
|
|
* ## Lifetime of an entry
|
|
|
|
*
|
|
|
|
* A DDT can be enormous, and typically is not held in memory all at once.
|
|
|
|
* Instead, the changes to an entry are tracked in memory, and written down to
|
|
|
|
* disk at the end of each txg.
|
|
|
|
*
|
|
|
|
* A "live" in-memory entry (ddt_entry_t) is a node on the live tree
|
|
|
|
* (ddt_tree). At the start of a txg, ddt_tree is empty. When an entry is
|
|
|
|
* required for IO, ddt_lookup() is called. If an entry already exists on
|
|
|
|
* ddt_tree, it is returned. Otherwise, a new one is created, and the
|
|
|
|
* type/class objects for the DDT are searched for that key. If its found, its
|
|
|
|
* value is copied into the live entry. If not, an empty entry is created.
|
|
|
|
*
|
|
|
|
* The live entry will be modified during the txg, usually by modifying the
|
|
|
|
* refcount, but sometimes by adding or updating DVAs. At the end of the txg
|
|
|
|
* (during spa_sync()), type and class are recalculated for entry (see
|
|
|
|
* ddt_sync_entry()), and the entry is written to the appropriate storage
|
|
|
|
* object and (if necessary), removed from an old one. ddt_tree is cleared and
|
|
|
|
* the next txg can start.
|
|
|
|
*
|
|
|
|
* ## Repair IO
|
|
|
|
*
|
|
|
|
* If a read on a dedup block fails, but there are other copies of the block in
|
|
|
|
* the other ddt_phys_t slots, reads will be issued for those instead
|
|
|
|
* (zio_ddt_read_start()). If one of those succeeds, the read is returned to
|
|
|
|
* the caller, and a copy is stashed on the entry's dde_repair_abd.
|
|
|
|
*
|
|
|
|
* During the end-of-txg sync, any entries with a dde_repair_abd get a
|
|
|
|
* "rewrite" write issued for the original block pointer, with the data read
|
|
|
|
* from the alternate block. If the block is actually damaged, this will invoke
|
|
|
|
* the pool's "self-healing" mechanism, and repair the block.
|
|
|
|
*
|
|
|
|
* ## Scanning (scrub/resilver)
|
|
|
|
*
|
|
|
|
* If dedup is active, the scrub machinery will walk the dedup table first, and
|
|
|
|
* scrub all blocks with refcnt > 1 first. After that it will move on to the
|
|
|
|
* regular top-down scrub, and exclude the refcnt > 1 blocks when it sees them.
|
|
|
|
* In this way, heavily deduplicated blocks are only scrubbed once. See the
|
|
|
|
* commentary on dsl_scan_ddt() for more details.
|
|
|
|
*
|
|
|
|
* Walking the DDT is done via ddt_walk(). The current position is stored in a
|
|
|
|
* ddt_bookmark_t, which represents a stable position in the storage object.
|
|
|
|
* This bookmark is stored by the scan machinery, and must reference the same
|
|
|
|
* position on the object even if the object changes, the pool is exported, or
|
|
|
|
* OpenZFS is upgraded.
|
|
|
|
*
|
|
|
|
* ## Interaction with block cloning
|
|
|
|
*
|
|
|
|
* If block cloning and dedup are both enabled on a pool, BRT will look for the
|
|
|
|
* dedup bit on an incoming block pointer. If set, it will call into the DDT
|
|
|
|
* (ddt_addref()) to add a reference to the block, instead of adding a
|
|
|
|
* reference to the BRT. See brt_pending_apply().
|
|
|
|
*/
|
|
|
|
|
2024-02-01 03:05:18 +03:00
|
|
|
/*
|
|
|
|
* These are the only checksums valid for dedup. They must match the list
|
|
|
|
* from dedup_table in zfs_prop.c
|
|
|
|
*/
|
|
|
|
#define DDT_CHECKSUM_VALID(c) \
|
|
|
|
(c == ZIO_CHECKSUM_SHA256 || c == ZIO_CHECKSUM_SHA512 || \
|
|
|
|
c == ZIO_CHECKSUM_SKEIN || c == ZIO_CHECKSUM_EDONR || \
|
|
|
|
c == ZIO_CHECKSUM_BLAKE3)
|
|
|
|
|
2013-11-20 01:34:46 +04:00
|
|
|
static kmem_cache_t *ddt_cache;
|
|
|
|
static kmem_cache_t *ddt_entry_cache;
|
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
/*
|
|
|
|
* Enable/disable prefetching of dedup-ed blocks which are going to be freed.
|
|
|
|
*/
|
2014-08-30 06:13:26 +04:00
|
|
|
int zfs_dedup_prefetch = 0;
|
2010-08-27 01:24:34 +04:00
|
|
|
|
2022-02-25 16:26:54 +03:00
|
|
|
static const ddt_ops_t *const ddt_ops[DDT_TYPES] = {
|
2010-05-29 00:45:14 +04:00
|
|
|
&ddt_zap_ops,
|
|
|
|
};
|
|
|
|
|
2022-02-25 16:26:54 +03:00
|
|
|
static const char *const ddt_class_name[DDT_CLASSES] = {
|
2010-05-29 00:45:14 +04:00
|
|
|
"ditto",
|
|
|
|
"duplicate",
|
|
|
|
"unique",
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_create(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2010-05-29 00:45:14 +04:00
|
|
|
dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
spa_t *spa = ddt->ddt_spa;
|
|
|
|
objset_t *os = ddt->ddt_os;
|
|
|
|
uint64_t *objectp = &ddt->ddt_object[type][class];
|
2016-06-16 01:47:05 +03:00
|
|
|
boolean_t prehash = zio_checksum_table[ddt->ddt_checksum].ci_flags &
|
|
|
|
ZCHECKSUM_FLAG_DEDUP;
|
2010-05-29 00:45:14 +04:00
|
|
|
char name[DDT_NAMELEN];
|
|
|
|
|
|
|
|
ddt_object_name(ddt, type, class, name);
|
|
|
|
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT3U(*objectp, ==, 0);
|
|
|
|
VERIFY0(ddt_ops[type]->ddt_op_create(os, objectp, tx, prehash));
|
|
|
|
ASSERT3U(*objectp, !=, 0);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2024-02-15 11:37:38 +03:00
|
|
|
VERIFY0(zap_add(os, DMU_POOL_DIRECTORY_OBJECT, name,
|
|
|
|
sizeof (uint64_t), 1, objectp, tx));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2024-02-15 11:37:38 +03:00
|
|
|
VERIFY0(zap_add(os, spa->spa_ddt_stat_object, name,
|
2010-05-29 00:45:14 +04:00
|
|
|
sizeof (uint64_t), sizeof (ddt_histogram_t) / sizeof (uint64_t),
|
2024-02-15 11:37:38 +03:00
|
|
|
&ddt->ddt_histogram[type][class], tx));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_destroy(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2010-05-29 00:45:14 +04:00
|
|
|
dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
spa_t *spa = ddt->ddt_spa;
|
|
|
|
objset_t *os = ddt->ddt_os;
|
|
|
|
uint64_t *objectp = &ddt->ddt_object[type][class];
|
2012-10-26 21:01:49 +04:00
|
|
|
uint64_t count;
|
2010-05-29 00:45:14 +04:00
|
|
|
char name[DDT_NAMELEN];
|
|
|
|
|
|
|
|
ddt_object_name(ddt, type, class, name);
|
|
|
|
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT3U(*objectp, !=, 0);
|
2010-05-29 00:45:14 +04:00
|
|
|
ASSERT(ddt_histogram_empty(&ddt->ddt_histogram[type][class]));
|
2024-02-15 11:37:38 +03:00
|
|
|
VERIFY0(ddt_object_count(ddt, type, class, &count));
|
|
|
|
VERIFY0(count);
|
|
|
|
VERIFY0(zap_remove(os, DMU_POOL_DIRECTORY_OBJECT, name, tx));
|
|
|
|
VERIFY0(zap_remove(os, spa->spa_ddt_stat_object, name, tx));
|
|
|
|
VERIFY0(ddt_ops[type]->ddt_op_destroy(os, *objectp, tx));
|
2022-02-25 16:26:54 +03:00
|
|
|
memset(&ddt->ddt_object_stats[type][class], 0, sizeof (ddt_object_t));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
*objectp = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_load(ddt_t *ddt, ddt_type_t type, ddt_class_t class)
|
2010-05-29 00:45:14 +04:00
|
|
|
{
|
|
|
|
ddt_object_t *ddo = &ddt->ddt_object_stats[type][class];
|
|
|
|
dmu_object_info_t doi;
|
2012-10-26 21:01:49 +04:00
|
|
|
uint64_t count;
|
2010-05-29 00:45:14 +04:00
|
|
|
char name[DDT_NAMELEN];
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ddt_object_name(ddt, type, class, name);
|
|
|
|
|
|
|
|
error = zap_lookup(ddt->ddt_os, DMU_POOL_DIRECTORY_OBJECT, name,
|
|
|
|
sizeof (uint64_t), 1, &ddt->ddt_object[type][class]);
|
2013-12-09 22:37:51 +04:00
|
|
|
if (error != 0)
|
2010-05-29 00:45:14 +04:00
|
|
|
return (error);
|
|
|
|
|
2015-08-18 21:20:22 +03:00
|
|
|
error = zap_lookup(ddt->ddt_os, ddt->ddt_spa->spa_ddt_stat_object, name,
|
2010-05-29 00:45:14 +04:00
|
|
|
sizeof (uint64_t), sizeof (ddt_histogram_t) / sizeof (uint64_t),
|
2015-08-18 21:20:22 +03:00
|
|
|
&ddt->ddt_histogram[type][class]);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Seed the cached statistics.
|
|
|
|
*/
|
2012-07-20 01:50:25 +04:00
|
|
|
error = ddt_object_info(ddt, type, class, &doi);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2012-10-26 21:01:49 +04:00
|
|
|
error = ddt_object_count(ddt, type, class, &count);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ddo->ddo_count = count;
|
2010-05-29 00:45:14 +04:00
|
|
|
ddo->ddo_dspace = doi.doi_physical_blocks_512 << 9;
|
|
|
|
ddo->ddo_mspace = doi.doi_fill_count * doi.doi_data_block_size;
|
|
|
|
|
2013-12-09 22:37:51 +04:00
|
|
|
return (0);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_sync(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2010-05-29 00:45:14 +04:00
|
|
|
dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
ddt_object_t *ddo = &ddt->ddt_object_stats[type][class];
|
|
|
|
dmu_object_info_t doi;
|
2012-10-26 21:01:49 +04:00
|
|
|
uint64_t count;
|
2010-05-29 00:45:14 +04:00
|
|
|
char name[DDT_NAMELEN];
|
|
|
|
|
|
|
|
ddt_object_name(ddt, type, class, name);
|
|
|
|
|
2024-02-15 11:37:38 +03:00
|
|
|
VERIFY0(zap_update(ddt->ddt_os, ddt->ddt_spa->spa_ddt_stat_object, name,
|
2010-05-29 00:45:14 +04:00
|
|
|
sizeof (uint64_t), sizeof (ddt_histogram_t) / sizeof (uint64_t),
|
2024-02-15 11:37:38 +03:00
|
|
|
&ddt->ddt_histogram[type][class], tx));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cache DDT statistics; this is the only time they'll change.
|
|
|
|
*/
|
2024-02-15 11:37:38 +03:00
|
|
|
VERIFY0(ddt_object_info(ddt, type, class, &doi));
|
|
|
|
VERIFY0(ddt_object_count(ddt, type, class, &count));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2012-10-26 21:01:49 +04:00
|
|
|
ddo->ddo_count = count;
|
2010-05-29 00:45:14 +04:00
|
|
|
ddo->ddo_dspace = doi.doi_physical_blocks_512 << 9;
|
|
|
|
ddo->ddo_mspace = doi.doi_fill_count * doi.doi_data_block_size;
|
|
|
|
}
|
|
|
|
|
2023-06-30 06:35:18 +03:00
|
|
|
static boolean_t
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_exists(ddt_t *ddt, ddt_type_t type, ddt_class_t class)
|
2023-06-30 06:35:18 +03:00
|
|
|
{
|
|
|
|
return (!!ddt->ddt_object[type][class]);
|
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
static int
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_lookup(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_entry_t *dde)
|
|
|
|
{
|
|
|
|
if (!ddt_object_exists(ddt, type, class))
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOENT));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
return (ddt_ops[type]->ddt_op_lookup(ddt->ddt_os,
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt->ddt_object[type][class], &dde->dde_key,
|
|
|
|
dde->dde_phys, sizeof (dde->dde_phys)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ddt_object_contains(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
|
|
|
const ddt_key_t *ddk)
|
|
|
|
{
|
|
|
|
if (!ddt_object_exists(ddt, type, class))
|
|
|
|
return (SET_ERROR(ENOENT));
|
|
|
|
|
|
|
|
return (ddt_ops[type]->ddt_op_contains(ddt->ddt_os,
|
|
|
|
ddt->ddt_object[type][class], ddk));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_prefetch(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2023-07-03 16:28:46 +03:00
|
|
|
const ddt_key_t *ddk)
|
2010-05-29 00:45:14 +04:00
|
|
|
{
|
|
|
|
if (!ddt_object_exists(ddt, type, class))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ddt_ops[type]->ddt_op_prefetch(ddt->ddt_os,
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt->ddt_object[type][class], ddk);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
2023-06-30 06:35:18 +03:00
|
|
|
static int
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_update(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_entry_t *dde, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
ASSERT(ddt_object_exists(ddt, type, class));
|
|
|
|
|
|
|
|
return (ddt_ops[type]->ddt_op_update(ddt->ddt_os,
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt->ddt_object[type][class], &dde->dde_key, dde->dde_phys,
|
|
|
|
sizeof (dde->dde_phys), tx));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_remove(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2023-07-03 16:28:46 +03:00
|
|
|
const ddt_key_t *ddk, dmu_tx_t *tx)
|
2010-05-29 00:45:14 +04:00
|
|
|
{
|
|
|
|
ASSERT(ddt_object_exists(ddt, type, class));
|
|
|
|
|
|
|
|
return (ddt_ops[type]->ddt_op_remove(ddt->ddt_os,
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt->ddt_object[type][class], ddk, tx));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_walk(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2010-05-29 00:45:14 +04:00
|
|
|
uint64_t *walk, ddt_entry_t *dde)
|
|
|
|
{
|
|
|
|
ASSERT(ddt_object_exists(ddt, type, class));
|
|
|
|
|
|
|
|
return (ddt_ops[type]->ddt_op_walk(ddt->ddt_os,
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt->ddt_object[type][class], walk, &dde->dde_key,
|
|
|
|
dde->dde_phys, sizeof (dde->dde_phys)));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
2012-10-26 21:01:49 +04:00
|
|
|
int
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_count(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2012-10-26 21:01:49 +04:00
|
|
|
uint64_t *count)
|
2010-05-29 00:45:14 +04:00
|
|
|
{
|
|
|
|
ASSERT(ddt_object_exists(ddt, type, class));
|
|
|
|
|
|
|
|
return (ddt_ops[type]->ddt_op_count(ddt->ddt_os,
|
2012-10-26 21:01:49 +04:00
|
|
|
ddt->ddt_object[type][class], count));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_info(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2010-05-29 00:45:14 +04:00
|
|
|
dmu_object_info_t *doi)
|
|
|
|
{
|
|
|
|
if (!ddt_object_exists(ddt, type, class))
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOENT));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
return (dmu_object_info(ddt->ddt_os, ddt->ddt_object[type][class],
|
|
|
|
doi));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_object_name(ddt_t *ddt, ddt_type_t type, ddt_class_t class,
|
2010-05-29 00:45:14 +04:00
|
|
|
char *name)
|
|
|
|
{
|
2020-06-07 21:42:12 +03:00
|
|
|
(void) snprintf(name, DDT_NAMELEN, DMU_POOL_DDT,
|
2010-05-29 00:45:14 +04:00
|
|
|
zio_checksum_table[ddt->ddt_checksum].ci_name,
|
|
|
|
ddt_ops[type]->ddt_op_name, ddt_class_name[class]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_bp_fill(const ddt_phys_t *ddp, blkptr_t *bp, uint64_t txg)
|
|
|
|
{
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT3U(txg, !=, 0);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int d = 0; d < SPA_DVAS_PER_BP; d++)
|
2010-05-29 00:45:14 +04:00
|
|
|
bp->blk_dva[d] = ddp->ddp_dva[d];
|
|
|
|
BP_SET_BIRTH(bp, txg, ddp->ddp_phys_birth);
|
|
|
|
}
|
|
|
|
|
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 20:36:48 +03:00
|
|
|
/*
|
|
|
|
* The bp created via this function may be used for repairs and scrub, but it
|
|
|
|
* will be missing the salt / IV required to do a full decrypting read.
|
|
|
|
*/
|
2010-05-29 00:45:14 +04:00
|
|
|
void
|
|
|
|
ddt_bp_create(enum zio_checksum checksum,
|
|
|
|
const ddt_key_t *ddk, const ddt_phys_t *ddp, blkptr_t *bp)
|
|
|
|
{
|
|
|
|
BP_ZERO(bp);
|
|
|
|
|
|
|
|
if (ddp != NULL)
|
|
|
|
ddt_bp_fill(ddp, bp, ddp->ddp_phys_birth);
|
|
|
|
|
|
|
|
bp->blk_cksum = ddk->ddk_cksum;
|
|
|
|
|
|
|
|
BP_SET_LSIZE(bp, DDK_GET_LSIZE(ddk));
|
|
|
|
BP_SET_PSIZE(bp, DDK_GET_PSIZE(ddk));
|
|
|
|
BP_SET_COMPRESS(bp, DDK_GET_COMPRESS(ddk));
|
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 20:36:48 +03:00
|
|
|
BP_SET_CRYPT(bp, DDK_GET_CRYPT(ddk));
|
|
|
|
BP_SET_FILL(bp, 1);
|
2010-05-29 00:45:14 +04:00
|
|
|
BP_SET_CHECKSUM(bp, checksum);
|
|
|
|
BP_SET_TYPE(bp, DMU_OT_DEDUP);
|
|
|
|
BP_SET_LEVEL(bp, 0);
|
2019-01-18 02:25:00 +03:00
|
|
|
BP_SET_DEDUP(bp, 1);
|
2010-05-29 00:45:14 +04:00
|
|
|
BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_key_fill(ddt_key_t *ddk, const blkptr_t *bp)
|
|
|
|
{
|
|
|
|
ddk->ddk_cksum = bp->blk_cksum;
|
|
|
|
ddk->ddk_prop = 0;
|
|
|
|
|
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 20:36:48 +03:00
|
|
|
ASSERT(BP_IS_ENCRYPTED(bp) || !BP_USES_CRYPT(bp));
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
DDK_SET_LSIZE(ddk, BP_GET_LSIZE(bp));
|
|
|
|
DDK_SET_PSIZE(ddk, BP_GET_PSIZE(bp));
|
|
|
|
DDK_SET_COMPRESS(ddk, BP_GET_COMPRESS(bp));
|
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 20:36:48 +03:00
|
|
|
DDK_SET_CRYPT(ddk, BP_USES_CRYPT(bp));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_phys_fill(ddt_phys_t *ddp, const blkptr_t *bp)
|
|
|
|
{
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT0(ddp->ddp_phys_birth);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int d = 0; d < SPA_DVAS_PER_BP; d++)
|
2010-05-29 00:45:14 +04:00
|
|
|
ddp->ddp_dva[d] = bp->blk_dva[d];
|
|
|
|
ddp->ddp_phys_birth = BP_PHYSICAL_BIRTH(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_phys_clear(ddt_phys_t *ddp)
|
|
|
|
{
|
2022-02-25 16:26:54 +03:00
|
|
|
memset(ddp, 0, sizeof (*ddp));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_phys_addref(ddt_phys_t *ddp)
|
|
|
|
{
|
|
|
|
ddp->ddp_refcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_phys_decref(ddt_phys_t *ddp)
|
|
|
|
{
|
2013-03-19 23:05:08 +04:00
|
|
|
if (ddp) {
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT3U(ddp->ddp_refcnt, >, 0);
|
2013-03-19 23:05:08 +04:00
|
|
|
ddp->ddp_refcnt--;
|
|
|
|
}
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
2023-06-30 06:35:18 +03:00
|
|
|
static void
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_phys_free(ddt_t *ddt, ddt_key_t *ddk, ddt_phys_t *ddp, uint64_t txg)
|
|
|
|
{
|
|
|
|
blkptr_t blk;
|
|
|
|
|
|
|
|
ddt_bp_create(ddt->ddt_checksum, ddk, ddp, &blk);
|
2019-01-18 02:25:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We clear the dedup bit so that zio_free() will actually free the
|
|
|
|
* space, rather than just decrementing the refcount in the DDT.
|
|
|
|
*/
|
|
|
|
BP_SET_DEDUP(&blk, 0);
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_phys_clear(ddp);
|
|
|
|
zio_free(ddt->ddt_spa, txg, &blk);
|
|
|
|
}
|
|
|
|
|
|
|
|
ddt_phys_t *
|
|
|
|
ddt_phys_select(const ddt_entry_t *dde, const blkptr_t *bp)
|
|
|
|
{
|
|
|
|
ddt_phys_t *ddp = (ddt_phys_t *)dde->dde_phys;
|
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
|
2010-05-29 00:45:14 +04:00
|
|
|
if (DVA_EQUAL(BP_IDENTITY(bp), &ddp->ddp_dva[0]) &&
|
|
|
|
BP_PHYSICAL_BIRTH(bp) == ddp->ddp_phys_birth)
|
|
|
|
return (ddp);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
ddt_phys_total_refcnt(const ddt_entry_t *dde)
|
|
|
|
{
|
|
|
|
uint64_t refcnt = 0;
|
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int p = DDT_PHYS_SINGLE; p <= DDT_PHYS_TRIPLE; p++)
|
2010-05-29 00:45:14 +04:00
|
|
|
refcnt += dde->dde_phys[p].ddp_refcnt;
|
|
|
|
|
|
|
|
return (refcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
ddt_t *
|
|
|
|
ddt_select(spa_t *spa, const blkptr_t *bp)
|
|
|
|
{
|
2024-02-01 03:05:18 +03:00
|
|
|
ASSERT(DDT_CHECKSUM_VALID(BP_GET_CHECKSUM(bp)));
|
2010-05-29 00:45:14 +04:00
|
|
|
return (spa->spa_ddt[BP_GET_CHECKSUM(bp)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_enter(ddt_t *ddt)
|
|
|
|
{
|
|
|
|
mutex_enter(&ddt->ddt_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_exit(ddt_t *ddt)
|
|
|
|
{
|
|
|
|
mutex_exit(&ddt->ddt_lock);
|
|
|
|
}
|
|
|
|
|
2013-11-20 01:34:46 +04:00
|
|
|
void
|
|
|
|
ddt_init(void)
|
|
|
|
{
|
|
|
|
ddt_cache = kmem_cache_create("ddt_cache",
|
|
|
|
sizeof (ddt_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
|
|
|
|
ddt_entry_cache = kmem_cache_create("ddt_entry_cache",
|
|
|
|
sizeof (ddt_entry_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_fini(void)
|
|
|
|
{
|
|
|
|
kmem_cache_destroy(ddt_entry_cache);
|
|
|
|
kmem_cache_destroy(ddt_cache);
|
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
static ddt_entry_t *
|
|
|
|
ddt_alloc(const ddt_key_t *ddk)
|
|
|
|
{
|
|
|
|
ddt_entry_t *dde;
|
|
|
|
|
2014-11-21 03:09:39 +03:00
|
|
|
dde = kmem_cache_alloc(ddt_entry_cache, KM_SLEEP);
|
2022-02-25 16:26:54 +03:00
|
|
|
memset(dde, 0, sizeof (ddt_entry_t));
|
2010-05-29 00:45:14 +04:00
|
|
|
cv_init(&dde->dde_cv, NULL, CV_DEFAULT, NULL);
|
|
|
|
|
|
|
|
dde->dde_key = *ddk;
|
|
|
|
|
|
|
|
return (dde);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ddt_free(ddt_entry_t *dde)
|
|
|
|
{
|
2023-12-05 06:28:39 +03:00
|
|
|
ASSERT(dde->dde_flags & DDE_FLAG_LOADED);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int p = 0; p < DDT_PHYS_TYPES; p++)
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT3P(dde->dde_lead_zio[p], ==, NULL);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2016-07-22 18:52:49 +03:00
|
|
|
if (dde->dde_repair_abd != NULL)
|
|
|
|
abd_free(dde->dde_repair_abd);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
cv_destroy(&dde->dde_cv);
|
2013-11-20 01:34:46 +04:00
|
|
|
kmem_cache_free(ddt_entry_cache, dde);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_remove(ddt_t *ddt, ddt_entry_t *dde)
|
|
|
|
{
|
|
|
|
ASSERT(MUTEX_HELD(&ddt->ddt_lock));
|
|
|
|
|
|
|
|
avl_remove(&ddt->ddt_tree, dde);
|
|
|
|
ddt_free(dde);
|
|
|
|
}
|
|
|
|
|
|
|
|
ddt_entry_t *
|
|
|
|
ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add)
|
|
|
|
{
|
2023-06-09 03:14:42 +03:00
|
|
|
ddt_key_t search;
|
|
|
|
ddt_entry_t *dde;
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_type_t type;
|
|
|
|
ddt_class_t class;
|
2010-05-29 00:45:14 +04:00
|
|
|
avl_index_t where;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ASSERT(MUTEX_HELD(&ddt->ddt_lock));
|
|
|
|
|
2023-06-09 03:14:42 +03:00
|
|
|
ddt_key_fill(&search, bp);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2023-12-05 06:28:39 +03:00
|
|
|
/* Find an existing live entry */
|
2023-06-09 03:14:42 +03:00
|
|
|
dde = avl_find(&ddt->ddt_tree, &search, &where);
|
2023-12-05 06:28:39 +03:00
|
|
|
if (dde != NULL) {
|
|
|
|
/* Found it. If it's already loaded, we can just return it. */
|
|
|
|
if (dde->dde_flags & DDE_FLAG_LOADED)
|
|
|
|
return (dde);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2023-12-05 06:28:39 +03:00
|
|
|
/* Someone else is loading it, wait for it. */
|
|
|
|
while (!(dde->dde_flags & DDE_FLAG_LOADED))
|
|
|
|
cv_wait(&dde->dde_cv, &ddt->ddt_lock);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
return (dde);
|
2023-12-05 06:28:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Not found. */
|
|
|
|
if (!add)
|
|
|
|
return (NULL);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2023-12-05 06:28:39 +03:00
|
|
|
/* Time to make a new entry. */
|
|
|
|
dde = ddt_alloc(&search);
|
|
|
|
avl_insert(&ddt->ddt_tree, dde, where);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2023-12-05 06:28:39 +03:00
|
|
|
/*
|
|
|
|
* ddt_tree is now stable, so unlock and let everyone else keep moving.
|
|
|
|
* Anyone landing on this entry will find it without DDE_FLAG_LOADED,
|
|
|
|
* and go to sleep waiting for it above.
|
|
|
|
*/
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_exit(ddt);
|
|
|
|
|
2023-12-05 06:28:39 +03:00
|
|
|
/* Search all store objects for the entry. */
|
2010-05-29 00:45:14 +04:00
|
|
|
error = ENOENT;
|
|
|
|
for (type = 0; type < DDT_TYPES; type++) {
|
|
|
|
for (class = 0; class < DDT_CLASSES; class++) {
|
|
|
|
error = ddt_object_lookup(ddt, type, class, dde);
|
OpenZFS 7614, 9064 - zfs device evacuation/removal
OpenZFS 7614 - zfs device evacuation/removal
OpenZFS 9064 - remove_mirror should wait for device removal to complete
This project allows top-level vdevs to be removed from the storage pool
with "zpool remove", reducing the total amount of storage in the pool.
This operation copies all allocated regions of the device to be removed
onto other devices, recording the mapping from old to new location.
After the removal is complete, read and free operations to the removed
(now "indirect") vdev must be remapped and performed at the new location
on disk. The indirect mapping table is kept in memory whenever the pool
is loaded, so there is minimal performance overhead when doing operations
on the indirect vdev.
The size of the in-memory mapping table will be reduced when its entries
become "obsolete" because they are no longer used by any block pointers
in the pool. An entry becomes obsolete when all the blocks that use
it are freed. An entry can also become obsolete when all the snapshots
that reference it are deleted, and the block pointers that reference it
have been "remapped" in all filesystems/zvols (and clones). Whenever an
indirect block is written, all the block pointers in it will be "remapped"
to their new (concrete) locations if possible. This process can be
accelerated by using the "zfs remap" command to proactively rewrite all
indirect blocks that reference indirect (removed) vdevs.
Note that when a device is removed, we do not verify the checksum of
the data that is copied. This makes the process much faster, but if it
were used on redundant vdevs (i.e. mirror or raidz vdevs), it would be
possible to copy the wrong data, when we have the correct data on e.g.
the other side of the mirror.
At the moment, only mirrors and simple top-level vdevs can be removed
and no removal is allowed if any of the top-level vdevs are raidz.
Porting Notes:
* Avoid zero-sized kmem_alloc() in vdev_compact_children().
The device evacuation code adds a dependency that
vdev_compact_children() be able to properly empty the vdev_child
array by setting it to NULL and zeroing vdev_children. Under Linux,
kmem_alloc() and related functions return a sentinel pointer rather
than NULL for zero-sized allocations.
* Remove comment regarding "mpt" driver where zfs_remove_max_segment
is initialized to SPA_MAXBLOCKSIZE.
Change zfs_condense_indirect_commit_entry_delay_ticks to
zfs_condense_indirect_commit_entry_delay_ms for consistency with
most other tunables in which delays are specified in ms.
* ZTS changes:
Use set_tunable rather than mdb
Use zpool sync as appropriate
Use sync_pool instead of sync
Kill jobs during test_removal_with_operation to allow unmount/export
Don't add non-disk names such as "mirror" or "raidz" to $DISKS
Use $TEST_BASE_DIR instead of /tmp
Increase HZ from 100 to 1000 which is more common on Linux
removal_multiple_indirection.ksh
Reduce iterations in order to not time out on the code
coverage builders.
removal_resume_export:
Functionally, the test case is correct but there exists a race
where the kernel thread hasn't been fully started yet and is
not visible. Wait for up to 1 second for the removal thread
to be started before giving up on it. Also, increase the
amount of data copied in order that the removal not finish
before the export has a chance to fail.
* MMP compatibility, the concept of concrete versus non-concrete devices
has slightly changed the semantics of vdev_writeable(). Update
mmp_random_leaf_impl() accordingly.
* Updated dbuf_remap() to handle the org.zfsonlinux:large_dnode pool
feature which is not supported by OpenZFS.
* Added support for new vdev removal tracepoints.
* Test cases removal_with_zdb and removal_condense_export have been
intentionally disabled. When run manually they pass as intended,
but when running in the automated test environment they produce
unreliable results on the latest Fedora release.
They may work better once the upstream pool import refectoring is
merged into ZoL at which point they will be re-enabled.
Authored by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Alex Reece <alex@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Richard Laager <rlaager@wiktel.com>
Reviewed by: Tim Chase <tim@chase2k.com>
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Garrett D'Amore <garrett@damore.org>
Ported-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Tim Chase <tim@chase2k.com>
OpenZFS-issue: https://www.illumos.org/issues/7614
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/f539f1eb
Closes #6900
2016-09-22 19:30:13 +03:00
|
|
|
if (error != ENOENT) {
|
|
|
|
ASSERT0(error);
|
2010-05-29 00:45:14 +04:00
|
|
|
break;
|
OpenZFS 7614, 9064 - zfs device evacuation/removal
OpenZFS 7614 - zfs device evacuation/removal
OpenZFS 9064 - remove_mirror should wait for device removal to complete
This project allows top-level vdevs to be removed from the storage pool
with "zpool remove", reducing the total amount of storage in the pool.
This operation copies all allocated regions of the device to be removed
onto other devices, recording the mapping from old to new location.
After the removal is complete, read and free operations to the removed
(now "indirect") vdev must be remapped and performed at the new location
on disk. The indirect mapping table is kept in memory whenever the pool
is loaded, so there is minimal performance overhead when doing operations
on the indirect vdev.
The size of the in-memory mapping table will be reduced when its entries
become "obsolete" because they are no longer used by any block pointers
in the pool. An entry becomes obsolete when all the blocks that use
it are freed. An entry can also become obsolete when all the snapshots
that reference it are deleted, and the block pointers that reference it
have been "remapped" in all filesystems/zvols (and clones). Whenever an
indirect block is written, all the block pointers in it will be "remapped"
to their new (concrete) locations if possible. This process can be
accelerated by using the "zfs remap" command to proactively rewrite all
indirect blocks that reference indirect (removed) vdevs.
Note that when a device is removed, we do not verify the checksum of
the data that is copied. This makes the process much faster, but if it
were used on redundant vdevs (i.e. mirror or raidz vdevs), it would be
possible to copy the wrong data, when we have the correct data on e.g.
the other side of the mirror.
At the moment, only mirrors and simple top-level vdevs can be removed
and no removal is allowed if any of the top-level vdevs are raidz.
Porting Notes:
* Avoid zero-sized kmem_alloc() in vdev_compact_children().
The device evacuation code adds a dependency that
vdev_compact_children() be able to properly empty the vdev_child
array by setting it to NULL and zeroing vdev_children. Under Linux,
kmem_alloc() and related functions return a sentinel pointer rather
than NULL for zero-sized allocations.
* Remove comment regarding "mpt" driver where zfs_remove_max_segment
is initialized to SPA_MAXBLOCKSIZE.
Change zfs_condense_indirect_commit_entry_delay_ticks to
zfs_condense_indirect_commit_entry_delay_ms for consistency with
most other tunables in which delays are specified in ms.
* ZTS changes:
Use set_tunable rather than mdb
Use zpool sync as appropriate
Use sync_pool instead of sync
Kill jobs during test_removal_with_operation to allow unmount/export
Don't add non-disk names such as "mirror" or "raidz" to $DISKS
Use $TEST_BASE_DIR instead of /tmp
Increase HZ from 100 to 1000 which is more common on Linux
removal_multiple_indirection.ksh
Reduce iterations in order to not time out on the code
coverage builders.
removal_resume_export:
Functionally, the test case is correct but there exists a race
where the kernel thread hasn't been fully started yet and is
not visible. Wait for up to 1 second for the removal thread
to be started before giving up on it. Also, increase the
amount of data copied in order that the removal not finish
before the export has a chance to fail.
* MMP compatibility, the concept of concrete versus non-concrete devices
has slightly changed the semantics of vdev_writeable(). Update
mmp_random_leaf_impl() accordingly.
* Updated dbuf_remap() to handle the org.zfsonlinux:large_dnode pool
feature which is not supported by OpenZFS.
* Added support for new vdev removal tracepoints.
* Test cases removal_with_zdb and removal_condense_export have been
intentionally disabled. When run manually they pass as intended,
but when running in the automated test environment they produce
unreliable results on the latest Fedora release.
They may work better once the upstream pool import refectoring is
merged into ZoL at which point they will be re-enabled.
Authored by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Alex Reece <alex@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Richard Laager <rlaager@wiktel.com>
Reviewed by: Tim Chase <tim@chase2k.com>
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Garrett D'Amore <garrett@damore.org>
Ported-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Tim Chase <tim@chase2k.com>
OpenZFS-issue: https://www.illumos.org/issues/7614
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/f539f1eb
Closes #6900
2016-09-22 19:30:13 +03:00
|
|
|
}
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
if (error != ENOENT)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ddt_enter(ddt);
|
|
|
|
|
2023-12-05 06:28:39 +03:00
|
|
|
ASSERT(!(dde->dde_flags & DDE_FLAG_LOADED));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
dde->dde_type = type; /* will be DDT_TYPES if no entry found */
|
|
|
|
dde->dde_class = class; /* will be DDT_CLASSES if no entry found */
|
|
|
|
|
|
|
|
if (error == 0)
|
|
|
|
ddt_stat_update(ddt, dde, -1ULL);
|
|
|
|
|
2023-12-05 06:28:39 +03:00
|
|
|
/* Entry loaded, everyone can proceed now */
|
|
|
|
dde->dde_flags |= DDE_FLAG_LOADED;
|
2010-05-29 00:45:14 +04:00
|
|
|
cv_broadcast(&dde->dde_cv);
|
|
|
|
|
|
|
|
return (dde);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_prefetch(spa_t *spa, const blkptr_t *bp)
|
|
|
|
{
|
|
|
|
ddt_t *ddt;
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt_key_t ddk;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
if (!zfs_dedup_prefetch || bp == NULL || !BP_GET_DEDUP(bp))
|
2010-05-29 00:45:14 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
2010-08-27 01:24:34 +04:00
|
|
|
* We only remove the DDT once all tables are empty and only
|
|
|
|
* prefetch dedup blocks when there are entries in the DDT.
|
|
|
|
* Thus no locking is required as the DDT can't disappear on us.
|
2010-05-29 00:45:14 +04:00
|
|
|
*/
|
|
|
|
ddt = ddt_select(spa, bp);
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt_key_fill(&ddk, bp);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2023-07-03 05:32:53 +03:00
|
|
|
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
|
|
|
|
for (ddt_class_t class = 0; class < DDT_CLASSES; class++) {
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt_object_prefetch(ddt, type, class, &ddk);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 21:12:53 +03:00
|
|
|
/*
|
2023-06-09 03:14:42 +03:00
|
|
|
* Key comparison. Any struct wanting to make use of this function must have
|
|
|
|
* the key as the first element.
|
2016-08-27 21:12:53 +03:00
|
|
|
*/
|
|
|
|
#define DDT_KEY_CMP_LEN (sizeof (ddt_key_t) / sizeof (uint16_t))
|
|
|
|
|
|
|
|
typedef struct ddt_key_cmp {
|
|
|
|
uint16_t u16[DDT_KEY_CMP_LEN];
|
|
|
|
} ddt_key_cmp_t;
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
int
|
2023-06-09 03:14:42 +03:00
|
|
|
ddt_key_compare(const void *x1, const void *x2)
|
2010-05-29 00:45:14 +04:00
|
|
|
{
|
2023-06-09 03:14:42 +03:00
|
|
|
const ddt_key_cmp_t *k1 = (const ddt_key_cmp_t *)x1;
|
|
|
|
const ddt_key_cmp_t *k2 = (const ddt_key_cmp_t *)x2;
|
2016-08-27 21:12:53 +03:00
|
|
|
int32_t cmp = 0;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int i = 0; i < DDT_KEY_CMP_LEN; i++) {
|
2016-08-27 21:12:53 +03:00
|
|
|
cmp = (int32_t)k1->u16[i] - (int32_t)k2->u16[i];
|
|
|
|
if (likely(cmp))
|
|
|
|
break;
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
Reduce loaded range tree memory usage
This patch implements a new tree structure for ZFS, and uses it to
store range trees more efficiently.
The new structure is approximately a B-tree, though there are some
small differences from the usual characterizations. The tree has core
nodes and leaf nodes; each contain data elements, which the elements
in the core nodes acting as separators between its children. The
difference between core and leaf nodes is that the core nodes have an
array of children, while leaf nodes don't. Every node in the tree may
be only partially full; in most cases, they are all at least 50% full
(in terms of element count) except for the root node, which can be
less full. Underfull nodes will steal from their neighbors or merge to
remain full enough, while overfull nodes will split in two. The data
elements are contained in tree-controlled buffers; they are copied
into these on insertion, and overwritten on deletion. This means that
the elements are not independently allocated, which reduces overhead,
but also means they can't be shared between trees (and also that
pointers to them are only valid until a side-effectful tree operation
occurs). The overhead varies based on how dense the tree is, but is
usually on the order of about 50% of the element size; the per-node
overheads are very small, and so don't make a significant difference.
The trees can accept arbitrary records; they accept a size and a
comparator to allow them to be used for a variety of purposes.
The new trees replace the AVL trees used in the range trees today.
Currently, the range_seg_t structure contains three 8 byte integers
of payload and two 24 byte avl_tree_node_ts to handle its storage in
both an offset-sorted tree and a size-sorted tree (total size: 64
bytes). In the new model, the range seg structures are usually two 4
byte integers, but a separate one needs to exist for the size-sorted
and offset-sorted tree. Between the raw size, the 50% overhead, and
the double storage, the new btrees are expected to use 8*1.5*2 = 24
bytes per record, or 33.3% as much memory as the AVL trees (this is
for the purposes of storing metaslab range trees; for other purposes,
like scrubs, they use ~50% as much memory).
We reduced the size of the payload in the range segments by teaching
range trees about starting offsets and shifts; since metaslabs have a
fixed starting offset, and they all operate in terms of disk sectors,
we can store the ranges using 4-byte integers as long as the size of
the metaslab divided by the sector size is less than 2^32. For 512-byte
sectors, this is a 2^41 (or 2TB) metaslab, which with the default
settings corresponds to a 256PB disk. 4k sector disks can handle
metaslabs up to 2^46 bytes, or 2^63 byte disks. Since we do not
anticipate disks of this size in the near future, there should be
almost no cases where metaslabs need 64-byte integers to store their
ranges. We do still have the capability to store 64-byte integer ranges
to account for cases where we are storing per-vdev (or per-dnode) trees,
which could reasonably go above the limits discussed. We also do not
store fill information in the compact version of the node, since it
is only used for sorted scrub.
We also optimized the metaslab loading process in various other ways
to offset some inefficiencies in the btree model. While individual
operations (find, insert, remove_from) are faster for the btree than
they are for the avl tree, remove usually requires a find operation,
while in the AVL tree model the element itself suffices. Some clever
changes actually caused an overall speedup in metaslab loading; we use
approximately 40% less cpu to load metaslabs in our tests on Illumos.
Another memory and performance optimization was achieved by changing
what is stored in the size-sorted trees. When a disk is heavily
fragmented, the df algorithm used by default in ZFS will almost always
find a number of small regions in its initial cursor-based search; it
will usually only fall back to the size-sorted tree to find larger
regions. If we increase the size of the cursor-based search slightly,
and don't store segments that are smaller than a tunable size floor
in the size-sorted tree, we can further cut memory usage down to
below 20% of what the AVL trees store. This also results in further
reductions in CPU time spent loading metaslabs.
The 16KiB size floor was chosen because it results in substantial memory
usage reduction while not usually resulting in situations where we can't
find an appropriate chunk with the cursor and are forced to use an
oversized chunk from the size-sorted tree. In addition, even if we do
have to use an oversized chunk from the size-sorted tree, the chunk
would be too small to use for ZIL allocations, so it isn't as big of a
loss as it might otherwise be. And often, more small allocations will
follow the initial one, and the cursor search will now find the
remainder of the chunk we didn't use all of and use it for subsequent
allocations. Practical testing has shown little or no change in
fragmentation as a result of this change.
If the size-sorted tree becomes empty while the offset sorted one still
has entries, it will load all the entries from the offset sorted tree
and disregard the size floor until it is unloaded again. This operation
occurs rarely with the default setting, only on incredibly thoroughly
fragmented pools.
There are some other small changes to zdb to teach it to handle btrees,
but nothing major.
Reviewed-by: George Wilson <gwilson@delphix.com>
Reviewed-by: Matt Ahrens <matt@delphix.com>
Reviewed by: Sebastien Roy seb@delphix.com
Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #9181
2019-10-09 20:36:03 +03:00
|
|
|
return (TREE_ISIGN(cmp));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static ddt_t *
|
|
|
|
ddt_table_alloc(spa_t *spa, enum zio_checksum c)
|
|
|
|
{
|
|
|
|
ddt_t *ddt;
|
|
|
|
|
2014-11-21 03:09:39 +03:00
|
|
|
ddt = kmem_cache_alloc(ddt_cache, KM_SLEEP);
|
2022-02-25 16:26:54 +03:00
|
|
|
memset(ddt, 0, sizeof (ddt_t));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
mutex_init(&ddt->ddt_lock, NULL, MUTEX_DEFAULT, NULL);
|
2023-06-09 03:14:42 +03:00
|
|
|
avl_create(&ddt->ddt_tree, ddt_key_compare,
|
2010-05-29 00:45:14 +04:00
|
|
|
sizeof (ddt_entry_t), offsetof(ddt_entry_t, dde_node));
|
2023-06-09 03:14:42 +03:00
|
|
|
avl_create(&ddt->ddt_repair_tree, ddt_key_compare,
|
2010-05-29 00:45:14 +04:00
|
|
|
sizeof (ddt_entry_t), offsetof(ddt_entry_t, dde_node));
|
|
|
|
ddt->ddt_checksum = c;
|
|
|
|
ddt->ddt_spa = spa;
|
|
|
|
ddt->ddt_os = spa->spa_meta_objset;
|
|
|
|
|
|
|
|
return (ddt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ddt_table_free(ddt_t *ddt)
|
|
|
|
{
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT0(avl_numnodes(&ddt->ddt_tree));
|
|
|
|
ASSERT0(avl_numnodes(&ddt->ddt_repair_tree));
|
2010-05-29 00:45:14 +04:00
|
|
|
avl_destroy(&ddt->ddt_tree);
|
|
|
|
avl_destroy(&ddt->ddt_repair_tree);
|
|
|
|
mutex_destroy(&ddt->ddt_lock);
|
2013-11-20 01:34:46 +04:00
|
|
|
kmem_cache_free(ddt_cache, ddt);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_create(spa_t *spa)
|
|
|
|
{
|
|
|
|
spa->spa_dedup_checksum = ZIO_DEDUPCHECKSUM;
|
|
|
|
|
2024-02-01 03:05:18 +03:00
|
|
|
for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
|
|
|
|
if (DDT_CHECKSUM_VALID(c))
|
|
|
|
spa->spa_ddt[c] = ddt_table_alloc(spa, c);
|
|
|
|
}
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ddt_load(spa_t *spa)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ddt_create(spa);
|
|
|
|
|
|
|
|
error = zap_lookup(spa->spa_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
|
|
|
|
DMU_POOL_DDT_STATS, sizeof (uint64_t), 1,
|
|
|
|
&spa->spa_ddt_stat_object);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
return (error == ENOENT ? 0 : error);
|
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
|
2024-02-01 03:05:18 +03:00
|
|
|
if (!DDT_CHECKSUM_VALID(c))
|
|
|
|
continue;
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_t *ddt = spa->spa_ddt[c];
|
2023-07-03 05:32:53 +03:00
|
|
|
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
|
|
|
|
for (ddt_class_t class = 0; class < DDT_CLASSES;
|
2010-05-29 00:45:14 +04:00
|
|
|
class++) {
|
|
|
|
error = ddt_object_load(ddt, type, class);
|
|
|
|
if (error != 0 && error != ENOENT)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Seed the cached histograms.
|
|
|
|
*/
|
2022-02-25 16:26:54 +03:00
|
|
|
memcpy(&ddt->ddt_histogram_cache, ddt->ddt_histogram,
|
2010-05-29 00:45:14 +04:00
|
|
|
sizeof (ddt->ddt_histogram));
|
2016-12-03 02:59:35 +03:00
|
|
|
spa->spa_dedup_dspace = ~0ULL;
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_unload(spa_t *spa)
|
|
|
|
{
|
2017-11-04 23:25:13 +03:00
|
|
|
for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
|
2010-05-29 00:45:14 +04:00
|
|
|
if (spa->spa_ddt[c]) {
|
|
|
|
ddt_table_free(spa->spa_ddt[c]);
|
|
|
|
spa->spa_ddt[c] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean_t
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_class_contains(spa_t *spa, ddt_class_t max_class, const blkptr_t *bp)
|
2010-05-29 00:45:14 +04:00
|
|
|
{
|
|
|
|
ddt_t *ddt;
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt_key_t ddk;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
if (!BP_GET_DEDUP(bp))
|
|
|
|
return (B_FALSE);
|
|
|
|
|
|
|
|
if (max_class == DDT_CLASS_UNIQUE)
|
|
|
|
return (B_TRUE);
|
|
|
|
|
|
|
|
ddt = spa->spa_ddt[BP_GET_CHECKSUM(bp)];
|
|
|
|
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt_key_fill(&ddk, bp);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2023-07-03 05:32:53 +03:00
|
|
|
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
|
|
|
|
for (ddt_class_t class = 0; class <= max_class; class++) {
|
2023-07-03 16:28:46 +03:00
|
|
|
if (ddt_object_contains(ddt, type, class, &ddk) == 0)
|
2010-05-29 00:45:14 +04:00
|
|
|
return (B_TRUE);
|
2011-05-26 00:56:40 +04:00
|
|
|
}
|
|
|
|
}
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
return (B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ddt_entry_t *
|
|
|
|
ddt_repair_start(ddt_t *ddt, const blkptr_t *bp)
|
|
|
|
{
|
|
|
|
ddt_key_t ddk;
|
|
|
|
ddt_entry_t *dde;
|
|
|
|
|
|
|
|
ddt_key_fill(&ddk, bp);
|
|
|
|
|
|
|
|
dde = ddt_alloc(&ddk);
|
|
|
|
|
2023-07-03 05:32:53 +03:00
|
|
|
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
|
|
|
|
for (ddt_class_t class = 0; class < DDT_CLASSES; class++) {
|
2010-05-29 00:45:14 +04:00
|
|
|
/*
|
|
|
|
* We can only do repair if there are multiple copies
|
|
|
|
* of the block. For anything in the UNIQUE class,
|
|
|
|
* there's definitely only one copy, so don't even try.
|
|
|
|
*/
|
|
|
|
if (class != DDT_CLASS_UNIQUE &&
|
|
|
|
ddt_object_lookup(ddt, type, class, dde) == 0)
|
|
|
|
return (dde);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 16:26:54 +03:00
|
|
|
memset(dde->dde_phys, 0, sizeof (dde->dde_phys));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
return (dde);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_repair_done(ddt_t *ddt, ddt_entry_t *dde)
|
|
|
|
{
|
|
|
|
avl_index_t where;
|
|
|
|
|
|
|
|
ddt_enter(ddt);
|
|
|
|
|
2016-07-22 18:52:49 +03:00
|
|
|
if (dde->dde_repair_abd != NULL && spa_writeable(ddt->ddt_spa) &&
|
2010-05-29 00:45:14 +04:00
|
|
|
avl_find(&ddt->ddt_repair_tree, dde, &where) == NULL)
|
|
|
|
avl_insert(&ddt->ddt_repair_tree, dde, where);
|
|
|
|
else
|
|
|
|
ddt_free(dde);
|
|
|
|
|
|
|
|
ddt_exit(ddt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ddt_repair_entry_done(zio_t *zio)
|
|
|
|
{
|
|
|
|
ddt_entry_t *rdde = zio->io_private;
|
|
|
|
|
|
|
|
ddt_free(rdde);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ddt_repair_entry(ddt_t *ddt, ddt_entry_t *dde, ddt_entry_t *rdde, zio_t *rio)
|
|
|
|
{
|
|
|
|
ddt_phys_t *ddp = dde->dde_phys;
|
|
|
|
ddt_phys_t *rddp = rdde->dde_phys;
|
|
|
|
ddt_key_t *ddk = &dde->dde_key;
|
|
|
|
ddt_key_t *rddk = &rdde->dde_key;
|
|
|
|
zio_t *zio;
|
|
|
|
blkptr_t blk;
|
|
|
|
|
|
|
|
zio = zio_null(rio, rio->io_spa, NULL,
|
|
|
|
ddt_repair_entry_done, rdde, rio->io_flags);
|
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++, rddp++) {
|
2010-05-29 00:45:14 +04:00
|
|
|
if (ddp->ddp_phys_birth == 0 ||
|
|
|
|
ddp->ddp_phys_birth != rddp->ddp_phys_birth ||
|
2022-02-25 16:26:54 +03:00
|
|
|
memcmp(ddp->ddp_dva, rddp->ddp_dva, sizeof (ddp->ddp_dva)))
|
2010-05-29 00:45:14 +04:00
|
|
|
continue;
|
|
|
|
ddt_bp_create(ddt->ddt_checksum, ddk, ddp, &blk);
|
|
|
|
zio_nowait(zio_rewrite(zio, zio->io_spa, 0, &blk,
|
2016-07-22 18:52:49 +03:00
|
|
|
rdde->dde_repair_abd, DDK_GET_PSIZE(rddk), NULL, NULL,
|
2010-05-29 00:45:14 +04:00
|
|
|
ZIO_PRIORITY_SYNC_WRITE, ZIO_DDT_CHILD_FLAGS(zio), NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
zio_nowait(zio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ddt_repair_table(ddt_t *ddt, zio_t *rio)
|
|
|
|
{
|
|
|
|
spa_t *spa = ddt->ddt_spa;
|
|
|
|
ddt_entry_t *dde, *rdde_next, *rdde;
|
|
|
|
avl_tree_t *t = &ddt->ddt_repair_tree;
|
|
|
|
blkptr_t blk;
|
|
|
|
|
|
|
|
if (spa_sync_pass(spa) > 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ddt_enter(ddt);
|
|
|
|
for (rdde = avl_first(t); rdde != NULL; rdde = rdde_next) {
|
|
|
|
rdde_next = AVL_NEXT(t, rdde);
|
|
|
|
avl_remove(&ddt->ddt_repair_tree, rdde);
|
|
|
|
ddt_exit(ddt);
|
|
|
|
ddt_bp_create(ddt->ddt_checksum, &rdde->dde_key, NULL, &blk);
|
|
|
|
dde = ddt_repair_start(ddt, &blk);
|
|
|
|
ddt_repair_entry(ddt, dde, rdde, rio);
|
|
|
|
ddt_repair_done(ddt, dde);
|
|
|
|
ddt_enter(ddt);
|
|
|
|
}
|
|
|
|
ddt_exit(ddt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ddt_sync_entry(ddt_t *ddt, ddt_entry_t *dde, dmu_tx_t *tx, uint64_t txg)
|
|
|
|
{
|
|
|
|
dsl_pool_t *dp = ddt->ddt_spa->spa_dsl_pool;
|
|
|
|
ddt_phys_t *ddp = dde->dde_phys;
|
|
|
|
ddt_key_t *ddk = &dde->dde_key;
|
2023-07-03 05:32:53 +03:00
|
|
|
ddt_type_t otype = dde->dde_type;
|
|
|
|
ddt_type_t ntype = DDT_TYPE_DEFAULT;
|
|
|
|
ddt_class_t oclass = dde->dde_class;
|
|
|
|
ddt_class_t nclass;
|
2010-05-29 00:45:14 +04:00
|
|
|
uint64_t total_refcnt = 0;
|
|
|
|
|
2023-12-05 06:28:39 +03:00
|
|
|
ASSERT(dde->dde_flags & DDE_FLAG_LOADED);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT3P(dde->dde_lead_zio[p], ==, NULL);
|
2010-05-29 00:45:14 +04:00
|
|
|
if (ddp->ddp_phys_birth == 0) {
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT0(ddp->ddp_refcnt);
|
2010-05-29 00:45:14 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (p == DDT_PHYS_DITTO) {
|
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-20 00:54:02 +03:00
|
|
|
/*
|
|
|
|
* Note, we no longer create DDT-DITTO blocks, but we
|
|
|
|
* don't want to leak any written by older software.
|
|
|
|
*/
|
|
|
|
ddt_phys_free(ddt, ddk, ddp, txg);
|
2010-05-29 00:45:14 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ddp->ddp_refcnt == 0)
|
|
|
|
ddt_phys_free(ddt, ddk, ddp, txg);
|
|
|
|
total_refcnt += ddp->ddp_refcnt;
|
|
|
|
}
|
|
|
|
|
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-20 00:54:02 +03:00
|
|
|
/* We do not create new DDT-DITTO blocks. */
|
|
|
|
ASSERT0(dde->dde_phys[DDT_PHYS_DITTO].ddp_phys_birth);
|
|
|
|
if (total_refcnt > 1)
|
2010-05-29 00:45:14 +04:00
|
|
|
nclass = DDT_CLASS_DUPLICATE;
|
|
|
|
else
|
|
|
|
nclass = DDT_CLASS_UNIQUE;
|
|
|
|
|
|
|
|
if (otype != DDT_TYPES &&
|
|
|
|
(otype != ntype || oclass != nclass || total_refcnt == 0)) {
|
2023-07-03 16:28:46 +03:00
|
|
|
VERIFY0(ddt_object_remove(ddt, otype, oclass, ddk, tx));
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT3U(
|
2023-07-03 16:28:46 +03:00
|
|
|
ddt_object_contains(ddt, otype, oclass, ddk), ==, ENOENT);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (total_refcnt != 0) {
|
|
|
|
dde->dde_type = ntype;
|
|
|
|
dde->dde_class = nclass;
|
|
|
|
ddt_stat_update(ddt, dde, 0);
|
|
|
|
if (!ddt_object_exists(ddt, ntype, nclass))
|
|
|
|
ddt_object_create(ddt, ntype, nclass, tx);
|
2024-02-15 11:37:38 +03:00
|
|
|
VERIFY0(ddt_object_update(ddt, ntype, nclass, dde, tx));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the class changes, the order that we scan this bp
|
|
|
|
* changes. If it decreases, we could miss it, so
|
|
|
|
* scan it right now. (This covers both class changing
|
|
|
|
* while we are doing ddt_walk(), and when we are
|
|
|
|
* traversing.)
|
|
|
|
*/
|
|
|
|
if (nclass < oclass) {
|
|
|
|
dsl_scan_ddt_entry(dp->dp_scan,
|
|
|
|
ddt->ddt_checksum, dde, tx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ddt_sync_table(ddt_t *ddt, dmu_tx_t *tx, uint64_t txg)
|
|
|
|
{
|
|
|
|
spa_t *spa = ddt->ddt_spa;
|
|
|
|
ddt_entry_t *dde;
|
|
|
|
void *cookie = NULL;
|
|
|
|
|
|
|
|
if (avl_numnodes(&ddt->ddt_tree) == 0)
|
|
|
|
return;
|
|
|
|
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT3U(spa->spa_uberblock.ub_version, >=, SPA_VERSION_DEDUP);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
if (spa->spa_ddt_stat_object == 0) {
|
2012-12-14 03:24:15 +04:00
|
|
|
spa->spa_ddt_stat_object = zap_create_link(ddt->ddt_os,
|
|
|
|
DMU_OT_DDT_STATS, DMU_POOL_DIRECTORY_OBJECT,
|
|
|
|
DMU_POOL_DDT_STATS, tx);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((dde = avl_destroy_nodes(&ddt->ddt_tree, &cookie)) != NULL) {
|
|
|
|
ddt_sync_entry(ddt, dde, tx, txg);
|
|
|
|
ddt_free(dde);
|
|
|
|
}
|
|
|
|
|
2023-07-03 05:32:53 +03:00
|
|
|
for (ddt_type_t type = 0; type < DDT_TYPES; type++) {
|
2012-10-26 21:01:49 +04:00
|
|
|
uint64_t add, count = 0;
|
2023-07-03 05:32:53 +03:00
|
|
|
for (ddt_class_t class = 0; class < DDT_CLASSES; class++) {
|
2010-08-27 01:24:34 +04:00
|
|
|
if (ddt_object_exists(ddt, type, class)) {
|
|
|
|
ddt_object_sync(ddt, type, class, tx);
|
2024-02-15 11:37:38 +03:00
|
|
|
VERIFY0(ddt_object_count(ddt, type, class,
|
|
|
|
&add));
|
2012-10-26 21:01:49 +04:00
|
|
|
count += add;
|
2010-08-27 01:24:34 +04:00
|
|
|
}
|
|
|
|
}
|
2023-07-03 05:32:53 +03:00
|
|
|
for (ddt_class_t class = 0; class < DDT_CLASSES; class++) {
|
2010-08-27 01:24:34 +04:00
|
|
|
if (count == 0 && ddt_object_exists(ddt, type, class))
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_object_destroy(ddt, type, class, tx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 16:26:54 +03:00
|
|
|
memcpy(&ddt->ddt_histogram_cache, ddt->ddt_histogram,
|
2010-05-29 00:45:14 +04:00
|
|
|
sizeof (ddt->ddt_histogram));
|
2016-12-03 02:59:35 +03:00
|
|
|
spa->spa_dedup_dspace = ~0ULL;
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ddt_sync(spa_t *spa, uint64_t txg)
|
|
|
|
{
|
2017-11-16 04:27:01 +03:00
|
|
|
dsl_scan_t *scn = spa->spa_dsl_pool->dp_scan;
|
2010-05-29 00:45:14 +04:00
|
|
|
dmu_tx_t *tx;
|
2017-11-16 04:27:01 +03:00
|
|
|
zio_t *rio;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT3U(spa_syncing_txg(spa), ==, txg);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
tx = dmu_tx_create_assigned(spa->spa_dsl_pool, txg);
|
|
|
|
|
2017-11-16 04:27:01 +03:00
|
|
|
rio = zio_root(spa, NULL, NULL,
|
OpenZFS 7614, 9064 - zfs device evacuation/removal
OpenZFS 7614 - zfs device evacuation/removal
OpenZFS 9064 - remove_mirror should wait for device removal to complete
This project allows top-level vdevs to be removed from the storage pool
with "zpool remove", reducing the total amount of storage in the pool.
This operation copies all allocated regions of the device to be removed
onto other devices, recording the mapping from old to new location.
After the removal is complete, read and free operations to the removed
(now "indirect") vdev must be remapped and performed at the new location
on disk. The indirect mapping table is kept in memory whenever the pool
is loaded, so there is minimal performance overhead when doing operations
on the indirect vdev.
The size of the in-memory mapping table will be reduced when its entries
become "obsolete" because they are no longer used by any block pointers
in the pool. An entry becomes obsolete when all the blocks that use
it are freed. An entry can also become obsolete when all the snapshots
that reference it are deleted, and the block pointers that reference it
have been "remapped" in all filesystems/zvols (and clones). Whenever an
indirect block is written, all the block pointers in it will be "remapped"
to their new (concrete) locations if possible. This process can be
accelerated by using the "zfs remap" command to proactively rewrite all
indirect blocks that reference indirect (removed) vdevs.
Note that when a device is removed, we do not verify the checksum of
the data that is copied. This makes the process much faster, but if it
were used on redundant vdevs (i.e. mirror or raidz vdevs), it would be
possible to copy the wrong data, when we have the correct data on e.g.
the other side of the mirror.
At the moment, only mirrors and simple top-level vdevs can be removed
and no removal is allowed if any of the top-level vdevs are raidz.
Porting Notes:
* Avoid zero-sized kmem_alloc() in vdev_compact_children().
The device evacuation code adds a dependency that
vdev_compact_children() be able to properly empty the vdev_child
array by setting it to NULL and zeroing vdev_children. Under Linux,
kmem_alloc() and related functions return a sentinel pointer rather
than NULL for zero-sized allocations.
* Remove comment regarding "mpt" driver where zfs_remove_max_segment
is initialized to SPA_MAXBLOCKSIZE.
Change zfs_condense_indirect_commit_entry_delay_ticks to
zfs_condense_indirect_commit_entry_delay_ms for consistency with
most other tunables in which delays are specified in ms.
* ZTS changes:
Use set_tunable rather than mdb
Use zpool sync as appropriate
Use sync_pool instead of sync
Kill jobs during test_removal_with_operation to allow unmount/export
Don't add non-disk names such as "mirror" or "raidz" to $DISKS
Use $TEST_BASE_DIR instead of /tmp
Increase HZ from 100 to 1000 which is more common on Linux
removal_multiple_indirection.ksh
Reduce iterations in order to not time out on the code
coverage builders.
removal_resume_export:
Functionally, the test case is correct but there exists a race
where the kernel thread hasn't been fully started yet and is
not visible. Wait for up to 1 second for the removal thread
to be started before giving up on it. Also, increase the
amount of data copied in order that the removal not finish
before the export has a chance to fail.
* MMP compatibility, the concept of concrete versus non-concrete devices
has slightly changed the semantics of vdev_writeable(). Update
mmp_random_leaf_impl() accordingly.
* Updated dbuf_remap() to handle the org.zfsonlinux:large_dnode pool
feature which is not supported by OpenZFS.
* Added support for new vdev removal tracepoints.
* Test cases removal_with_zdb and removal_condense_export have been
intentionally disabled. When run manually they pass as intended,
but when running in the automated test environment they produce
unreliable results on the latest Fedora release.
They may work better once the upstream pool import refectoring is
merged into ZoL at which point they will be re-enabled.
Authored by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Alex Reece <alex@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Richard Laager <rlaager@wiktel.com>
Reviewed by: Tim Chase <tim@chase2k.com>
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Garrett D'Amore <garrett@damore.org>
Ported-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Tim Chase <tim@chase2k.com>
OpenZFS-issue: https://www.illumos.org/issues/7614
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/f539f1eb
Closes #6900
2016-09-22 19:30:13 +03:00
|
|
|
ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE | ZIO_FLAG_SELF_HEAL);
|
2017-11-16 04:27:01 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function may cause an immediate scan of ddt blocks (see
|
|
|
|
* the comment above dsl_scan_ddt() for details). We set the
|
|
|
|
* scan's root zio here so that we can wait for any scan IOs in
|
|
|
|
* addition to the regular ddt IOs.
|
|
|
|
*/
|
|
|
|
ASSERT3P(scn->scn_zio_root, ==, NULL);
|
|
|
|
scn->scn_zio_root = rio;
|
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_t *ddt = spa->spa_ddt[c];
|
|
|
|
if (ddt == NULL)
|
|
|
|
continue;
|
|
|
|
ddt_sync_table(ddt, tx, txg);
|
|
|
|
ddt_repair_table(ddt, rio);
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) zio_wait(rio);
|
2017-11-16 04:27:01 +03:00
|
|
|
scn->scn_zio_root = NULL;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ddt_walk(spa_t *spa, ddt_bookmark_t *ddb, ddt_entry_t *dde)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
ddt_t *ddt = spa->spa_ddt[ddb->ddb_checksum];
|
2024-02-01 03:05:18 +03:00
|
|
|
if (ddt == NULL)
|
|
|
|
continue;
|
2010-05-29 00:45:14 +04:00
|
|
|
int error = ENOENT;
|
|
|
|
if (ddt_object_exists(ddt, ddb->ddb_type,
|
|
|
|
ddb->ddb_class)) {
|
|
|
|
error = ddt_object_walk(ddt,
|
|
|
|
ddb->ddb_type, ddb->ddb_class,
|
|
|
|
&ddb->ddb_cursor, dde);
|
|
|
|
}
|
|
|
|
dde->dde_type = ddb->ddb_type;
|
|
|
|
dde->dde_class = ddb->ddb_class;
|
|
|
|
if (error == 0)
|
|
|
|
return (0);
|
|
|
|
if (error != ENOENT)
|
|
|
|
return (error);
|
|
|
|
ddb->ddb_cursor = 0;
|
|
|
|
} while (++ddb->ddb_checksum < ZIO_CHECKSUM_FUNCTIONS);
|
|
|
|
ddb->ddb_checksum = 0;
|
|
|
|
} while (++ddb->ddb_type < DDT_TYPES);
|
|
|
|
ddb->ddb_type = 0;
|
|
|
|
} while (++ddb->ddb_class < DDT_CLASSES);
|
|
|
|
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOENT));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
2011-05-04 02:09:28 +04:00
|
|
|
|
2023-03-10 22:59:53 +03:00
|
|
|
/*
|
|
|
|
* This function is used by Block Cloning (brt.c) to increase reference
|
|
|
|
* counter for the DDT entry if the block is already in DDT.
|
|
|
|
*
|
|
|
|
* Return false if the block, despite having the D bit set, is not present
|
|
|
|
* in the DDT. Currently this is not possible but might be in the future.
|
|
|
|
* See the comment below.
|
|
|
|
*/
|
|
|
|
boolean_t
|
|
|
|
ddt_addref(spa_t *spa, const blkptr_t *bp)
|
|
|
|
{
|
|
|
|
ddt_t *ddt;
|
|
|
|
ddt_entry_t *dde;
|
|
|
|
boolean_t result;
|
|
|
|
|
|
|
|
spa_config_enter(spa, SCL_ZIO, FTAG, RW_READER);
|
|
|
|
ddt = ddt_select(spa, bp);
|
|
|
|
ddt_enter(ddt);
|
|
|
|
|
|
|
|
dde = ddt_lookup(ddt, bp, B_TRUE);
|
2024-02-15 11:37:38 +03:00
|
|
|
ASSERT3P(dde, !=, NULL);
|
2023-03-10 22:59:53 +03:00
|
|
|
|
|
|
|
if (dde->dde_type < DDT_TYPES) {
|
|
|
|
ddt_phys_t *ddp;
|
|
|
|
|
|
|
|
ASSERT3S(dde->dde_class, <, DDT_CLASSES);
|
|
|
|
|
|
|
|
ddp = &dde->dde_phys[BP_GET_NDVAS(bp)];
|
ddt_addref: remove unnecessary phys fill when refcount is 0
The previous comment wondered if this case could happen; it turns out
that it really can't.
This block can only be entered if dde_type and dde_class are "real";
that only happens when a ddt entry has been previously synced to a ddt
store, that is, it was created on a previous txg. Since its gone through
that sync, its dde_refcount must be >0.
ddt_addref() is called from brt_pending_apply(), which is called at the
beginning of spa_sync(), before pending DMU writes/frees are issued.
Freeing a dedup block is the only thing that can decrement dde_refcount,
so there's no way for it to drop to zero before applying the clone bumps
it.
Further, even if it _could_ go to zero, it wouldn't be necessary to fill
the entry from the block. The phys content is not cleared until the free
is issued, which happens when the refcount goes to zero, when the last
real free comes through. The cloned block should be identical to what's
in the phys already, so the fill should be a no-op anyway.
I've replaced this with an assertion because this is all very dependent
on the ordering in which BRT and DDT changes are applied, and that might
change in the future.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Sponsored-By: Klara, Inc.
Closes #15004
2023-06-30 19:01:58 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This entry already existed (dde_type is real), so it must
|
|
|
|
* have refcnt >0 at the start of this txg. We are called from
|
|
|
|
* brt_pending_apply(), before frees are issued, so the refcnt
|
|
|
|
* can't be lowered yet. Therefore, it must be >0. We assert
|
|
|
|
* this because if the order of BRT and DDT interactions were
|
|
|
|
* ever to change and the refcnt was ever zero here, then
|
|
|
|
* likely further action is required to fill out the DDT entry,
|
|
|
|
* and this is a place that is likely to be missed in testing.
|
|
|
|
*/
|
|
|
|
ASSERT3U(ddp->ddp_refcnt, >, 0);
|
|
|
|
|
2023-03-10 22:59:53 +03:00
|
|
|
ddt_phys_addref(ddp);
|
|
|
|
result = B_TRUE;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* At the time of implementating this if the block has the
|
|
|
|
* DEDUP flag set it must exist in the DEDUP table, but
|
|
|
|
* there are many advocates that want ability to remove
|
|
|
|
* entries from DDT with refcnt=1. If this will happen,
|
|
|
|
* we may have a block with the DEDUP set, but which doesn't
|
|
|
|
* have a corresponding entry in the DDT. Be ready.
|
|
|
|
*/
|
|
|
|
ASSERT3S(dde->dde_class, ==, DDT_CLASSES);
|
|
|
|
ddt_remove(ddt, dde);
|
|
|
|
result = B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ddt_exit(ddt);
|
|
|
|
spa_config_exit(spa, SCL_ZIO, FTAG);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:14:47 +03:00
|
|
|
ZFS_MODULE_PARAM(zfs_dedup, zfs_dedup_, prefetch, INT, ZMOD_RW,
|
2019-09-06 00:49:49 +03:00
|
|
|
"Enable prefetching dedup-ed blks");
|