diff options
author | Matthew Ahrens <[email protected]> | 2016-09-22 09:30:13 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2018-04-14 12:16:17 -0700 |
commit | a1d477c24c7badc89c60955995fd84d311938486 (patch) | |
tree | d0efeec0908cd74a183e1d1975244c951226c4fb /module/zfs/space_map.c | |
parent | 4b0f5b2d7b99ca3ed9585173fe4b1c7fedda5aa5 (diff) |
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 <[email protected]>
Reviewed-by: Alex Reece <[email protected]>
Reviewed-by: George Wilson <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Prakash Surya <[email protected]>
Reviewed by: Richard Laager <[email protected]>
Reviewed by: Tim Chase <[email protected]>
Reviewed by: Brian Behlendorf <[email protected]>
Approved by: Garrett D'Amore <[email protected]>
Ported-by: Tim Chase <[email protected]>
Signed-off-by: Tim Chase <[email protected]>
OpenZFS-issue: https://www.illumos.org/issues/7614
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/f539f1eb
Closes #6900
Diffstat (limited to 'module/zfs/space_map.c')
-rw-r--r-- | module/zfs/space_map.c | 136 |
1 files changed, 77 insertions, 59 deletions
diff --git a/module/zfs/space_map.c b/module/zfs/space_map.c index baab0610d..d84dd7583 100644 --- a/module/zfs/space_map.c +++ b/module/zfs/space_map.c @@ -46,42 +46,27 @@ int space_map_blksz = (1 << 12); /* - * Load the space map disk into the specified range tree. Segments of maptype - * are added to the range tree, other segment types are removed. - * - * Note: space_map_load() will drop sm_lock across dmu_read() calls. - * The caller must be OK with this. + * Iterate through the space map, invoking the callback on each (non-debug) + * space map entry. */ int -space_map_load(space_map_t *sm, range_tree_t *rt, maptype_t maptype) +space_map_iterate(space_map_t *sm, sm_cb_t callback, void *arg) { uint64_t *entry, *entry_map, *entry_map_end; - uint64_t bufsize, size, offset, end, space; + uint64_t bufsize, size, offset, end; int error = 0; - ASSERT(MUTEX_HELD(sm->sm_lock)); - end = space_map_length(sm); - space = space_map_allocated(sm); - - VERIFY0(range_tree_space(rt)); - - if (maptype == SM_FREE) { - range_tree_add(rt, sm->sm_start, sm->sm_size); - space = sm->sm_size - space; - } bufsize = MAX(sm->sm_blksz, SPA_MINBLOCKSIZE); entry_map = vmem_alloc(bufsize, KM_SLEEP); - mutex_exit(sm->sm_lock); if (end > bufsize) { dmu_prefetch(sm->sm_os, space_map_object(sm), 0, bufsize, end - bufsize, ZIO_PRIORITY_SYNC_READ); } - mutex_enter(sm->sm_lock); - for (offset = 0; offset < end; offset += bufsize) { + for (offset = 0; offset < end && error == 0; offset += bufsize) { size = MIN(end - offset, bufsize); VERIFY(P2PHASE(size, sizeof (uint64_t)) == 0); VERIFY(size != 0); @@ -90,19 +75,18 @@ space_map_load(space_map_t *sm, range_tree_t *rt, maptype_t maptype) dprintf("object=%llu offset=%llx size=%llx\n", space_map_object(sm), offset, size); - mutex_exit(sm->sm_lock); error = dmu_read(sm->sm_os, space_map_object(sm), offset, size, entry_map, DMU_READ_PREFETCH); - mutex_enter(sm->sm_lock); if (error != 0) break; entry_map_end = entry_map + (size / sizeof (uint64_t)); - for (entry = entry_map; entry < entry_map_end; entry++) { + for (entry = entry_map; entry < entry_map_end && error == 0; + entry++) { uint64_t e = *entry; uint64_t offset, size; - if (SM_DEBUG_DECODE(e)) /* Skip debug entries */ + if (SM_DEBUG_DECODE(e)) /* Skip debug entries */ continue; offset = (SM_OFFSET_DECODE(e) << sm->sm_shift) + @@ -113,23 +97,67 @@ space_map_load(space_map_t *sm, range_tree_t *rt, maptype_t maptype) VERIFY0(P2PHASE(size, 1ULL << sm->sm_shift)); VERIFY3U(offset, >=, sm->sm_start); VERIFY3U(offset + size, <=, sm->sm_start + sm->sm_size); - if (SM_TYPE_DECODE(e) == maptype) { - VERIFY3U(range_tree_space(rt) + size, <=, - sm->sm_size); - range_tree_add(rt, offset, size); - } else { - range_tree_remove(rt, offset, size); - } + error = callback(SM_TYPE_DECODE(e), offset, size, arg); } } - if (error == 0) + vmem_free(entry_map, bufsize); + return (error); +} + +typedef struct space_map_load_arg { + space_map_t *smla_sm; + range_tree_t *smla_rt; + maptype_t smla_type; +} space_map_load_arg_t; + +static int +space_map_load_callback(maptype_t type, uint64_t offset, uint64_t size, + void *arg) +{ + space_map_load_arg_t *smla = arg; + if (type == smla->smla_type) { + VERIFY3U(range_tree_space(smla->smla_rt) + size, <=, + smla->smla_sm->sm_size); + range_tree_add(smla->smla_rt, offset, size); + } else { + range_tree_remove(smla->smla_rt, offset, size); + } + + return (0); +} + +/* + * Load the space map disk into the specified range tree. Segments of maptype + * are added to the range tree, other segment types are removed. + */ +int +space_map_load(space_map_t *sm, range_tree_t *rt, maptype_t maptype) +{ + uint64_t space; + int err; + space_map_load_arg_t smla; + + VERIFY0(range_tree_space(rt)); + space = space_map_allocated(sm); + + if (maptype == SM_FREE) { + range_tree_add(rt, sm->sm_start, sm->sm_size); + space = sm->sm_size - space; + } + + smla.smla_rt = rt; + smla.smla_sm = sm; + smla.smla_type = maptype; + err = space_map_iterate(sm, space_map_load_callback, &smla); + + if (err == 0) { VERIFY3U(range_tree_space(rt), ==, space); - else + } else { range_tree_vacate(rt, NULL, NULL); + } - vmem_free(entry_map, bufsize); - return (error); + return (err); } void @@ -160,7 +188,6 @@ space_map_histogram_add(space_map_t *sm, range_tree_t *rt, dmu_tx_t *tx) { int idx = 0; - ASSERT(MUTEX_HELD(rt->rt_lock)); ASSERT(dmu_tx_is_syncing(tx)); VERIFY3U(space_map_object(sm), !=, 0); @@ -229,9 +256,6 @@ space_map_entries(space_map_t *sm, range_tree_t *rt) return (entries); } -/* - * Note: space_map_write() will drop sm_lock across dmu_write() calls. - */ void space_map_write(space_map_t *sm, range_tree_t *rt, maptype_t maptype, dmu_tx_t *tx) @@ -244,7 +268,6 @@ space_map_write(space_map_t *sm, range_tree_t *rt, maptype_t maptype, uint64_t *entry, *entry_map, *entry_map_end; uint64_t expected_entries, actual_entries = 1; - ASSERT(MUTEX_HELD(rt->rt_lock)); ASSERT(dsl_pool_sync_context(dmu_objset_pool(os))); VERIFY3U(space_map_object(sm), !=, 0); dmu_buf_will_dirty(sm->sm_dbuf, tx); @@ -294,11 +317,9 @@ space_map_write(space_map_t *sm, range_tree_t *rt, maptype_t maptype, run_len = MIN(size, SM_RUN_MAX); if (entry == entry_map_end) { - mutex_exit(rt->rt_lock); dmu_write(os, space_map_object(sm), sm->sm_phys->smp_objsize, sm->sm_blksz, entry_map, tx); - mutex_enter(rt->rt_lock); sm->sm_phys->smp_objsize += sm->sm_blksz; entry = entry_map; } @@ -315,10 +336,8 @@ space_map_write(space_map_t *sm, range_tree_t *rt, maptype_t maptype, if (entry != entry_map) { size = (entry - entry_map) * sizeof (uint64_t); - mutex_exit(rt->rt_lock); dmu_write(os, space_map_object(sm), sm->sm_phys->smp_objsize, size, entry_map, tx); - mutex_enter(rt->rt_lock); sm->sm_phys->smp_objsize += size; } ASSERT3U(expected_entries, ==, actual_entries); @@ -351,7 +370,7 @@ space_map_open_impl(space_map_t *sm) int space_map_open(space_map_t **smp, objset_t *os, uint64_t object, - uint64_t start, uint64_t size, uint8_t shift, kmutex_t *lp) + uint64_t start, uint64_t size, uint8_t shift) { space_map_t *sm; int error; @@ -365,7 +384,6 @@ space_map_open(space_map_t **smp, objset_t *os, uint64_t object, sm->sm_start = start; sm->sm_size = size; sm->sm_shift = shift; - sm->sm_lock = lp; sm->sm_os = os; sm->sm_object = object; sm->sm_length = 0; @@ -459,8 +477,6 @@ space_map_update(space_map_t *sm) if (sm == NULL) return; - ASSERT(MUTEX_HELD(sm->sm_lock)); - sm->sm_alloc = sm->sm_phys->smp_alloc; sm->sm_length = sm->sm_phys->smp_objsize; } @@ -488,27 +504,29 @@ space_map_alloc(objset_t *os, dmu_tx_t *tx) } void -space_map_free(space_map_t *sm, dmu_tx_t *tx) +space_map_free_obj(objset_t *os, uint64_t smobj, dmu_tx_t *tx) { - spa_t *spa; - - if (sm == NULL) - return; - - spa = dmu_objset_spa(sm->sm_os); + spa_t *spa = dmu_objset_spa(os); if (spa_feature_is_enabled(spa, SPA_FEATURE_SPACEMAP_HISTOGRAM)) { dmu_object_info_t doi; - dmu_object_info_from_db(sm->sm_dbuf, &doi); + VERIFY0(dmu_object_info(os, smobj, &doi)); if (doi.doi_bonus_size != SPACE_MAP_SIZE_V0) { - VERIFY(spa_feature_is_active(spa, - SPA_FEATURE_SPACEMAP_HISTOGRAM)); spa_feature_decr(spa, SPA_FEATURE_SPACEMAP_HISTOGRAM, tx); } } - VERIFY3U(dmu_object_free(sm->sm_os, space_map_object(sm), tx), ==, 0); + VERIFY0(dmu_object_free(os, smobj, tx)); +} + +void +space_map_free(space_map_t *sm, dmu_tx_t *tx) +{ + if (sm == NULL) + return; + + space_map_free_obj(sm->sm_os, space_map_object(sm), tx); sm->sm_object = 0; } |