Skip to content

Commit

Permalink
Remove unnecessary cache allocation in zfs_znode_hold_enter
Browse files Browse the repository at this point in the history
remove the *zh_new pointer in zfs_znode_hold_enter. When avl_find()
cannot find *zh,kmem_cache_alloc() is used to allocate cache and
kmem_cache_free() is removed.

Signed-off-by: GreatRiver Shen <[email protected]>
  • Loading branch information
LeftHandCold committed Aug 4, 2024
1 parent c8184d7 commit af677b6
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions module/os/linux/zfs/zfs_znode.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,30 +275,24 @@ zfs_znode_held(zfsvfs_t *zfsvfs, uint64_t obj)
znode_hold_t *
zfs_znode_hold_enter(zfsvfs_t *zfsvfs, uint64_t obj)
{
znode_hold_t *zh, *zh_new, search;
znode_hold_t *zh, search;
int i = ZFS_OBJ_HASH(zfsvfs, obj);
boolean_t found = B_FALSE;

zh_new = kmem_cache_alloc(znode_hold_cache, KM_SLEEP);
search.zh_obj = obj;

mutex_enter(&zfsvfs->z_hold_locks[i]);
zh = avl_find(&zfsvfs->z_hold_trees[i], &search, NULL);
if (likely(zh == NULL)) {
zh = zh_new;
zh = kmem_cache_alloc(znode_hold_cache, KM_SLEEP);
zh->zh_obj = obj;
avl_add(&zfsvfs->z_hold_trees[i], zh);
} else {
ASSERT3U(zh->zh_obj, ==, obj);
found = B_TRUE;
}
zh->zh_refcount++;
ASSERT3S(zh->zh_refcount, >, 0);
mutex_exit(&zfsvfs->z_hold_locks[i]);

if (found == B_TRUE)
kmem_cache_free(znode_hold_cache, zh_new);

ASSERT(MUTEX_NOT_HELD(&zh->zh_lock));
mutex_enter(&zh->zh_lock);

Expand Down

0 comments on commit af677b6

Please sign in to comment.