2008-11-20 23:01:55 +03: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.
|
2008-11-20 23:01:55 +03: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
|
|
|
|
*/
|
|
|
|
/*
|
2010-05-29 00:45:14 +04:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2021-03-17 00:56:17 +03:00
|
|
|
* Copyright (c) 2012, 2021 by Delphix. All rights reserved.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/zfs_context.h>
|
2020-07-30 02:35:33 +03:00
|
|
|
#include <sys/zfs_refcount.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2022-01-15 02:37:55 +03:00
|
|
|
#ifdef ZFS_DEBUG
|
2020-04-13 20:51:44 +03:00
|
|
|
/*
|
|
|
|
* Reference count tracking is disabled by default. It's memory requirements
|
|
|
|
* are reasonable, however as implemented it consumes a significant amount of
|
|
|
|
* cpu time. Until its performance is improved it should be manually enabled.
|
|
|
|
*/
|
2022-01-15 02:37:55 +03:00
|
|
|
int reference_tracking_enable = B_FALSE;
|
Cleanup: Specify unsignedness on things that should not be signed
In #13871, zfs_vdev_aggregation_limit_non_rotating and
zfs_vdev_aggregation_limit being signed was pointed out as a possible
reason not to eliminate an unnecessary MAX(unsigned, 0) since the
unsigned value was assigned from them.
There is no reason for these module parameters to be signed and upon
inspection, it was found that there are a number of other module
parameters that are signed, but should not be, so we make them unsigned.
Making them unsigned made it clear that some other variables in the code
should also be unsigned, so we also make those unsigned. This prevents
users from setting negative values that could potentially cause bad
behaviors. It also makes the code slightly easier to understand.
Mostly module parameters that deal with timeouts, limits, bitshifts and
percentages are made unsigned by this. Any that are boolean are left
signed, since whether booleans should be considered signed or unsigned
does not matter.
Making zfs_arc_lotsfree_percent unsigned caused a
`zfs_arc_lotsfree_percent >= 0` check to become redundant, so it was
removed. Removing the check was also necessary to prevent a compiler
error from -Werror=type-limits.
Several end of line comments had to be moved to their own lines because
replacing int with uint_t caused us to exceed the 80 character limit
enforced by cstyle.pl.
The following were kept signed because they are passed to
taskq_create(), which expects signed values and modifying the
OpenSolaris/Illumos DDI is out of scope of this patch:
* metaslab_load_pct
* zfs_sync_taskq_batch_pct
* zfs_zil_clean_taskq_nthr_pct
* zfs_zil_clean_taskq_minalloc
* zfs_zil_clean_taskq_maxalloc
* zfs_arc_prune_task_threads
Also, negative values in those parameters was found to be harmless.
The following were left signed because either negative values make
sense, or more analysis was needed to determine whether negative values
should be disallowed:
* zfs_metaslab_switch_threshold
* zfs_pd_bytes_max
* zfs_livelist_min_percent_shared
zfs_multihost_history was made static to be consistent with other
parameters.
A number of module parameters were marked as signed, but in reality
referenced unsigned variables. upgrade_errlog_limit is one of the
numerous examples. In the case of zfs_vdev_async_read_max_active, it was
already uint32_t, but zdb had an extern int declaration for it.
Interestingly, the documentation in zfs.4 was right for
upgrade_errlog_limit despite the module parameter being wrongly marked,
while the documentation for zfs_vdev_async_read_max_active (and friends)
was wrong. It was also wrong for zstd_abort_size, which was unsigned,
but was documented as signed.
Also, the documentation in zfs.4 incorrectly described the following
parameters as ulong when they were int:
* zfs_arc_meta_adjust_restarts
* zfs_override_estimate_recordsize
They are now uint_t as of this patch and thus the man page has been
updated to describe them as uint.
dbuf_state_index was left alone since it does nothing and perhaps should
be removed in another patch.
If any module parameters were missed, they were not found by `grep -r
'ZFS_MODULE_PARAM' | grep ', INT'`. I did find a few that grep missed,
but only because they were in files that had hits.
This patch intentionally did not attempt to address whether some of
these module parameters should be elevated to 64-bit parameters, because
the length of a long on 32-bit is 32-bit.
Lastly, it was pointed out during review that uint_t is a better match
for these variables than uint32_t because FreeBSD kernel parameter
definitions are designed for uint_t, whose bit width can change in
future memory models. As a result, we change the existing parameters
that are uint32_t to use uint_t.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13875
2022-09-28 02:42:41 +03:00
|
|
|
static uint_t reference_history = 3; /* tunable */
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
static kmem_cache_t *reference_cache;
|
|
|
|
|
|
|
|
void
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_init(void)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
reference_cache = kmem_cache_create("reference_cache",
|
|
|
|
sizeof (reference_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_fini(void)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
kmem_cache_destroy(reference_cache);
|
2023-06-14 18:02:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_refcount_compare(const void *x1, const void *x2)
|
|
|
|
{
|
|
|
|
const reference_t *r1 = (const reference_t *)x1;
|
|
|
|
const reference_t *r2 = (const reference_t *)x2;
|
|
|
|
|
|
|
|
int cmp1 = TREE_CMP(r1->ref_holder, r2->ref_holder);
|
|
|
|
int cmp2 = TREE_CMP(r1->ref_number, r2->ref_number);
|
|
|
|
int cmp = cmp1 ? cmp1 : cmp2;
|
|
|
|
return ((cmp || r1->ref_search) ? cmp : TREE_PCMP(r1, r2));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_create(zfs_refcount_t *rc)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
mutex_init(&rc->rc_mtx, NULL, MUTEX_DEFAULT, NULL);
|
2023-06-14 18:02:27 +03:00
|
|
|
avl_create(&rc->rc_tree, zfs_refcount_compare, sizeof (reference_t),
|
|
|
|
offsetof(reference_t, ref_link.a));
|
2008-11-20 23:01:55 +03:00
|
|
|
list_create(&rc->rc_removed, sizeof (reference_t),
|
2023-06-14 18:02:27 +03:00
|
|
|
offsetof(reference_t, ref_link.l));
|
2008-11-20 23:01:55 +03:00
|
|
|
rc->rc_count = 0;
|
|
|
|
rc->rc_removed_count = 0;
|
2013-09-04 16:00:57 +04:00
|
|
|
rc->rc_tracked = reference_tracking_enable;
|
|
|
|
}
|
|
|
|
|
2016-10-14 03:59:18 +03:00
|
|
|
void
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_create_tracked(zfs_refcount_t *rc)
|
2016-10-14 03:59:18 +03:00
|
|
|
{
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_create(rc);
|
2016-10-14 03:59:18 +03:00
|
|
|
rc->rc_tracked = B_TRUE;
|
|
|
|
}
|
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
void
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_create_untracked(zfs_refcount_t *rc)
|
2013-09-04 16:00:57 +04:00
|
|
|
{
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_create(rc);
|
2013-09-04 16:00:57 +04:00
|
|
|
rc->rc_tracked = B_FALSE;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_destroy_many(zfs_refcount_t *rc, uint64_t number)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
reference_t *ref;
|
2023-06-14 18:02:27 +03:00
|
|
|
void *cookie = NULL;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
Implement Redacted Send/Receive
Redacted send/receive allows users to send subsets of their data to
a target system. One possible use case for this feature is to not
transmit sensitive information to a data warehousing, test/dev, or
analytics environment. Another is to save space by not replicating
unimportant data within a given dataset, for example in backup tools
like zrepl.
Redacted send/receive is a three-stage process. First, a clone (or
clones) is made of the snapshot to be sent to the target. In this
clone (or clones), all unnecessary or unwanted data is removed or
modified. This clone is then snapshotted to create the "redaction
snapshot" (or snapshots). Second, the new zfs redact command is used
to create a redaction bookmark. The redaction bookmark stores the
list of blocks in a snapshot that were modified by the redaction
snapshot(s). Finally, the redaction bookmark is passed as a parameter
to zfs send. When sending to the snapshot that was redacted, the
redaction bookmark is used to filter out blocks that contain sensitive
or unwanted information, and those blocks are not included in the send
stream. When sending from the redaction bookmark, the blocks it
contains are considered as candidate blocks in addition to those
blocks in the destination snapshot that were modified since the
creation_txg of the redaction bookmark. This step is necessary to
allow the target to rehydrate data in the case where some blocks are
accidentally or unnecessarily modified in the redaction snapshot.
The changes to bookmarks to enable fast space estimation involve
adding deadlists to bookmarks. There is also logic to manage the
life cycles of these deadlists.
The new size estimation process operates in cases where previously
an accurate estimate could not be provided. In those cases, a send
is performed where no data blocks are read, reducing the runtime
significantly and providing a byte-accurate size estimate.
Reviewed-by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed-by: Matt Ahrens <mahrens@delphix.com>
Reviewed-by: Prashanth Sreenivasa <pks@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Chris Williamson <chris.williamson@delphix.com>
Reviewed-by: Pavel Zhakarov <pavel.zakharov@delphix.com>
Reviewed-by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed-by: Prakash Surya <prakash.surya@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #7958
2019-06-19 19:48:13 +03:00
|
|
|
ASSERT3U(rc->rc_count, ==, number);
|
2023-06-14 18:02:27 +03:00
|
|
|
while ((ref = avl_destroy_nodes(&rc->rc_tree, &cookie)) != NULL)
|
2008-11-20 23:01:55 +03:00
|
|
|
kmem_cache_free(reference_cache, ref);
|
2023-06-14 18:02:27 +03:00
|
|
|
avl_destroy(&rc->rc_tree);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
while ((ref = list_remove_head(&rc->rc_removed)))
|
2008-11-20 23:01:55 +03:00
|
|
|
kmem_cache_free(reference_cache, ref);
|
|
|
|
list_destroy(&rc->rc_removed);
|
|
|
|
mutex_destroy(&rc->rc_mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_destroy(zfs_refcount_t *rc)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_destroy_many(rc, 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_is_zero(zfs_refcount_t *rc)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2021-08-17 18:44:34 +03:00
|
|
|
return (zfs_refcount_count(rc) == 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_count(zfs_refcount_t *rc)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2021-08-17 18:44:34 +03:00
|
|
|
return (atomic_load_64(&rc->rc_count));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2019-08-14 06:24:43 +03:00
|
|
|
zfs_refcount_add_many(zfs_refcount_t *rc, uint64_t number, const void *holder)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2023-06-14 18:02:27 +03:00
|
|
|
reference_t *ref;
|
2008-11-20 23:01:55 +03:00
|
|
|
int64_t count;
|
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
if (likely(!rc->rc_tracked)) {
|
2021-08-17 18:44:34 +03:00
|
|
|
count = atomic_add_64_nv(&(rc)->rc_count, number);
|
|
|
|
ASSERT3U(count, >=, number);
|
|
|
|
return (count);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
2021-08-17 18:44:34 +03:00
|
|
|
|
|
|
|
ref = kmem_cache_alloc(reference_cache, KM_SLEEP);
|
|
|
|
ref->ref_holder = holder;
|
|
|
|
ref->ref_number = number;
|
2023-06-14 18:02:27 +03:00
|
|
|
ref->ref_search = B_FALSE;
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_enter(&rc->rc_mtx);
|
2023-06-14 18:02:27 +03:00
|
|
|
avl_add(&rc->rc_tree, ref);
|
2008-11-20 23:01:55 +03:00
|
|
|
rc->rc_count += number;
|
|
|
|
count = rc->rc_count;
|
|
|
|
mutex_exit(&rc->rc_mtx);
|
|
|
|
|
|
|
|
return (count);
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2019-08-14 06:24:43 +03:00
|
|
|
zfs_refcount_add(zfs_refcount_t *rc, const void *holder)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2018-10-01 20:42:05 +03:00
|
|
|
return (zfs_refcount_add_many(rc, 1, holder));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2023-06-05 21:51:44 +03:00
|
|
|
void
|
|
|
|
zfs_refcount_add_few(zfs_refcount_t *rc, uint64_t number, const void *holder)
|
|
|
|
{
|
2023-06-14 18:02:27 +03:00
|
|
|
if (likely(!rc->rc_tracked))
|
2023-06-05 21:51:44 +03:00
|
|
|
(void) zfs_refcount_add_many(rc, number, holder);
|
|
|
|
else for (; number > 0; number--)
|
|
|
|
(void) zfs_refcount_add(rc, holder);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
int64_t
|
2019-08-14 06:24:43 +03:00
|
|
|
zfs_refcount_remove_many(zfs_refcount_t *rc, uint64_t number,
|
|
|
|
const void *holder)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2023-06-14 18:02:27 +03:00
|
|
|
reference_t *ref, s;
|
2008-11-20 23:01:55 +03:00
|
|
|
int64_t count;
|
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
if (likely(!rc->rc_tracked)) {
|
2021-08-17 18:44:34 +03:00
|
|
|
count = atomic_add_64_nv(&(rc)->rc_count, -number);
|
|
|
|
ASSERT3S(count, >=, 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (count);
|
|
|
|
}
|
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
s.ref_holder = holder;
|
|
|
|
s.ref_number = number;
|
|
|
|
s.ref_search = B_TRUE;
|
2021-08-17 18:44:34 +03:00
|
|
|
mutex_enter(&rc->rc_mtx);
|
|
|
|
ASSERT3U(rc->rc_count, >=, number);
|
2023-06-14 18:02:27 +03:00
|
|
|
ref = avl_find(&rc->rc_tree, &s, NULL);
|
|
|
|
if (unlikely(ref == NULL)) {
|
|
|
|
panic("No such hold %p on refcount %llx", holder,
|
|
|
|
(u_longlong_t)(uintptr_t)rc);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
avl_remove(&rc->rc_tree, ref);
|
|
|
|
if (reference_history > 0) {
|
|
|
|
list_insert_head(&rc->rc_removed, ref);
|
|
|
|
if (rc->rc_removed_count >= reference_history) {
|
|
|
|
ref = list_remove_tail(&rc->rc_removed);
|
|
|
|
kmem_cache_free(reference_cache, ref);
|
|
|
|
} else {
|
|
|
|
rc->rc_removed_count++;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
2023-06-14 18:02:27 +03:00
|
|
|
} else {
|
|
|
|
kmem_cache_free(reference_cache, ref);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
2023-06-14 18:02:27 +03:00
|
|
|
rc->rc_count -= number;
|
|
|
|
count = rc->rc_count;
|
|
|
|
mutex_exit(&rc->rc_mtx);
|
|
|
|
return (count);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2019-08-14 06:24:43 +03:00
|
|
|
zfs_refcount_remove(zfs_refcount_t *rc, const void *holder)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2018-10-01 20:42:05 +03:00
|
|
|
return (zfs_refcount_remove_many(rc, 1, holder));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2023-06-05 21:51:44 +03:00
|
|
|
void
|
|
|
|
zfs_refcount_remove_few(zfs_refcount_t *rc, uint64_t number, const void *holder)
|
|
|
|
{
|
2023-06-14 18:02:27 +03:00
|
|
|
if (likely(!rc->rc_tracked))
|
2023-06-05 21:51:44 +03:00
|
|
|
(void) zfs_refcount_remove_many(rc, number, holder);
|
|
|
|
else for (; number > 0; number--)
|
|
|
|
(void) zfs_refcount_remove(rc, holder);
|
|
|
|
}
|
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
void
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_transfer(zfs_refcount_t *dst, zfs_refcount_t *src)
|
2010-08-27 01:24:34 +04:00
|
|
|
{
|
2023-06-14 18:02:27 +03:00
|
|
|
avl_tree_t tree;
|
|
|
|
list_t removed;
|
|
|
|
reference_t *ref;
|
|
|
|
void *cookie = NULL;
|
|
|
|
uint64_t count;
|
|
|
|
uint_t removed_count;
|
2010-08-27 01:24:34 +04:00
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
avl_create(&tree, zfs_refcount_compare, sizeof (reference_t),
|
|
|
|
offsetof(reference_t, ref_link.a));
|
2010-08-27 01:24:34 +04:00
|
|
|
list_create(&removed, sizeof (reference_t),
|
2023-06-14 18:02:27 +03:00
|
|
|
offsetof(reference_t, ref_link.l));
|
2010-08-27 01:24:34 +04:00
|
|
|
|
|
|
|
mutex_enter(&src->rc_mtx);
|
|
|
|
count = src->rc_count;
|
|
|
|
removed_count = src->rc_removed_count;
|
|
|
|
src->rc_count = 0;
|
|
|
|
src->rc_removed_count = 0;
|
2023-06-14 18:02:27 +03:00
|
|
|
avl_swap(&tree, &src->rc_tree);
|
2010-08-27 01:24:34 +04:00
|
|
|
list_move_tail(&removed, &src->rc_removed);
|
|
|
|
mutex_exit(&src->rc_mtx);
|
|
|
|
|
|
|
|
mutex_enter(&dst->rc_mtx);
|
|
|
|
dst->rc_count += count;
|
|
|
|
dst->rc_removed_count += removed_count;
|
2023-06-14 18:02:27 +03:00
|
|
|
if (avl_is_empty(&dst->rc_tree))
|
|
|
|
avl_swap(&dst->rc_tree, &tree);
|
|
|
|
else while ((ref = avl_destroy_nodes(&tree, &cookie)) != NULL)
|
|
|
|
avl_add(&dst->rc_tree, ref);
|
2010-08-27 01:24:34 +04:00
|
|
|
list_move_tail(&dst->rc_removed, &removed);
|
|
|
|
mutex_exit(&dst->rc_mtx);
|
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
avl_destroy(&tree);
|
2010-08-27 01:24:34 +04:00
|
|
|
list_destroy(&removed);
|
|
|
|
}
|
|
|
|
|
2016-06-02 07:04:53 +03:00
|
|
|
void
|
2018-10-09 00:58:21 +03:00
|
|
|
zfs_refcount_transfer_ownership_many(zfs_refcount_t *rc, uint64_t number,
|
2019-08-14 06:24:43 +03:00
|
|
|
const void *current_holder, const void *new_holder)
|
2016-06-02 07:04:53 +03:00
|
|
|
{
|
2023-06-14 18:02:27 +03:00
|
|
|
reference_t *ref, s;
|
2016-06-02 07:04:53 +03:00
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
if (likely(!rc->rc_tracked))
|
2016-06-02 07:04:53 +03:00
|
|
|
return;
|
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
s.ref_holder = current_holder;
|
|
|
|
s.ref_number = number;
|
|
|
|
s.ref_search = B_TRUE;
|
2021-08-17 18:44:34 +03:00
|
|
|
mutex_enter(&rc->rc_mtx);
|
2023-06-14 18:02:27 +03:00
|
|
|
ref = avl_find(&rc->rc_tree, &s, NULL);
|
|
|
|
ASSERT(ref);
|
|
|
|
ref->ref_holder = new_holder;
|
|
|
|
avl_update(&rc->rc_tree, ref);
|
2016-06-02 07:04:53 +03:00
|
|
|
mutex_exit(&rc->rc_mtx);
|
|
|
|
}
|
2016-10-14 03:59:18 +03:00
|
|
|
|
2018-10-09 00:58:21 +03:00
|
|
|
void
|
2019-08-14 06:24:43 +03:00
|
|
|
zfs_refcount_transfer_ownership(zfs_refcount_t *rc, const void *current_holder,
|
|
|
|
const void *new_holder)
|
2018-10-09 00:58:21 +03:00
|
|
|
{
|
|
|
|
return (zfs_refcount_transfer_ownership_many(rc, 1, current_holder,
|
|
|
|
new_holder));
|
|
|
|
}
|
|
|
|
|
2016-10-14 03:59:18 +03:00
|
|
|
/*
|
|
|
|
* If tracking is enabled, return true if a reference exists that matches
|
|
|
|
* the "holder" tag. If tracking is disabled, then return true if a reference
|
|
|
|
* might be held.
|
|
|
|
*/
|
|
|
|
boolean_t
|
2019-08-14 06:24:43 +03:00
|
|
|
zfs_refcount_held(zfs_refcount_t *rc, const void *holder)
|
2016-10-14 03:59:18 +03:00
|
|
|
{
|
2023-06-14 18:02:27 +03:00
|
|
|
reference_t *ref, s;
|
|
|
|
avl_index_t idx;
|
|
|
|
boolean_t res;
|
2016-10-14 03:59:18 +03:00
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
if (likely(!rc->rc_tracked))
|
2021-08-17 18:44:34 +03:00
|
|
|
return (zfs_refcount_count(rc) > 0);
|
2016-10-14 03:59:18 +03:00
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
s.ref_holder = holder;
|
|
|
|
s.ref_number = 0;
|
|
|
|
s.ref_search = B_TRUE;
|
2021-08-17 18:44:34 +03:00
|
|
|
mutex_enter(&rc->rc_mtx);
|
2023-06-14 18:02:27 +03:00
|
|
|
ref = avl_find(&rc->rc_tree, &s, &idx);
|
|
|
|
if (likely(ref == NULL))
|
|
|
|
ref = avl_nearest(&rc->rc_tree, idx, AVL_AFTER);
|
|
|
|
res = ref && ref->ref_holder == holder;
|
2016-10-14 03:59:18 +03:00
|
|
|
mutex_exit(&rc->rc_mtx);
|
2023-06-14 18:02:27 +03:00
|
|
|
return (res);
|
2016-10-14 03:59:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If tracking is enabled, return true if a reference does not exist that
|
|
|
|
* matches the "holder" tag. If tracking is disabled, always return true
|
|
|
|
* since the reference might not be held.
|
|
|
|
*/
|
|
|
|
boolean_t
|
2019-08-14 06:24:43 +03:00
|
|
|
zfs_refcount_not_held(zfs_refcount_t *rc, const void *holder)
|
2016-10-14 03:59:18 +03:00
|
|
|
{
|
2023-06-14 18:02:27 +03:00
|
|
|
reference_t *ref, s;
|
|
|
|
avl_index_t idx;
|
|
|
|
boolean_t res;
|
2016-10-14 03:59:18 +03:00
|
|
|
|
2023-06-14 18:02:27 +03:00
|
|
|
if (likely(!rc->rc_tracked))
|
2016-10-14 03:59:18 +03:00
|
|
|
return (B_TRUE);
|
|
|
|
|
2021-08-17 18:44:34 +03:00
|
|
|
mutex_enter(&rc->rc_mtx);
|
2023-06-14 18:02:27 +03:00
|
|
|
s.ref_holder = holder;
|
|
|
|
s.ref_number = 0;
|
|
|
|
s.ref_search = B_TRUE;
|
|
|
|
ref = avl_find(&rc->rc_tree, &s, &idx);
|
|
|
|
if (likely(ref == NULL))
|
|
|
|
ref = avl_nearest(&rc->rc_tree, idx, AVL_AFTER);
|
|
|
|
res = ref == NULL || ref->ref_holder != holder;
|
2016-10-14 03:59:18 +03:00
|
|
|
mutex_exit(&rc->rc_mtx);
|
2023-06-14 18:02:27 +03:00
|
|
|
return (res);
|
2016-10-14 03:59:18 +03:00
|
|
|
}
|
2021-03-17 00:56:17 +03:00
|
|
|
|
2021-10-11 20:54:39 +03:00
|
|
|
EXPORT_SYMBOL(zfs_refcount_create);
|
|
|
|
EXPORT_SYMBOL(zfs_refcount_destroy);
|
|
|
|
EXPORT_SYMBOL(zfs_refcount_is_zero);
|
|
|
|
EXPORT_SYMBOL(zfs_refcount_count);
|
|
|
|
EXPORT_SYMBOL(zfs_refcount_add);
|
|
|
|
EXPORT_SYMBOL(zfs_refcount_remove);
|
|
|
|
EXPORT_SYMBOL(zfs_refcount_held);
|
|
|
|
|
2021-03-17 00:56:17 +03:00
|
|
|
/* BEGIN CSTYLED */
|
2022-01-15 02:37:55 +03:00
|
|
|
ZFS_MODULE_PARAM(zfs, , reference_tracking_enable, INT, ZMOD_RW,
|
2021-03-17 00:56:17 +03:00
|
|
|
"Track reference holders to refcount_t objects");
|
|
|
|
|
Cleanup: Specify unsignedness on things that should not be signed
In #13871, zfs_vdev_aggregation_limit_non_rotating and
zfs_vdev_aggregation_limit being signed was pointed out as a possible
reason not to eliminate an unnecessary MAX(unsigned, 0) since the
unsigned value was assigned from them.
There is no reason for these module parameters to be signed and upon
inspection, it was found that there are a number of other module
parameters that are signed, but should not be, so we make them unsigned.
Making them unsigned made it clear that some other variables in the code
should also be unsigned, so we also make those unsigned. This prevents
users from setting negative values that could potentially cause bad
behaviors. It also makes the code slightly easier to understand.
Mostly module parameters that deal with timeouts, limits, bitshifts and
percentages are made unsigned by this. Any that are boolean are left
signed, since whether booleans should be considered signed or unsigned
does not matter.
Making zfs_arc_lotsfree_percent unsigned caused a
`zfs_arc_lotsfree_percent >= 0` check to become redundant, so it was
removed. Removing the check was also necessary to prevent a compiler
error from -Werror=type-limits.
Several end of line comments had to be moved to their own lines because
replacing int with uint_t caused us to exceed the 80 character limit
enforced by cstyle.pl.
The following were kept signed because they are passed to
taskq_create(), which expects signed values and modifying the
OpenSolaris/Illumos DDI is out of scope of this patch:
* metaslab_load_pct
* zfs_sync_taskq_batch_pct
* zfs_zil_clean_taskq_nthr_pct
* zfs_zil_clean_taskq_minalloc
* zfs_zil_clean_taskq_maxalloc
* zfs_arc_prune_task_threads
Also, negative values in those parameters was found to be harmless.
The following were left signed because either negative values make
sense, or more analysis was needed to determine whether negative values
should be disallowed:
* zfs_metaslab_switch_threshold
* zfs_pd_bytes_max
* zfs_livelist_min_percent_shared
zfs_multihost_history was made static to be consistent with other
parameters.
A number of module parameters were marked as signed, but in reality
referenced unsigned variables. upgrade_errlog_limit is one of the
numerous examples. In the case of zfs_vdev_async_read_max_active, it was
already uint32_t, but zdb had an extern int declaration for it.
Interestingly, the documentation in zfs.4 was right for
upgrade_errlog_limit despite the module parameter being wrongly marked,
while the documentation for zfs_vdev_async_read_max_active (and friends)
was wrong. It was also wrong for zstd_abort_size, which was unsigned,
but was documented as signed.
Also, the documentation in zfs.4 incorrectly described the following
parameters as ulong when they were int:
* zfs_arc_meta_adjust_restarts
* zfs_override_estimate_recordsize
They are now uint_t as of this patch and thus the man page has been
updated to describe them as uint.
dbuf_state_index was left alone since it does nothing and perhaps should
be removed in another patch.
If any module parameters were missed, they were not found by `grep -r
'ZFS_MODULE_PARAM' | grep ', INT'`. I did find a few that grep missed,
but only because they were in files that had hits.
This patch intentionally did not attempt to address whether some of
these module parameters should be elevated to 64-bit parameters, because
the length of a long on 32-bit is 32-bit.
Lastly, it was pointed out during review that uint_t is a better match
for these variables than uint32_t because FreeBSD kernel parameter
definitions are designed for uint_t, whose bit width can change in
future memory models. As a result, we change the existing parameters
that are uint32_t to use uint_t.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13875
2022-09-28 02:42:41 +03:00
|
|
|
ZFS_MODULE_PARAM(zfs, , reference_history, UINT, ZMOD_RW,
|
2021-03-17 00:56:17 +03:00
|
|
|
"Maximum reference holders being tracked");
|
|
|
|
/* END CSTYLED */
|
2010-08-27 01:24:34 +04:00
|
|
|
#endif /* ZFS_DEBUG */
|