diff options
author | Brian Behlendorf <[email protected]> | 2015-12-22 13:47:38 -0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2016-01-15 15:33:45 -0800 |
commit | c96c36fa22ab97f6b3025b356bfca8d9e030d002 (patch) | |
tree | cfa628fd0d582460925b75e54801d079984f1fda /include/sys/zfs_znode.h | |
parent | 0720116d4dd7a62d2097863fc4c32c3cbd11aefa (diff) |
Fix zsb->z_hold_mtx deadlock
The zfs_znode_hold_enter() / zfs_znode_hold_exit() functions are used to
serialize access to a znode and its SA buffer while the object is being
created or destroyed. This kind of locking would normally reside in the
znode itself but in this case that's impossible because the znode and SA
buffer may not yet exist. Therefore the locking is handled externally
with an array of mutexs and AVLs trees which contain per-object locks.
In zfs_znode_hold_enter() a per-object lock is created as needed, inserted
in to the correct AVL tree and finally the per-object lock is held. In
zfs_znode_hold_exit() the process is reversed. The per-object lock is
released, removed from the AVL tree and destroyed if there are no waiters.
This scheme has two important properties:
1) No memory allocations are performed while holding one of the z_hold_locks.
This ensures evict(), which can be called from direct memory reclaim, will
never block waiting on a z_hold_locks which just happens to have hashed
to the same index.
2) All locks used to serialize access to an object are per-object and never
shared. This minimizes lock contention without creating a large number
of dedicated locks.
On the downside it does require znode_lock_t structures to be frequently
allocated and freed. However, because these are backed by a kmem cache
and very short lived this cost is minimal.
Signed-off-by: Brian Behlendorf <[email protected]>
Issue #4106
Diffstat (limited to 'include/sys/zfs_znode.h')
-rw-r--r-- | include/sys/zfs_znode.h | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/include/sys/zfs_znode.h b/include/sys/zfs_znode.h index 59ca085ef..c03bef5c7 100644 --- a/include/sys/zfs_znode.h +++ b/include/sys/zfs_znode.h @@ -220,6 +220,12 @@ typedef struct znode { struct inode z_inode; /* generic vfs inode */ } znode_t; +typedef struct znode_hold { + uint64_t zh_obj; /* object id */ + kmutex_t zh_lock; /* lock serializing object access */ + avl_node_t zh_node; /* avl tree linkage */ + refcount_t zh_refcount; /* active consumer reference count */ +} znode_hold_t; /* * Range locking rules @@ -273,24 +279,12 @@ typedef struct znode { /* * Macros for dealing with dmu_buf_hold */ -#define ZFS_OBJ_MTX_SZ 64 -#define ZFS_OBJ_MTX_MAX (1024 * 1024) +#define ZFS_OBJ_MTX_SZ 64 +#define ZFS_OBJ_MTX_MAX (1024 * 1024) +#define ZFS_OBJ_HASH(zsb, obj) ((obj) & ((zsb->z_hold_size) - 1)) extern unsigned int zfs_object_mutex_size; -#define ZFS_OBJ_HASH(zsb, obj_num) \ - ((obj_num) & ((zsb->z_hold_mtx_size) - 1)) -#define ZFS_OBJ_MUTEX(zsb, obj_num) \ - (&(zsb)->z_hold_mtx[ZFS_OBJ_HASH(zsb, obj_num)]) -#define ZFS_OBJ_HOLD_ENTER(zsb, obj_num) \ - mutex_enter(ZFS_OBJ_MUTEX((zsb), (obj_num))) -#define ZFS_OBJ_HOLD_TRYENTER(zsb, obj_num) \ - mutex_tryenter(ZFS_OBJ_MUTEX((zsb), (obj_num))) -#define ZFS_OBJ_HOLD_EXIT(zsb, obj_num) \ - mutex_exit(ZFS_OBJ_MUTEX((zsb), (obj_num))) -#define ZFS_OBJ_HOLD_OWNED(zsb, obj_num) \ - mutex_owned(ZFS_OBJ_MUTEX((zsb), (obj_num))) - /* Encode ZFS stored time values from a struct timespec */ #define ZFS_TIME_ENCODE(tp, stmp) \ { \ @@ -326,6 +320,7 @@ extern void zfs_grow_blocksize(znode_t *, uint64_t, dmu_tx_t *); extern int zfs_freesp(znode_t *, uint64_t, uint64_t, int, boolean_t); extern void zfs_znode_init(void); extern void zfs_znode_fini(void); +extern int zfs_znode_hold_compare(const void *, const void *); extern int zfs_zget(zfs_sb_t *, uint64_t, znode_t **); extern int zfs_rezget(znode_t *); extern void zfs_zinactive(znode_t *); |