summaryrefslogtreecommitdiffstats
path: root/sys/kern/vfs_cache.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2001-03-17 09:31:06 +0000
committerpeter <peter@FreeBSD.org>2001-03-17 09:31:06 +0000
commit670e711dd19510316ecaa1f30d78f16ba66492f6 (patch)
treedf728469695bfff83fcf93f9e9a460606a09b3f1 /sys/kern/vfs_cache.c
parent400aa0706c1d55d12d0405666ddac2d3e3ec5d69 (diff)
downloadFreeBSD-src-670e711dd19510316ecaa1f30d78f16ba66492f6.zip
FreeBSD-src-670e711dd19510316ecaa1f30d78f16ba66492f6.tar.gz
Use a generic implementation of the Fowler/Noll/Vo hash (FNV hash).
Make the name cache hash as well as the nfsnode hash use it. As a special tweak, create an unsigned version of register_t. This allows us to use a special tweak for the 64 bit versions that significantly speeds up the i386 version (ie: int64 XOR int64 is slower than int64 XOR int32). The code layout is a little strange for the string function, but I was able to get between 5 to 10% improvement over the original version I started with. The layout affects gcc code generation choices and this way was fastest on x86 and alpha. Note that 'CPUTYPE=p3' etc makes a fair difference to this. It is around 45% faster with -march=pentiumpro on a p6 cpu.
Diffstat (limited to 'sys/kern/vfs_cache.c')
-rw-r--r--sys/kern/vfs_cache.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index 6657523..3f92c8f 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -48,6 +48,7 @@
#include <sys/sysproto.h>
#include <sys/proc.h>
#include <sys/filedesc.h>
+#include <sys/fnv_hash.h>
/*
* This structure describes the elements in the cache of recent
@@ -180,9 +181,7 @@ cache_lookup(dvp, vpp, cnp)
struct componentname *cnp;
{
struct namecache *ncp;
- u_long hash;
- u_char *cp;
- int len;
+ u_int32_t hash;
if (!doingcache) {
cnp->cn_flags &= ~MAKEENTRY;
@@ -209,10 +208,7 @@ cache_lookup(dvp, vpp, cnp)
}
}
- hash = 0;
- len = cnp->cn_namelen;
- for (cp = cnp->cn_nameptr; len; len--, cp++)
- hash += *cp;
+ hash = fnv32_hashbuf(cnp->cn_nameptr, cnp->cn_namelen);
LIST_FOREACH(ncp, (NCHHASH(dvp, hash)), nc_hash) {
numchecks++;
if (ncp->nc_dvp == dvp && ncp->nc_nlen == cnp->cn_namelen &&
@@ -279,8 +275,7 @@ cache_enter(dvp, vp, cnp)
{
struct namecache *ncp;
struct nchashhead *ncpp;
- u_long hash;
- u_char *cp, *dp;
+ u_int32_t hash;
int len;
if (!doingcache)
@@ -323,10 +318,8 @@ cache_enter(dvp, vp, cnp)
ncp->nc_vp = vp;
ncp->nc_dvp = dvp;
len = ncp->nc_nlen = cnp->cn_namelen;
- hash = 0;
- dp = ncp->nc_name;
- for (cp = cnp->cn_nameptr; len; len--, cp++, dp++)
- hash += (*dp = *cp);
+ hash = fnv32_hashbuf(cnp->cn_nameptr, len);
+ bcopy(cnp->cn_nameptr, ncp->nc_name, len);
ncpp = NCHHASH(dvp, hash);
LIST_INSERT_HEAD(ncpp, ncp, nc_hash);
if (LIST_EMPTY(&dvp->v_cache_src))
OpenPOWER on IntegriCloud