summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2005-03-16 07:35:06 +0000
committerphk <phk@FreeBSD.org>2005-03-16 07:35:06 +0000
commite61634909a711e4dc62a5b7c64acc1ddabc9c351 (patch)
tree2a5ad25ecb42bea9ee693b1e0d5f739148d0b162 /sys
parenteeb2c527c0ecb4fc525ae4af75f02284359c1a3a (diff)
downloadFreeBSD-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')
-rw-r--r--sys/kern/vfs_hash.c32
-rw-r--r--sys/kern/vfs_mount.c1
-rw-r--r--sys/sys/mount.h1
-rw-r--r--sys/sys/vnode.h1
4 files changed, 19 insertions, 16 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;
diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c
index 94e2715..7930386 100644
--- a/sys/kern/vfs_mount.c
+++ b/sys/kern/vfs_mount.c
@@ -428,6 +428,7 @@ vfs_mount_alloc(struct vnode *vp, struct vfsconf *vfsp,
mac_init_mount(mp);
mac_create_mount(td->td_ucred, mp);
#endif
+ arc4rand(&mp->mnt_hashseed, sizeof mp->mnt_hashseed, 0);
*mpp = mp;
return (0);
}
diff --git a/sys/sys/mount.h b/sys/sys/mount.h
index 527ed44..3c4cf2e 100644
--- a/sys/sys/mount.h
+++ b/sys/sys/mount.h
@@ -159,6 +159,7 @@ struct mount {
struct label *mnt_mntlabel; /* MAC label for the mount */
struct label *mnt_fslabel; /* MAC label for the fs */
int mnt_nvnodelistsize; /* # of vnodes on this mount */
+ u_int mnt_hashseed; /* Random seed for vfs_hash */
};
struct vnode *__mnt_vnode_next(struct vnode **nvp, struct mount *mp);
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index f12427d..920df12 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -238,7 +238,6 @@ struct xvnode {
* VI flags are protected by interlock and live in v_iflag
* VV flags are protected by the vnode lock and live in v_vflag
*/
-#define VI_HASHED 0x0004 /* vnode is hashed in vfs_hash */
#define VI_MOUNT 0x0020 /* Mount in progress */
#define VI_AGE 0x0040 /* Insert vnode at head of free list */
#define VI_DOOMED 0x0080 /* This vnode is being recycled */
OpenPOWER on IntegriCloud