git: 2749c222da8a - main - vfs cache: sanitize debug counters

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Thu, 05 Oct 2023 12:44:48 UTC
The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=2749c222da8a6325d39c0571f72b1dbed2f7d583

commit 2749c222da8a6325d39c0571f72b1dbed2f7d583
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-10-05 12:16:18 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-10-05 12:44:42 +0000

    vfs cache: sanitize debug counters
    
    They are very rarely triggered, so no need for per-cpu distribution.
    
    At the same time the non-cpu ones still should use atomics to not lose
    any updates.
---
 sys/kern/vfs_cache.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index 6ae4239cc11d..00632716a2ec 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -628,17 +628,14 @@ static SYSCTL_NODE(_vfs_cache, OID_AUTO, debug, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
     "Name cache debugging");
 #define DEBUGNODE_ULONG(name, varname, descr)					\
 	SYSCTL_ULONG(_vfs_cache_debug, OID_AUTO, name, CTLFLAG_RD, &varname, 0, descr);
-#define DEBUGNODE_COUNTER(name, varname, descr)					\
-	static COUNTER_U64_DEFINE_EARLY(varname);				\
-	SYSCTL_COUNTER_U64(_vfs_cache_debug, OID_AUTO, name, CTLFLAG_RD, &varname, \
-	    descr);
-DEBUGNODE_COUNTER(zap_bucket_relock_success, zap_bucket_relock_success,
+static u_long zap_bucket_relock_success;
+DEBUGNODE_ULONG(zap_bucket_relock_success, zap_bucket_relock_success,
     "Number of successful removals after relocking");
-static long zap_bucket_fail;
+static u_long zap_bucket_fail;
 DEBUGNODE_ULONG(zap_bucket_fail, zap_bucket_fail, "");
-static long zap_bucket_fail2;
+static u_long zap_bucket_fail2;
 DEBUGNODE_ULONG(zap_bucket_fail2, zap_bucket_fail2, "");
-static long cache_lock_vnodes_cel_3_failures;
+static u_long cache_lock_vnodes_cel_3_failures;
 DEBUGNODE_ULONG(vnodes_cel_3_failures, cache_lock_vnodes_cel_3_failures,
     "Number of times 3-way vnode locking failed");
 
@@ -1739,7 +1736,7 @@ cache_zap_unlocked_bucket(struct namecache *ncp, struct componentname *cnp,
 		cache_zap_locked(rncp);
 		mtx_unlock(blp);
 		cache_unlock_vnodes(dvlp, vlp);
-		counter_u64_add(zap_bucket_relock_success, 1);
+		atomic_add_long(&zap_bucket_relock_success, 1);
 		return (0);
 	}
 
@@ -1835,7 +1832,7 @@ retry:
 
 	error = cache_zap_locked_bucket(ncp, cnp, hash, blp);
 	if (__predict_false(error != 0)) {
-		zap_bucket_fail++;
+		atomic_add_long(&zap_bucket_fail, 1);
 		goto retry;
 	}
 	counter_u64_add(numposzaps, 1);
@@ -2061,7 +2058,7 @@ negative_success:
 			counter_u64_add(numnegzaps, 1);
 			error = cache_zap_locked_bucket(ncp, cnp, hash, blp);
 			if (__predict_false(error != 0)) {
-				zap_bucket_fail2++;
+				atomic_add_long(&zap_bucket_fail2, 1);
 				goto retry;
 			}
 			cache_free(ncp);
@@ -2259,8 +2256,8 @@ cache_lock_vnodes_cel_3(struct celockstate *cel, struct vnode *vp)
 	} else {
 		if (mtx_trylock(vlp))
 			goto out;
-		cache_lock_vnodes_cel_3_failures++;
 		cache_unlock_vnodes_cel(cel);
+		atomic_add_long(&cache_lock_vnodes_cel_3_failures, 1);
 		if (vlp < cel->vlp[0]) {
 			mtx_lock(vlp);
 			mtx_lock(cel->vlp[0]);