Index: kern/vfs_cache.c =================================================================== RCS file: /home/ncvs/src/sys/kern/vfs_cache.c,v retrieving revision 1.52 retrieving revision 1.54 diff -u -2 -r1.52 -r1.54 --- kern/vfs_cache.c 2000/12/08 20:08:26 1.52 +++ kern/vfs_cache.c 2001/03/20 02:10:18 1.54 @@ -49,4 +49,5 @@ #include #include +#include /* @@ -86,6 +87,6 @@ * Structures associated with name cacheing. */ -#define NCHHASH(dvp, hash) \ - (&nchashtbl[((dvp)->v_id + (hash)) & nchash]) +#define NCHHASH(hash) \ + (&nchashtbl[(hash) & nchash]) static LIST_HEAD(nchashhead, namecache) *nchashtbl; /* Hash Table */ static TAILQ_HEAD(, namecache) ncneg; /* Hash Table */ @@ -181,7 +182,5 @@ { struct namecache *ncp; - u_long hash; - u_char *cp; - int len; + u_int32_t hash; if (!doingcache) { @@ -210,9 +209,7 @@ } - hash = 0; - len = cnp->cn_namelen; - for (cp = cnp->cn_nameptr; len; len--, cp++) - hash += *cp; - LIST_FOREACH(ncp, (NCHHASH(dvp, hash)), nc_hash) { + hash = fnv_32_buf(cnp->cn_nameptr, cnp->cn_namelen, FNV1_32_INIT); + hash = fnv_32_buf(&dvp->v_id, sizeof(dvp->v_id), hash); + LIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) { numchecks++; if (ncp->nc_dvp == dvp && ncp->nc_nlen == cnp->cn_namelen && @@ -280,6 +277,5 @@ struct namecache *ncp; struct nchashhead *ncpp; - u_long hash; - u_char *cp, *dp; + u_int32_t hash; int len; @@ -324,9 +320,8 @@ 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); - ncpp = NCHHASH(dvp, hash); + hash = fnv_32_buf(cnp->cn_nameptr, len, FNV1_32_INIT); + bcopy(cnp->cn_nameptr, ncp->nc_name, len); + hash = fnv_32_buf(&dvp->v_id, sizeof(dvp->v_id), hash); + ncpp = NCHHASH(hash); LIST_INSERT_HEAD(ncpp, ncp, nc_hash); if (LIST_EMPTY(&dvp->v_cache_src)) Index: sys/fnv_hash.h =================================================================== RCS file: fnv_hash.h diff -N fnv_hash.h --- /dev/null Mon Mar 19 18:30:25 2001 +++ /tmp/cvseYyyg52957 Mon Mar 19 18:32:49 2001 @@ -0,0 +1,68 @@ +/* + * Fowler / Noll / Vo Hash (FNV Hash) + * http://www.isthe.com/chongo/tech/comp/fnv/ + * + * This is an implementation of the algorithms posted above. + * This file is placed in the public domain by Peter Wemm. + * + * $FreeBSD$ + */ + +typedef u_int32_t Fnv32_t; +typedef u_int64_t Fnv64_t; + +#define FNV1_32_INIT ((Fnv32_t) 33554467UL) +#define FNV1_64_INIT ((Fnv64_t) 0xcbf29ce484222325ULL) + +#define FNV_32_PRIME ((Fnv32_t) 0x01000193UL) +#define FNV_64_PRIME ((Fnv64_t) 0x100000001b3ULL) + +static __inline Fnv32_t +fnv_32_buf(const void *buf, size_t len, Fnv32_t hval) +{ + const u_int8_t *s = (const u_int8_t *)buf; + + while (len-- != 0) { + hval *= FNV_32_PRIME; + hval ^= *s++; + } + return hval; +} + +static __inline Fnv32_t +fnv_32_str(const char *str, Fnv32_t hval) +{ + const u_int8_t *s = (const u_int8_t *)str; + Fnv32_t c; + + while ((c = *s++) != 0) { + hval *= FNV_32_PRIME; + hval ^= c; + } + return hval; +} + +static __inline Fnv64_t +fnv_64_buf(const void *buf, size_t len, Fnv64_t hval) +{ + const u_int8_t *s = (const u_int8_t *)buf; + + while (len-- != 0) { + hval *= FNV_64_PRIME; + hval ^= *s++; + } + return hval; +} + +static __inline Fnv64_t +fnv_64_str(const char *str, Fnv64_t hval) +{ + const u_int8_t *s = (const u_int8_t *)str; + u_register_t c; /* 32 bit on i386, 64 bit on alpha,ia64 */ + + while ((c = *s++) != 0) { + hval *= FNV_64_PRIME; + hval ^= c; + } + return hval; +} Index: nfs/nfs.h =================================================================== RCS file: /home/ncvs/src/sys/nfs/nfs.h,v retrieving revision 1.57 retrieving revision 1.58 diff -u -2 -r1.57 -r1.58 --- nfs/nfs.h 2001/02/18 13:30:19 1.57 +++ nfs/nfs.h 2001/03/17 09:31:06 1.58 @@ -634,5 +634,4 @@ void nfs_nhinit __P((void)); void nfs_timer __P((void*)); -u_long nfs_hash __P((nfsfh_t *, int)); int nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *, struct nfsrv_descript **)); Index: nfs/nfs_node.c =================================================================== RCS file: /home/ncvs/src/sys/nfs/nfs_node.c,v retrieving revision 1.42 retrieving revision 1.45 diff -u -2 -r1.42 -r1.45 --- nfs/nfs_node.c 2000/11/14 08:00:39 1.42 +++ nfs/nfs_node.c 2001/03/20 02:10:18 1.45 @@ -45,4 +45,5 @@ #include #include +#include #include @@ -73,23 +74,4 @@ /* - * Compute an entry in the NFS hash table structure - */ -u_long -nfs_hash(fhp, fhsize) - register nfsfh_t *fhp; - int fhsize; -{ - register u_char *fhpp; - register u_long fhsum; - register int i; - - fhpp = &fhp->fh_bytes[0]; - fhsum = 0; - for (i = 0; i < fhsize; i++) - fhsum += *fhpp++; - return (fhsum); -} - -/* * Look up a vnode/nfsnode by file handle. * Callers must check for mount points!! @@ -126,5 +108,5 @@ retry: - nhpp = NFSNOHASH(nfs_hash(fhp, fhsize)); + nhpp = NFSNOHASH(fnv_32_buf(fhp->fh_bytes, fhsize, FNV1_32_INIT)); loop: for (np = nhpp->lh_first; np != 0; np = np->n_hash.le_next) { Index: alpha/include/types.h =================================================================== RCS file: /home/ncvs/src/sys/alpha/include/types.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -2 -r1.13 -r1.14 --- alpha/include/types.h 2000/09/13 18:33:21 1.13 +++ alpha/include/types.h 2001/03/17 09:31:05 1.14 @@ -57,6 +57,6 @@ typedef unsigned long vm_size_t; - typedef __int64_t register_t; +typedef __uint64_t u_register_t; #ifdef _KERNEL Index: i386/include/types.h =================================================================== RCS file: /home/ncvs/src/sys/i386/include/types.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -2 -r1.20 -r1.21 --- i386/include/types.h 2000/09/13 18:33:22 1.20 +++ i386/include/types.h 2001/03/17 09:31:05 1.21 @@ -54,5 +54,5 @@ typedef __int32_t register_t; - +typedef __uint32_t u_register_t; #ifdef _KERNEL