Skip to content

Commit f8deed3

Browse files
amotinandrewc12
authored andcommitted
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 64f6df7 commit f8deed3

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
@@ -242,9 +242,9 @@ zfs_enter_verify_zp(zfsvfs_t *zfsvfs, znode_t *zp, const char *tag)
242242

243243
typedef struct znode_hold {
244244
uint64_t zh_obj; /* object id */
245-
kmutex_t zh_lock; /* lock serializing object access */
246245
avl_node_t zh_node; /* avl tree linkage */
247-
zfs_refcount_t zh_refcount; /* active consumer reference count */
246+
kmutex_t zh_lock; /* lock serializing object access */
247+
int zh_refcount; /* active consumer reference count */
248248
} znode_hold_t;
249249

250250
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
@@ -169,8 +169,7 @@ zfs_znode_hold_cache_constructor(void *buf, void *arg, int kmflags)
169169
znode_hold_t *zh = buf;
170170

171171
mutex_init(&zh->zh_lock, NULL, MUTEX_DEFAULT, NULL);
172-
zfs_refcount_create(&zh->zh_refcount);
173-
zh->zh_obj = ZFS_NO_OBJECT;
172+
zh->zh_refcount = 0;
174173

175174
return (0);
176175
}
@@ -182,7 +181,6 @@ zfs_znode_hold_cache_destructor(void *buf, void *arg)
182181
znode_hold_t *zh = buf;
183182

184183
mutex_destroy(&zh->zh_lock);
185-
zfs_refcount_destroy(&zh->zh_refcount);
186184
}
187185

188186
void
@@ -281,26 +279,26 @@ zfs_znode_hold_enter(zfsvfs_t *zfsvfs, uint64_t obj)
281279
boolean_t found = B_FALSE;
282280

283281
zh_new = kmem_cache_alloc(znode_hold_cache, KM_SLEEP);
284-
zh_new->zh_obj = obj;
285282
search.zh_obj = obj;
286283

287284
mutex_enter(&zfsvfs->z_hold_locks[i]);
288285
zh = avl_find(&zfsvfs->z_hold_trees[i], &search, NULL);
289286
if (likely(zh == NULL)) {
290287
zh = zh_new;
288+
zh->zh_obj = obj;
291289
avl_add(&zfsvfs->z_hold_trees[i], zh);
292290
} else {
293291
ASSERT3U(zh->zh_obj, ==, obj);
294292
found = B_TRUE;
295293
}
296-
zfs_refcount_add(&zh->zh_refcount, NULL);
294+
zh->zh_refcount++;
295+
ASSERT3S(zh->zh_refcount, >, 0);
297296
mutex_exit(&zfsvfs->z_hold_locks[i]);
298297

299298
if (found == B_TRUE)
300299
kmem_cache_free(znode_hold_cache, zh_new);
301300

302301
ASSERT(MUTEX_NOT_HELD(&zh->zh_lock));
303-
ASSERT3S(zfs_refcount_count(&zh->zh_refcount), >, 0);
304302
mutex_enter(&zh->zh_lock);
305303

306304
return (zh);
@@ -313,11 +311,11 @@ zfs_znode_hold_exit(zfsvfs_t *zfsvfs, znode_hold_t *zh)
313311
boolean_t remove = B_FALSE;
314312

315313
ASSERT(zfs_znode_held(zfsvfs, zh->zh_obj));
316-
ASSERT3S(zfs_refcount_count(&zh->zh_refcount), >, 0);
317314
mutex_exit(&zh->zh_lock);
318315

319316
mutex_enter(&zfsvfs->z_hold_locks[i]);
320-
if (zfs_refcount_remove(&zh->zh_refcount, NULL) == 0) {
317+
ASSERT3S(zh->zh_refcount, >, 0);
318+
if (--zh->zh_refcount == 0) {
321319
avl_remove(&zfsvfs->z_hold_trees[i], zh);
322320
remove = B_TRUE;
323321
}

0 commit comments

Comments
 (0)