Skip to content

Commit 55a0ad2

Browse files
committed
Remove atomics from zh_refcount
It is protected by z_hold_locks, so we do not need more serialization, simple integer math should be fine. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Reviewed-by: Richard Yao <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Closes openzfs#14196
1 parent c7e17c5 commit 55a0ad2

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

include/sys/zfs_znode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ typedef struct znode {
217217

218218
typedef struct znode_hold {
219219
uint64_t zh_obj; /* object id */
220-
kmutex_t zh_lock; /* lock serializing object access */
221220
avl_node_t zh_node; /* avl tree linkage */
222-
zfs_refcount_t zh_refcount; /* active consumer reference count */
221+
kmutex_t zh_lock; /* lock serializing object access */
222+
int zh_refcount; /* active consumer reference count */
223223
} znode_hold_t;
224224

225225
static inline uint64_t

module/os/linux/zfs/zfs_znode.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ zfs_znode_hold_cache_constructor(void *buf, void *arg, int kmflags)
162162
znode_hold_t *zh = buf;
163163

164164
mutex_init(&zh->zh_lock, NULL, MUTEX_DEFAULT, NULL);
165-
zfs_refcount_create(&zh->zh_refcount);
166-
zh->zh_obj = ZFS_NO_OBJECT;
165+
zh->zh_refcount = 0;
167166

168167
return (0);
169168
}
@@ -174,7 +173,6 @@ zfs_znode_hold_cache_destructor(void *buf, void *arg)
174173
znode_hold_t *zh = buf;
175174

176175
mutex_destroy(&zh->zh_lock);
177-
zfs_refcount_destroy(&zh->zh_refcount);
178176
}
179177

180178
void
@@ -273,26 +271,26 @@ zfs_znode_hold_enter(zfsvfs_t *zfsvfs, uint64_t obj)
273271
boolean_t found = B_FALSE;
274272

275273
zh_new = kmem_cache_alloc(znode_hold_cache, KM_SLEEP);
276-
zh_new->zh_obj = obj;
277274
search.zh_obj = obj;
278275

279276
mutex_enter(&zfsvfs->z_hold_locks[i]);
280277
zh = avl_find(&zfsvfs->z_hold_trees[i], &search, NULL);
281278
if (likely(zh == NULL)) {
282279
zh = zh_new;
280+
zh->zh_obj = obj;
283281
avl_add(&zfsvfs->z_hold_trees[i], zh);
284282
} else {
285283
ASSERT3U(zh->zh_obj, ==, obj);
286284
found = B_TRUE;
287285
}
288-
zfs_refcount_add(&zh->zh_refcount, NULL);
286+
zh->zh_refcount++;
287+
ASSERT3S(zh->zh_refcount, >, 0);
289288
mutex_exit(&zfsvfs->z_hold_locks[i]);
290289

291290
if (found == B_TRUE)
292291
kmem_cache_free(znode_hold_cache, zh_new);
293292

294293
ASSERT(MUTEX_NOT_HELD(&zh->zh_lock));
295-
ASSERT3S(zfs_refcount_count(&zh->zh_refcount), >, 0);
296294
mutex_enter(&zh->zh_lock);
297295

298296
return (zh);
@@ -305,11 +303,11 @@ zfs_znode_hold_exit(zfsvfs_t *zfsvfs, znode_hold_t *zh)
305303
boolean_t remove = B_FALSE;
306304

307305
ASSERT(zfs_znode_held(zfsvfs, zh->zh_obj));
308-
ASSERT3S(zfs_refcount_count(&zh->zh_refcount), >, 0);
309306
mutex_exit(&zh->zh_lock);
310307

311308
mutex_enter(&zfsvfs->z_hold_locks[i]);
312-
if (zfs_refcount_remove(&zh->zh_refcount, NULL) == 0) {
309+
ASSERT3S(zh->zh_refcount, >, 0);
310+
if (--zh->zh_refcount == 0) {
313311
avl_remove(&zfsvfs->z_hold_trees[i], zh);
314312
remove = B_TRUE;
315313
}

0 commit comments

Comments
 (0)