Subject: wide mode output for vmstat pool info
To: None <tech-userlevel@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-userlevel
Date: 01/14/2005 18:06:14
--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

A few folks were looking at the output of "vmstat -m", and noticed that
it was difficult to make the utilisation figures for pools add up.  The
reason for this is that a pool's page size isn't necessarily the native
system page size.  The following patch adds a -W flag to display more
information for each pool.  I've also included a with and without -W
output (from a pc532).

The other change was with "wide mode" to make the columns wider so that
they should line up nicely on busy systems that have been up for a long
time.

I'll commit this in a few days unless anyone has any problems,
suggestions, etc about this.

Simon.
--
Simon Burge                                   <simonb@wasabisystems.com>
NetBSD Development, Support and Service:   http://www.wasabisystems.com/

--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff-W

? diff-W
Index: vmstat.1
===================================================================
RCS file: /cvsroot/src/usr.bin/vmstat/vmstat.1,v
retrieving revision 1.12
diff -d -p -u -r1.12 vmstat.1
--- vmstat.1	13 Feb 2004 10:16:08 -0000	1.12
+++ vmstat.1	14 Jan 2005 07:03:31 -0000
@@ -68,7 +68,7 @@
 .Nd report virtual memory statistics
 .Sh SYNOPSIS
 .Nm
-.Op Fl efHilLmsUv
+.Op Fl efHilLmsUvW
 .Bk -words
 .Op Fl M Ar core
 .Ek
@@ -150,6 +150,8 @@ When used with the
 or
 .Fl m
 options prints out all counters, not just those with non-zero values.
+.It Fl W
+Print more verbose information about kernel memory pools.
 .It Fl w Ar wait
 Pause
 .Ar wait
Index: vmstat.c
===================================================================
RCS file: /cvsroot/src/usr.bin/vmstat/vmstat.c,v
retrieving revision 1.125
diff -d -p -u -r1.125 vmstat.c
--- vmstat.c	20 Dec 2004 08:20:50 -0000	1.125
+++ vmstat.c	14 Jan 2005 07:03:32 -0000
@@ -245,7 +245,7 @@ void	doevcnt(int verbose);
 void	dohashstat(int, int, const char *);
 void	dointr(int verbose);
 void	domem(void);
-void	dopool(int);
+void	dopool(int, int);
 void	dopoolcache(struct pool *, int);
 void	dosum(void);
 void	dovmstat(struct timespec *, int);
@@ -272,7 +272,7 @@ char	*nlistf, *memf;
 int
 main(int argc, char *argv[])
 {
-	int c, todo, verbose;
+	int c, todo, verbose, wide;
 	struct timespec interval;
 	int reps;
 	char errbuf[_POSIX2_LINE_MAX];
@@ -282,10 +282,10 @@ main(int argc, char *argv[])
 	histname = hashname = NULL;
 	(void)setegid(getgid());
 	memf = nlistf = NULL;
-	reps = todo = verbose = 0;
+	reps = todo = verbose = wide = 0;
 	interval.tv_sec = 0;
 	interval.tv_nsec = 0;
-	while ((c = getopt(argc, argv, "c:efh:HilLM:mN:su:Uvw:")) != -1) {
+	while ((c = getopt(argc, argv, "c:efh:HilLM:mN:su:UvWw:")) != -1) {
 		switch (c) {
 		case 'c':
 			reps = atoi(optarg);
@@ -332,6 +332,9 @@ main(int argc, char *argv[])
 		case 'v':
 			verbose++;
 			break;
+		case 'W':
+			wide++;
+			break;
 		case 'w':
 			interval.tv_sec = atol(optarg);
 			break;
@@ -430,7 +433,7 @@ main(int argc, char *argv[])
 			}
 			if (todo & MEMSTAT) {
 				domem();
-				dopool(verbose);
+				dopool(verbose, wide);
 				putchar('\n');
 			}
 			if (todo & SUMSTAT) {
@@ -1020,11 +1023,11 @@ domem(void)
 }
 
 void
-dopool(int verbose)
+dopool(int verbose, int wide)
 {
 	int first, ovflw;
 	void *addr;
-	long total = 0, inuse = 0;
+	long total, inuse, this_total, this_inuse;
 	TAILQ_HEAD(,pool) pool_head;
 	struct pool pool, *pp = &pool;
 	struct pool_allocator pa;
@@ -1033,6 +1036,8 @@ dopool(int verbose)
 	kread(X_POOLHEAD, &pool_head, sizeof(pool_head));
 	addr = TAILQ_FIRST(&pool_head);
 
+	total = inuse = 0;
+
 	for (first = 1; addr != NULL; addr = TAILQ_NEXT(pp, pr_poollist) ) {
 		deref_kptr(addr, pp, sizeof(*pp), "pool chain trashed");
 		deref_kptr(pp->pr_alloc, &pa, sizeof(pa),
@@ -1044,19 +1049,24 @@ dopool(int verbose)
 		if (first) {
 			(void)printf("Memory resource pool statistics\n");
 			(void)printf(
-			    "%-11s%5s%9s%5s%9s%6s%6s%6s%6s%6s%6s%5s\n",
-			    "Name",
-			    "Size",
-			    "Requests",
+			    "%-*s%*s%*s%5s%*s%s%s%*s%*s%6s%s%6s%6s%6s%5s%s%s\n",
+			    wide ? 16 : 11, "Name",
+			    wide ? 6 : 5, "Size",
+			    wide ? 12 : 9, "Requests",
 			    "Fail",
-			    "Releases",
-			    "Pgreq",
-			    "Pgrel",
+			    wide ? 12 : 9, "Releases",
+			    wide ? " InUse" : "",
+			    wide ? " Avail" : "",
+			    wide ? 7 : 6, "Pgreq",
+			    wide ? 7 : 6, "Pgrel",
 			    "Npage",
+			    wide ? " PageSz" : "",
 			    "Hiwat",
 			    "Minpg",
 			    "Maxpg",
-			    "Idle");
+			    "Idle",
+			    wide ? " Flags" : "",
+			    wide ? "   Util" : "");
 			first = 0;
 		}
 		if (pp->pr_nget == 0 && !verbose)
@@ -1081,18 +1091,27 @@ dopool(int verbose)
 		(ovflw) = 0;				\
 } while (/* CONSTCOND */0)
 		ovflw = 0;
-		PRWORD(ovflw, "%-*s", 11, 0, name);
-		PRWORD(ovflw, " %*u", 5, 1, pp->pr_size);
-		PRWORD(ovflw, " %*lu", 9, 1, pp->pr_nget);
+		PRWORD(ovflw, "%-*s", wide ? 16 : 11, 0, name);
+		PRWORD(ovflw, " %*u", wide ? 6 : 5, 1, pp->pr_size);
+		PRWORD(ovflw, " %*lu", wide ? 12 : 9, 1, pp->pr_nget);
 		PRWORD(ovflw, " %*lu", 5, 1, pp->pr_nfail);
-		PRWORD(ovflw, " %*lu", 9, 1, pp->pr_nput);
-		PRWORD(ovflw, " %*lu", 6, 1, pp->pr_npagealloc);
-		PRWORD(ovflw, " %*lu", 6, 1, pp->pr_npagefree);
-		PRWORD(ovflw, " %*d", 6, 1, pp->pr_npages);
-		PRWORD(ovflw, " %*d", 6, 1, pp->pr_hiwat);
-		PRWORD(ovflw, " %*d", 6, 1, pp->pr_minpages);
+		PRWORD(ovflw, " %*lu", wide ? 12 : 9, 1, pp->pr_nput);
+		if (wide)
+			PRWORD(ovflw, " %*u", 6, 1, pp->pr_nout);
+		if (wide)
+			PRWORD(ovflw, " %*u", 6, 1, pp->pr_nitems);
+		PRWORD(ovflw, " %*lu", wide ? 7 : 6, 1, pp->pr_npagealloc);
+		PRWORD(ovflw, " %*lu", wide ? 7 : 6, 1, pp->pr_npagefree);
+		PRWORD(ovflw, " %*u", 6, 1, pp->pr_npages);
+		if (wide)
+			PRWORD(ovflw, " %*u", 7, 1, pa.pa_pagesz);
+		PRWORD(ovflw, " %*u", 6, 1, pp->pr_hiwat);
+		PRWORD(ovflw, " %*u", 6, 1, pp->pr_minpages);
 		PRWORD(ovflw, " %*s", 6, 1, maxp);
-		PRWORD(ovflw, " %*lu\n", 5, 1, pp->pr_nidle);
+		PRWORD(ovflw, " %*lu", 5, 1, pp->pr_nidle);
+		if (wide)
+			PRWORD(ovflw, " 0x%0*x", 4, 1,
+			    pp->pr_flags | pp->pr_roflags);
 
 		if (pp->pr_roflags & PR_RECURSIVE) {
 			/*
@@ -1103,9 +1122,16 @@ dopool(int verbose)
 			total += pp->pr_npages * pa.pa_pagesz -
 			     (pp->pr_nget - pp->pr_nput) * pp->pr_size;
 		} else {
-			inuse += (pp->pr_nget - pp->pr_nput) * pp->pr_size;
-			total += pp->pr_npages * pa.pa_pagesz;
+			this_inuse += (pp->pr_nget - pp->pr_nput) * pp->pr_size;
+			this_total += pp->pr_npages * pa.pa_pagesz;
+			inuse += this_inuse;
+			total += this_total;
+
+			if (wide)
+				printf(" %5.1f%%",
+				    (double)(100 * this_inuse) / this_total);
 		}
+		printf("\n");
 		dopoolcache(pp, verbose);
 	}
 

--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=vmstat-m

Memory resource pool statistics
Name        Size Requests Fail Releases Pgreq Pgrel Npage Hiwat Minpg Maxpg Idle
phpool-0      40      142    0       98     1     0     1     1     0   inf    0
phpool-32     72        6    0        0     1     0     1     1     0   inf    0
pcgpool      140       19    0       13     1     0     1     1     0   inf    0
pmappl        52      405    0      396     1     0     1     1     0   inf    0
pdppl       4096       19    0        7    14     2    12    14     0   inf    0
kvakernel   4096      228    0       91     5     0     5     5     0     0    0
kvakmem     4096       22    0        8     1     0     1     1     0     0    0
inpcbpl      108       94    0       89     1     0     1     1     0   inf    0
inmltpl       32        2    0        0     1     0     1     1     0   inf    0
tcpipqepl     44        3    0        3     1     1     0     1     0   inf    0
synpl        172       18    0       18     3     3     0     1     0   inf    0
tcpcbpl      316       26    0       21     1     0     1     1     0   inf    0
ffsinopl     188      588    0       95    24     0    24    24     0   inf    0
dino1pl      128      588    0       95    16     0    16    16     0   inf    0
ufsdirpl     264       23    0       23     3     2     1     1     0   inf    1
rndsample    528      117    0      115     1     0     1     1     0   inf    0
filepl        56     4818    0     4791     1     0     1     1     0   inf    0
cwdipl        16      405    0      396     1     0     1     1     0   inf    0
fdescpl      284      405    0      396     1     0     1     1     0   inf    0
procpl       400      409    0      396     2     0     2     2     0   inf    0
lwppl        124      409    0      396     1     0     1     1     0   inf    0
pgrppl        16       97    0       89     1     0     1     1     0   inf    0
pcredpl       24      409    0      396     1     0     1     1     0   inf    0
plimitpl     176        4    0        3     1     0     1     1     0   inf    0
pstatspl     224      409    0      396     1     0     1     1     0   inf    0
rusgepl       72      396    0      396     3     2     1     1     0   inf    1
ptimerpl     124       44    0       40     1     0     1     1     0   inf    0
sessionpl     40       24    0       18     1     0     1     1     0   inf    0
credpl        84      217    0      211     1     0     1     1     0   inf    0
pipepl       144      410    0      410     1     0     1     1     0   inf    1
ttypl        264       68    0        0     5     0     5     5     0   inf    0
sockpl       216      134    0      127     1     0     1     1     0   inf    0
ncachepl      84      533    0       34    11     0    11    11     0   inf    0
lockfpl       52        8    0        8     1     1     0     1     0   inf    0
vnodepl      168      515    0       16    21     0    21    21     0   inf    0
rtentpl      132       12    0        5     1     0     1     1     0   inf    0
amappl        40     3914    0     3810     2     0     2     2     0   inf    0
uaoeltpl      84        8    0        5     1     0     1     1     0   inf    0
aobjpl        52        1    0        0     1     0     1     1     0   inf    0
vmsppl       224      405    0      396     1     0     1     1     0   inf    0
vmmpepl       88    15481    0    15277    10     3     7     7     0   inf    2
bufpl        124     7831    0     7809     4     2     2     3     0   inf    1
buf1k       1024      209    0      201    41    38     3     6     1     1    1
buf2k       2048       44    0       42    17    15     2     3     1     1    1
buf4k       4096       24    0       23    25    23     2     8     1     1    1
buf8k       8192      316    0      305    12    10     2     6     1     1    0
mbpl         256       76    0       49     5     2     3     3     1   inf    1
mclpl       2048       72    0       48    24     8    16    16     4   128    4
pnbufpl     1024        5    0        4     1     0     1     1     0   inf    0
scxspl       148  4711836    0  4711836     1     0     1     1     1   inf    1
sigapl      2052      405    0      396    17     5    12    14     0   inf    3
extent        20     2435    0     2301     1     0     1     1     0   inf    0

In use 13162K, total allocated 17464K; utilization 75.4%


--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=vmstat-mW

Memory resource pool statistics
Name              Size    Requests Fail    Releases InUse Avail  Pgreq  Pgrel Npage PageSz Hiwat Minpg Maxpg Idle Flags   Util
phpool-0            40         142    0          98    44    57      1      0     1   4096     1     0   inf    0 0x040  43.0%
phpool-32           72           6    0           0     6    50      1      0     1   4096     1     0   inf    0 0x040  26.8%
pcgpool            140          19    0          13     6    22      1      0     1   4096     1     0   inf    0 0x040  24.7%
pmappl              52         406    0         397     9    69      1      0     1   4096     1     0   inf    0 0x040  21.4%
pdppl             4096          19    0           7    12     0     14      2    12   4096    14     0   inf    0 0x000  80.3%
kvakernel         4096         228    0          91   137    23      5      0     5 131072     5     0     0    0 0x600
kvakmem           4096          22    0           8    14    18      1      0     1 131072     1     0     0    0 0x600
inpcbpl            108          94    0          89     5    32      1      0     1   4096     1     0   inf    0 0x040  76.4%
inmltpl             32           2    0           0     2   124      1      0     1   4096     1     0   inf    0 0x040  72.2%
tcpipqepl           44           3    0           3     0     0      1      1     0   4096     1     0   inf    0 0x040  72.2%
synpl              172          18    0          18     0     0      3      3     0   4096     1     0   inf    0 0x040  72.2%
tcpcbpl            316          26    0          21     5     7      1      0     1   4096     1     0   inf    0 0x040  70.5%
ffsinopl           188         588    0          95   493    11     24      0    24   4096    24     0   inf    0 0x040  83.8%
dino1pl            128         588    0          95   493     3     16      0    16   4096    16     0   inf    0 0x040  87.2%
ufsdirpl           264          23    0          23     0    15      3      2     1   4096     1     0   inf    1 0x040  85.7%
rndsample          528         117    0         115     2     5      1      0     1   4096     1     0   inf    0 0x040  84.7%
filepl              56        4824    0        4797    27    45      1      0     1   4096     1     0   inf    0 0x040  83.9%
cwdipl              16         406    0         397     9   244      1      0     1   4096     1     0   inf    0 0x040  82.7%
fdescpl            284         406    0         397     9     5      1      0     1   4096     1     0   inf    0 0x040  82.4%
procpl             400         410    0         397    13     7      2      0     2   4096     2     0   inf    0 0x040  81.8%
lwppl              124         410    0         397    13    19      1      0     1   4096     1     0   inf    0 0x040  81.2%
pgrppl              16          98    0          90     8   245      1      0     1   4096     1     0   inf    0 0x040  80.0%
pcredpl             24         410    0         397    13   156      1      0     1   4096     1     0   inf    0 0x040  79.0%
plimitpl           176           4    0           3     1    22      1      0     1   4096     1     0   inf    0 0x040  77.9%
pstatspl           224         410    0         397    13     5      1      0     1   4096     1     0   inf    0 0x040  77.8%
rusgepl             72         397    0         397     0    56      3      2     1   4096     1     0   inf    1 0x040  76.7%
ptimerpl           124          44    0          40     4    28      1      0     1   4096     1     0   inf    0 0x040  75.8%
sessionpl           40          24    0          18     6    95      1      0     1   4096     1     0   inf    0 0x040  74.9%
credpl              84         217    0         211     6    42      1      0     1   4096     1     0   inf    0 0x040  74.0%
pipepl             144         410    0         410     0    28      1      0     1   4096     1     0   inf    1 0x040  73.1%
ttypl              264          68    0           0    68     7      5      0     5   4096     5     0   inf    0 0x040  74.0%
sockpl             216         134    0         127     7    11      1      0     1   4096     1     0   inf    0 0x040  73.5%
ncachepl            84         533    0          34   499    29     11      0    11   4096    11     0   inf    0 0x040  75.8%
lockfpl             52           8    0           8     0     0      1      1     0   4096     1     0   inf    0 0x040  75.8%
vnodepl            168         515    0          16   499     5     21      0    21   4096    21     0   inf    0 0x040  79.8%
rtentpl            132          12    0           5     7    23      1      0     1   4096     1     0   inf    0 0x040  79.3%
amappl              40        3919    0        3815   104    98      2      0     2   4096     2     0   inf    0 0x040  78.8%
uaoeltpl            84           8    0           5     3    45      1      0     1   4096     1     0   inf    0 0x040  78.2%
aobjpl              52           1    0           0     1    77      1      0     1   4096     1     0   inf    0 0x040  77.6%
vmsppl             224         406    0         397     9     9      1      0     1   4096     1     0   inf    0 0x040  77.3%
vmmpepl             88       15496    0       15292   204   118     10      3     7   4096     7     0   inf    2 0x040  76.5%
bufpl              124        7834    0        7812    22    42      4      2     2   4096     3     0   inf    1 0x040  75.8%
buf1k             1024         209    0         201     8     4     41     38     3   4096     6     1     1    1 0x000  75.6%
buf2k             2048          44    0          42     2     2     17     15     2   4096     3     1     1    1 0x000  75.3%
buf4k             4096          24    0          23     1     1     25     23     2   4096     8     1     1    1 0x000  74.9%
buf8k             8192         316    0         305    11     5     12     10     2  65536     6     1     1    0 0x000  73.7%
mbpl               256          76    0          49    27    21      5      2     3   4096     3     1   inf    1 0x000  73.4%
mclpl             2048          72    0          48    24     8     24      8    16   4096    16     4   128    4 0x000  73.5%
pnbufpl           1024           5    0           4     1     3      1      0     1   4096     1     0   inf    0 0x000  73.3%
scxspl             148     4711864    0     4711864     0    27      1      0     1   4096     1     1   inf    1 0x040  72.9%
sigapl            2052         406    0         397     9     3     17      5    12   4096    14     0   inf    3 0x040  70.8%
extent              20        2435    0        2301   134    68      1      0     1   4096     1     0   inf    0 0x040  70.8%

In use 13162K, total allocated 17464K; utilization 75.4%


--Nq2Wo0NMKNjxTN9z--