aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAlexander Motin <[email protected]>2021-08-17 11:44:34 -0400
committerTony Hutter <[email protected]>2021-09-14 14:31:01 -0700
commit5afc35b69824db01b36418e8f091ffeaeaeb98c9 (patch)
tree87550992a8d5f8d743a25ac3c8c754ce6490d0fb /include
parentc6c0d30016ff344a91aacc8057d5fb392c5ea9c7 (diff)
Use more atomics in refcounts
Use atomic_load_64() for zfs_refcount_count() to prevent torn reads on 32-bit platforms. On 64-bit ones it should not change anything. When built with ZFS_DEBUG but running without tracking enabled use atomics instead of mutexes same as for builds without ZFS_DEBUG. Since rc_tracked can't change live we can check it without lock. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Matthew Ahrens <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Closes #12420
Diffstat (limited to 'include')
-rw-r--r--include/sys/zfs_refcount.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/include/sys/zfs_refcount.h b/include/sys/zfs_refcount.h
index fc0cbea1c..1e6449472 100644
--- a/include/sys/zfs_refcount.h
+++ b/include/sys/zfs_refcount.h
@@ -96,8 +96,8 @@ typedef struct refcount {
#define zfs_refcount_create_tracked(rc) ((rc)->rc_count = 0)
#define zfs_refcount_destroy(rc) ((rc)->rc_count = 0)
#define zfs_refcount_destroy_many(rc, number) ((rc)->rc_count = 0)
-#define zfs_refcount_is_zero(rc) ((rc)->rc_count == 0)
-#define zfs_refcount_count(rc) ((rc)->rc_count)
+#define zfs_refcount_is_zero(rc) (zfs_refcount_count(rc) == 0)
+#define zfs_refcount_count(rc) atomic_load_64(&(rc)->rc_count)
#define zfs_refcount_add(rc, holder) atomic_inc_64_nv(&(rc)->rc_count)
#define zfs_refcount_remove(rc, holder) atomic_dec_64_nv(&(rc)->rc_count)
#define zfs_refcount_add_many(rc, number, holder) \
@@ -105,13 +105,13 @@ typedef struct refcount {
#define zfs_refcount_remove_many(rc, number, holder) \
atomic_add_64_nv(&(rc)->rc_count, -number)
#define zfs_refcount_transfer(dst, src) { \
- uint64_t __tmp = (src)->rc_count; \
+ uint64_t __tmp = zfs_refcount_count(src); \
atomic_add_64(&(src)->rc_count, -__tmp); \
atomic_add_64(&(dst)->rc_count, __tmp); \
}
#define zfs_refcount_transfer_ownership(rc, ch, nh) ((void)0)
#define zfs_refcount_transfer_ownership_many(rc, nr, ch, nh) ((void)0)
-#define zfs_refcount_held(rc, holder) ((rc)->rc_count > 0)
+#define zfs_refcount_held(rc, holder) (zfs_refcount_count(rc) > 0)
#define zfs_refcount_not_held(rc, holder) (B_TRUE)
#define zfs_refcount_init()