diff options
author | phk <phk@FreeBSD.org> | 2005-03-16 07:35:06 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2005-03-16 07:35:06 +0000 |
commit | e61634909a711e4dc62a5b7c64acc1ddabc9c351 (patch) | |
tree | 2a5ad25ecb42bea9ee693b1e0d5f739148d0b162 /sys/kern/vfs_hash.c | |
parent | eeb2c527c0ecb4fc525ae4af75f02284359c1a3a (diff) | |
download | FreeBSD-src-e61634909a711e4dc62a5b7c64acc1ddabc9c351.zip FreeBSD-src-e61634909a711e4dc62a5b7c64acc1ddabc9c351.tar.gz |
Add mnt_hashseed to struct mount and initialize it witn PRNG bits, use
it to get better hashing in vfs_hash.
In case of an insert collision in vfs_hash_insert(), put the loosing vnode
on a special list so that vfs_hash_remove() can just assume that it is on
a list.
Drop the VI_HASHED flag.
Diffstat (limited to 'sys/kern/vfs_hash.c')
-rw-r--r-- | sys/kern/vfs_hash.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/sys/kern/vfs_hash.c b/sys/kern/vfs_hash.c index 72a0278..8940977 100644 --- a/sys/kern/vfs_hash.c +++ b/sys/kern/vfs_hash.c @@ -32,11 +32,13 @@ __FBSDID("$FreeBSD$"); #include <sys/systm.h> #include <sys/kernel.h> #include <sys/malloc.h> +#include <sys/mount.h> #include <sys/vnode.h> static MALLOC_DEFINE(M_VFS_HASH, "VFS hash", "VFS hash table"); -static LIST_HEAD(vfs_hashhead, vnode) *vfs_hash_tbl; +static LIST_HEAD(vfs_hash_head, vnode) *vfs_hash_tbl; +static LIST_HEAD(,vnode) vfs_hash_side; static u_long vfs_hash_mask; static struct mtx vfs_hash_mtx; @@ -46,11 +48,19 @@ vfs_hashinit(void *dummy __unused) vfs_hash_tbl = hashinit(desiredvnodes, M_VFS_HASH, &vfs_hash_mask); mtx_init(&vfs_hash_mtx, "vfs hash", NULL, MTX_DEF); + LIST_INIT(&vfs_hash_side); } /* Must be SI_ORDER_SECOND so desiredvnodes is available */ SYSINIT(vfs_hash, SI_SUB_VFS, SI_ORDER_SECOND, vfs_hashinit, NULL) +static struct vfs_hash_head * +vfs_hash_index(struct mount *mp, u_int hash) +{ + + return(&vfs_hash_tbl[(hash + mp->mnt_hashseed) & vfs_hash_mask]); +} + int vfs_hash_get(struct mount *mp, u_int hash, int flags, struct thread *td, struct vnode **vpp) { @@ -59,8 +69,7 @@ vfs_hash_get(struct mount *mp, u_int hash, int flags, struct thread *td, struct while (1) { mtx_lock(&vfs_hash_mtx); - LIST_FOREACH(vp, - &vfs_hash_tbl[hash & vfs_hash_mask], v_hashlist) { + LIST_FOREACH(vp, vfs_hash_index(mp, hash), v_hashlist) { if (vp->v_hash != hash) continue; if (vp->v_mount != mp) @@ -88,11 +97,7 @@ vfs_hash_remove(struct vnode *vp) { mtx_lock(&vfs_hash_mtx); - VI_LOCK(vp); - VNASSERT(vp->v_iflag & VI_HASHED, vp, ("vfs_hash_remove: not hashed")); LIST_REMOVE(vp, v_hashlist); - vp->v_iflag &= ~VI_HASHED; - VI_UNLOCK(vp); mtx_unlock(&vfs_hash_mtx); } @@ -107,7 +112,7 @@ vfs_hash_insert(struct vnode *vp, u_int hash, int flags, struct thread *td, stru while (1) { mtx_lock(&vfs_hash_mtx); LIST_FOREACH(vp2, - &vfs_hash_tbl[hash & vfs_hash_mask], v_hashlist) { + vfs_hash_index(vp->v_mount, hash), v_hashlist) { if (vp2->v_hash != hash) continue; if (vp2->v_mount != vp->v_mount) @@ -117,6 +122,9 @@ vfs_hash_insert(struct vnode *vp, u_int hash, int flags, struct thread *td, stru error = vget(vp2, flags | LK_INTERLOCK, td); if (error == ENOENT) break; + mtx_lock(&vfs_hash_mtx); + LIST_INSERT_HEAD(&vfs_hash_side, vp, v_hashlist); + mtx_unlock(&vfs_hash_mtx); vput(vp); if (!error) *vpp = vp2; @@ -126,13 +134,8 @@ vfs_hash_insert(struct vnode *vp, u_int hash, int flags, struct thread *td, stru break; } - VI_LOCK(vp); - VNASSERT(!(vp->v_iflag & VI_HASHED), vp, - ("vfs_hash_insert: already hashed")); vp->v_hash = hash; - LIST_INSERT_HEAD(&vfs_hash_tbl[hash & vfs_hash_mask], vp, v_hashlist); - vp->v_iflag |= VI_HASHED; - VI_UNLOCK(vp); + LIST_INSERT_HEAD(vfs_hash_index(vp->v_mount, hash), vp, v_hashlist); mtx_unlock(&vfs_hash_mtx); return (0); } @@ -142,7 +145,6 @@ vfs_hash_rehash(struct vnode *vp, u_int hash) { mtx_lock(&vfs_hash_mtx); - VNASSERT(vp->v_iflag & VI_HASHED, vp, ("vfs_hash_rehash: not hashed")); LIST_REMOVE(vp, v_hashlist); LIST_INSERT_HEAD(&vfs_hash_tbl[hash & vfs_hash_mask], vp, v_hashlist); vp->v_hash = hash; |