Module Name:    src
Committed By:   joerg
Date:           Sat Jun 14 16:12:34 UTC 2014

Modified Files:
        src/sys/kern: vfs_cache.c

Log Message:
Make the stat mutex a leaf. XXX Use atomic counters.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/kern/vfs_cache.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_cache.c
diff -u src/sys/kern/vfs_cache.c:1.97 src/sys/kern/vfs_cache.c:1.98
--- src/sys/kern/vfs_cache.c:1.97	Tue Jun  3 21:16:15 2014
+++ src/sys/kern/vfs_cache.c	Sat Jun 14 16:12:34 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_cache.c,v 1.97 2014/06/03 21:16:15 joerg Exp $	*/
+/*	$NetBSD: vfs_cache.c,v 1.98 2014/06/14 16:12:34 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.97 2014/06/03 21:16:15 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.98 2014/06/14 16:12:34 joerg Exp $");
 
 #include "opt_ddb.h"
 #include "opt_revcache.h"
@@ -388,8 +388,8 @@ cache_lookup(struct vnode *dvp, const ch
 	}
 
 	cpup = curcpu()->ci_data.cpu_nch;
-	mutex_enter(&cpup->cpu_lock);
 	if (__predict_false(namelen > NCHNAMLEN)) {
+		mutex_enter(&cpup->cpu_lock);
 		COUNT(cpup->cpu_stats, ncs_long);
 		mutex_exit(&cpup->cpu_lock);
 		/* found nothing */
@@ -397,13 +397,16 @@ cache_lookup(struct vnode *dvp, const ch
 	}
 	ncp = cache_lookup_entry(dvp, name, namelen);
 	if (__predict_false(ncp == NULL)) {
+		mutex_enter(&cpup->cpu_lock);
 		COUNT(cpup->cpu_stats, ncs_miss);
 		mutex_exit(&cpup->cpu_lock);
 		/* found nothing */
 		return 0;
 	}
 	if ((cnflags & MAKEENTRY) == 0) {
+		mutex_enter(&cpup->cpu_lock);
 		COUNT(cpup->cpu_stats, ncs_badhits);
+		mutex_exit(&cpup->cpu_lock);
 		/*
 		 * Last component and we are renaming or deleting,
 		 * the cache entry is invalid, or otherwise don't
@@ -411,7 +414,6 @@ cache_lookup(struct vnode *dvp, const ch
 		 */
 		cache_invalidate(ncp);
 		mutex_exit(&ncp->nc_lock);
-		mutex_exit(&cpup->cpu_lock);
 		/* found nothing */
 		return 0;
 	}
@@ -428,13 +430,16 @@ cache_lookup(struct vnode *dvp, const ch
 
 		if (__predict_true(nameiop != CREATE ||
 		    (cnflags & ISLASTCN) == 0)) {
+			mutex_enter(&cpup->cpu_lock);
 			COUNT(cpup->cpu_stats, ncs_neghits);
-			mutex_exit(&ncp->nc_lock);
 			mutex_exit(&cpup->cpu_lock);
+			mutex_exit(&ncp->nc_lock);
 			/* found neg entry; vn is already null from above */
 			return 1;
 		} else {
+			mutex_enter(&cpup->cpu_lock);
 			COUNT(cpup->cpu_stats, ncs_badhits);
+			mutex_exit(&cpup->cpu_lock);
 			/*
 			 * Last component and we are renaming or
 			 * deleting, the cache entry is invalid,
@@ -443,7 +448,6 @@ cache_lookup(struct vnode *dvp, const ch
 			 */
 			cache_invalidate(ncp);
 			mutex_exit(&ncp->nc_lock);
-			mutex_exit(&cpup->cpu_lock);
 			/* found nothing */
 			return 0;
 		}
@@ -452,7 +456,6 @@ cache_lookup(struct vnode *dvp, const ch
 	vp = ncp->nc_vp;
 	mutex_enter(vp->v_interlock);
 	mutex_exit(&ncp->nc_lock);
-	mutex_exit(&cpup->cpu_lock);
 	error = vget(vp, LK_NOWAIT);
 	if (error) {
 		KASSERT(error == EBUSY);
@@ -460,7 +463,9 @@ cache_lookup(struct vnode *dvp, const ch
 		 * This vnode is being cleaned out.
 		 * XXX badhits?
 		 */
+		mutex_enter(&cpup->cpu_lock);
 		COUNT(cpup->cpu_stats, ncs_falsehits);
+		mutex_exit(&cpup->cpu_lock);
 		/* found nothing */
 		return 0;
 	}
@@ -474,7 +479,9 @@ cache_lookup(struct vnode *dvp, const ch
 #endif /* DEBUG */
 
 	/* We don't have the right lock, but this is only for stats. */
+	mutex_enter(&cpup->cpu_lock);
 	COUNT(cpup->cpu_stats, ncs_goodhits);
+	mutex_exit(&cpup->cpu_lock);
 
 	/* found it */
 	*vn_ret = vp;
@@ -503,8 +510,8 @@ cache_lookup_raw(struct vnode *dvp, cons
 	}
 
 	cpup = curcpu()->ci_data.cpu_nch;
-	mutex_enter(&cpup->cpu_lock);
 	if (__predict_false(namelen > NCHNAMLEN)) {
+		mutex_enter(&cpup->cpu_lock);
 		COUNT(cpup->cpu_stats, ncs_long);
 		mutex_exit(&cpup->cpu_lock);
 		/* found nothing */
@@ -512,6 +519,7 @@ cache_lookup_raw(struct vnode *dvp, cons
 	}
 	ncp = cache_lookup_entry(dvp, name, namelen);
 	if (__predict_false(ncp == NULL)) {
+		mutex_enter(&cpup->cpu_lock);
 		COUNT(cpup->cpu_stats, ncs_miss);
 		mutex_exit(&cpup->cpu_lock);
 		/* found nothing */
@@ -527,15 +535,15 @@ cache_lookup_raw(struct vnode *dvp, cons
 			/*cnp->cn_flags |= ncp->nc_flags;*/
 			*iswht_ret = (ncp->nc_flags & ISWHITEOUT) != 0;
 		}
+		mutex_enter(&cpup->cpu_lock);
 		COUNT(cpup->cpu_stats, ncs_neghits);
-		mutex_exit(&ncp->nc_lock);
 		mutex_exit(&cpup->cpu_lock);
+		mutex_exit(&ncp->nc_lock);
 		/* found negative entry; vn is already null from above */
 		return 1;
 	}
 	mutex_enter(vp->v_interlock);
 	mutex_exit(&ncp->nc_lock);
-	mutex_exit(&cpup->cpu_lock);
 	error = vget(vp, LK_NOWAIT);
 	if (error) {
 		KASSERT(error == EBUSY);
@@ -543,7 +551,9 @@ cache_lookup_raw(struct vnode *dvp, cons
 		 * This vnode is being cleaned out.
 		 * XXX badhits?
 		 */
+		mutex_enter(&cpup->cpu_lock);
 		COUNT(cpup->cpu_stats, ncs_falsehits);
+		mutex_exit(&cpup->cpu_lock);
 		/* found nothing */
 		return 0;
 	}

Reply via email to