summaryrefslogtreecommitdiffstats
path: root/sys/kern/vfs_cache.c
diff options
context:
space:
mode:
authormckusick <mckusick@FreeBSD.org>2015-04-18 00:59:03 +0000
committermckusick <mckusick@FreeBSD.org>2015-04-18 00:59:03 +0000
commit88e3f42497b69ea964aa3a8f080f0f08547a4dbd (patch)
treeccc71b858b9c5f5a827d98b37984926ba7f8c44c /sys/kern/vfs_cache.c
parent3664663620aec0e5d52709d1601cced0b0ed3b0a (diff)
downloadFreeBSD-src-88e3f42497b69ea964aa3a8f080f0f08547a4dbd.zip
FreeBSD-src-88e3f42497b69ea964aa3a8f080f0f08547a4dbd.tar.gz
More accurately collect name-cache statistics in sysctl functions
sysctl_debug_hashstat_nchash() and sysctl_debug_hashstat_rawnchash(). These changes are in preparation for allowing changes in the size of the vnode hash tables driven by increases and decreases in the maximum number of vnodes in the system. Reviewed by: kib@ Phabric: D2265
Diffstat (limited to 'sys/kern/vfs_cache.c')
-rw-r--r--sys/kern/vfs_cache.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index d57dc90..42d32e7 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -323,29 +323,25 @@ static SYSCTL_NODE(_debug, OID_AUTO, hashstat, CTLFLAG_RW, NULL,
static int
sysctl_debug_hashstat_rawnchash(SYSCTL_HANDLER_ARGS)
{
- int error;
struct nchashhead *ncpp;
struct namecache *ncp;
- int n_nchash;
- int count;
+ int i, error, n_nchash, *cntbuf;
n_nchash = nchash + 1; /* nchash is max index, not count */
- if (!req->oldptr)
+ if (req->oldptr == NULL)
return SYSCTL_OUT(req, 0, n_nchash * sizeof(int));
-
- /* Scan hash tables for applicable entries */
- for (ncpp = nchashtbl; n_nchash > 0; n_nchash--, ncpp++) {
- CACHE_RLOCK();
- count = 0;
- LIST_FOREACH(ncp, ncpp, nc_hash) {
- count++;
- }
- CACHE_RUNLOCK();
- error = SYSCTL_OUT(req, &count, sizeof(count));
- if (error)
- return (error);
- }
- return (0);
+ cntbuf = malloc(n_nchash * sizeof(int), M_TEMP, M_ZERO | M_WAITOK);
+ CACHE_RLOCK();
+ /* Scan hash tables counting entries */
+ for (ncpp = nchashtbl, i = 0; i < n_nchash; ncpp++, i++)
+ LIST_FOREACH(ncp, ncpp, nc_hash)
+ cntbuf[i]++;
+ CACHE_RUNLOCK();
+ for (error = 0, i = 0; i < n_nchash; i++)
+ if ((error = SYSCTL_OUT(req, &cntbuf[i], sizeof(int))) != 0)
+ break;
+ free(cntbuf, M_TEMP);
+ return (error);
}
SYSCTL_PROC(_debug_hashstat, OID_AUTO, rawnchash, CTLTYPE_INT|CTLFLAG_RD|
CTLFLAG_MPSAFE, 0, 0, sysctl_debug_hashstat_rawnchash, "S,int",
@@ -363,6 +359,7 @@ sysctl_debug_hashstat_nchash(SYSCTL_HANDLER_ARGS)
if (!req->oldptr)
return SYSCTL_OUT(req, 0, 4 * sizeof(int));
+ CACHE_RLOCK();
n_nchash = nchash + 1; /* nchash is max index, not count */
used = 0;
maxlength = 0;
@@ -370,17 +367,16 @@ sysctl_debug_hashstat_nchash(SYSCTL_HANDLER_ARGS)
/* Scan hash tables for applicable entries */
for (ncpp = nchashtbl; n_nchash > 0; n_nchash--, ncpp++) {
count = 0;
- CACHE_RLOCK();
LIST_FOREACH(ncp, ncpp, nc_hash) {
count++;
}
- CACHE_RUNLOCK();
if (count)
used++;
if (maxlength < count)
maxlength = count;
}
n_nchash = nchash + 1;
+ CACHE_RUNLOCK();
pct = (used * 100) / (n_nchash / 100);
error = SYSCTL_OUT(req, &n_nchash, sizeof(n_nchash));
if (error)
OpenPOWER on IntegriCloud