summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1997-03-08 15:22:14 +0000
committerbde <bde@FreeBSD.org>1997-03-08 15:22:14 +0000
commitcaf27c1d1730c0bcb09fa9655332ae7515ddc6c2 (patch)
treed44bf479e2d35ef0adc5af86e26b5e6b37f33e60 /sys/kern
parentd3df6f9beba08586927062fa3ad7d45cf30506d2 (diff)
downloadFreeBSD-src-caf27c1d1730c0bcb09fa9655332ae7515ddc6c2.zip
FreeBSD-src-caf27c1d1730c0bcb09fa9655332ae7515ddc6c2.tar.gz
Fixed the hash formula. Lite2 doesn't have phashinit(), so Lite2's hash
formula uses `& nchash'. This is very broken when nchash is a prime number instead of 1 less than a power of 2, but the Lite2 formula was merged in. Merged some cosmetic changes from Lite2, rev.1.21 and Lite1. The merge was difficult because the Lite2 code is essentially ours (phk's) except where Lite2 improved or broke it. Summary of the Lite2 changes: - in the copyright, phk's rights have been transferred to the Regents. This change should be reviewed. - nchENOENT went away; the "no" vnode is now simply 0. - comments were improved. - style was "improved". - goto instead of Fanatism (sic) was considered bad :-). - there are some small changes to support whiteouts. - new cache entries are added in more cases. More work is required near here to change the hash table size if kern.desiredvnodes is changed using sysctl. - rescanning of the hash bucket in cache_purgevfs() was removed. This change should be reviewed.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/vfs_cache.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index 3c611a1..ef0f222 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)vfs_cache.c 8.3 (Berkeley) 8/22/94
- * $Id$
+ * @(#)vfs_cache.c 8.5 (Berkeley) 3/22/95
+ * $Id: vfs_cache.c,v 1.23 1997/02/22 09:39:31 peter Exp $
*/
#include <sys/param.h>
@@ -75,15 +75,16 @@
* Structures associated with name cacheing.
*/
#define NCHHASH(dvp, cnp) \
- (&nchashtbl[((dvp)->v_id + (cnp)->cn_hash) & nchash])
+ (&nchashtbl[((dvp)->v_id + (cnp)->cn_hash) % nchash])
static LIST_HEAD(nchashhead, namecache) *nchashtbl; /* Hash Table */
-static u_long nchash; /* size of hash table - 1 */
-static int doingcache = 1; /* 1 => enable the cache */
-SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0, "");
-static u_long numcache; /* number of cache entries allocated */
+static u_long nchash; /* size of hash table */
+static u_long numcache; /* number of cache entries allocated */
static TAILQ_HEAD(, namecache) nclruhead; /* LRU chain */
struct nchstats nchstats; /* cache effectiveness statistics */
+static int doingcache = 1; /* 1 => enable the cache */
+SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0, "");
+
#ifdef NCH_STATISTICS
u_long nchnbr;
#define NCHNBR(ncp) (ncp)->nc_nbr = ++nchnbr;
@@ -117,9 +118,9 @@ u_long nchnbr;
}
/*
- * Lookup an entry in the cache
+ * Lookup an entry in the cache
*
- * We don't do this if the segment name is long, simply so the cache
+ * We don't do this if the segment name is long, simply so the cache
* can avoid holding long names (which would either waste space, or
* add greatly to the complexity).
*
@@ -144,7 +145,6 @@ cache_lookup(dvp, vpp, cnp)
cnp->cn_flags &= ~MAKEENTRY;
return (0);
}
-
if (cnp->cn_namelen > NCHNAMLEN) {
nchstats.ncs_long++;
cnp->cn_flags &= ~MAKEENTRY;
@@ -181,7 +181,7 @@ cache_lookup(dvp, vpp, cnp)
nchstats.ncs_badhits++;
PURGE(ncp);
return (0);
- }
+ }
/* We found a "positive" match, return the vnode */
if (ncp->nc_vp) {
@@ -225,12 +225,10 @@ cache_enter(dvp, vp, cnp)
if (!doingcache)
return;
-#ifdef DIAGNOSTIC
if (cnp->cn_namelen > NCHNAMLEN) {
printf("cache_enter: name too long");
return;
}
-#endif
/*
* We allocate a new entry if we are less than the maximum
@@ -256,6 +254,7 @@ cache_enter(dvp, vp, cnp)
/* give up */
return;
}
+
/*
* Fill in cache info, if vp is NULL this is a "negative" cache entry.
* For negative entries, we have to record whether it is a whiteout.
@@ -284,13 +283,14 @@ cache_enter(dvp, vp, cnp)
void
nchinit()
{
+
TAILQ_INIT(&nclruhead);
nchashtbl = phashinit(desiredvnodes, M_CACHE, &nchash);
}
/*
* Invalidate all entries to particular vnode.
- *
+ *
* We actually just increment the v_id, that will do it. The stale entries
* will be purged by lookup as they get found. If the v_id wraps around, we
* need to ditch the entire cache, to avoid confusion. No valid vnode will
OpenPOWER on IntegriCloud