From owner-svn-src-all@FreeBSD.ORG Sat Apr 18 00:59:04 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DD3F5C2; Sat, 18 Apr 2015 00:59:04 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B1F68971; Sat, 18 Apr 2015 00:59:04 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t3I0x4ka004987; Sat, 18 Apr 2015 00:59:04 GMT (envelope-from mckusick@FreeBSD.org) Received: (from mckusick@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t3I0x4NT004986; Sat, 18 Apr 2015 00:59:04 GMT (envelope-from mckusick@FreeBSD.org) Message-Id: <201504180059.t3I0x4NT004986@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mckusick set sender to mckusick@FreeBSD.org using -f From: Kirk McKusick Date: Sat, 18 Apr 2015 00:59:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r281677 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Apr 2015 00:59:05 -0000 Author: mckusick Date: Sat Apr 18 00:59:03 2015 New Revision: 281677 URL: https://svnweb.freebsd.org/changeset/base/281677 Log: 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 Modified: head/sys/kern/vfs_cache.c Modified: head/sys/kern/vfs_cache.c ============================================================================== --- head/sys/kern/vfs_cache.c Sat Apr 18 00:53:52 2015 (r281676) +++ head/sys/kern/vfs_cache.c Sat Apr 18 00:59:03 2015 (r281677) @@ -323,29 +323,25 @@ static SYSCTL_NODE(_debug, OID_AUTO, has 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_HAND 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_HAND /* 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)