Add -z option to vmstat to dump data from the zone allocator

This commit is contained in:
Matthew Dillon 1999-02-13 09:59:24 +00:00
parent 7345cf9025
commit 2e8c5eaef8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=43962
2 changed files with 77 additions and 12 deletions

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)vmstat.8 8.1 (Berkeley) 6/6/93
.\" $Id: vmstat.8,v 1.10 1998/09/15 08:16:43 gibbs Exp $
.\" $Id: vmstat.8,v 1.11 1999/02/10 00:46:26 ken Exp $
.\"
.Dd June 6, 1996
.Dt VMSTAT 8
@ -41,7 +41,7 @@
.Sh SYNOPSIS
.Nm vmstat
.\" .Op Fl fimst
.Op Fl ims
.Op Fl imzs
.Op Fl c Ar count
.Op Fl M Ar core
.Op Fl N Ar system
@ -88,6 +88,8 @@ instead of the default
.It Fl m
Report on the usage of kernel dynamic memory listed first by size of
allocation and then by type of usage.
.It Fl z
Report on memory used by the kernel zone allocator, by zone.
.It Fl n
Change the maximum number of disks to display from the default of 2.
.It Fl p

View File

@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id: vmstat.c,v 1.29 1998/10/28 06:41:24 jdp Exp $";
"$Id: vmstat.c,v 1.31 1999/02/10 00:46:27 ken Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -60,6 +60,7 @@ static const char rcsid[] =
#include <sys/vmmeter.h>
#include <vm/vm_param.h>
#include <vm/vm_zone.h>
#include <ctype.h>
#include <err.h>
@ -101,20 +102,22 @@ struct nlist namelist[] = {
{ "_kmemstatistics" },
#define X_KMEMBUCKETS 11
{ "_bucket" },
#define X_ZLIST 12
{ "_zlist" },
#ifdef notyet
#define X_DEFICIT 12
#define X_DEFICIT 13
{ "_deficit" },
#define X_FORKSTAT 13
#define X_FORKSTAT 14
{ "_forkstat" },
#define X_REC 14
#define X_REC 15
{ "_rectime" },
#define X_PGIN 15
#define X_PGIN 16
{ "_pgintime" },
#define X_XSTATS 16
#define X_XSTATS 17
{ "_xstats" },
#define X_END 17
#define X_END 18
#else
#define X_END 14
#define X_END 13
#endif
#if defined(hp300) || defined(luna68k)
#define X_HPDINIT (X_END)
@ -166,8 +169,9 @@ kvm_t *kd;
#define SUMSTAT 0x08
#define TIMESTAT 0x10
#define VMSTAT 0x20
#define ZMEMSTAT 0x40
void cpustats(), dointr(), domem(), dosum();
void cpustats(), dointr(), domem(), dozmem(), dosum();
void dovmstat(), kread(), usage();
#ifdef notyet
void dotimes(), doforkst();
@ -190,7 +194,7 @@ main(argc, argv)
memf = nlistf = NULL;
interval = reps = todo = 0;
maxshowdevs = 2;
while ((c = getopt(argc, argv, "c:fiM:mN:n:p:stw:")) != -1) {
while ((c = getopt(argc, argv, "c:fiM:mzN:n:p:stw:")) != -1) {
switch (c) {
case 'c':
reps = atoi(optarg);
@ -211,6 +215,9 @@ main(argc, argv)
case 'm':
todo |= MEMSTAT;
break;
case 'z':
todo |= ZMEMSTAT;
break;
case 'N':
nlistf = optarg;
break;
@ -316,6 +323,8 @@ main(argc, argv)
#endif
if (todo & MEMSTAT)
domem();
if (todo & ZMEMSTAT)
dozmem();
if (todo & SUMSTAT)
dosum();
#ifdef notyet
@ -896,6 +905,60 @@ domem()
(totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq);
}
void
dozmem()
{
vm_zone_t zonep;
int nmax = 512;
int zused_bytes = 0;
int ztotal_bytes = 0;
printf(
"\n"
"%-16s%-8s%-8s%-8s\n",
"ZONE",
"used",
"total",
"mem-use"
);
kread(X_ZLIST, &zonep, sizeof(zonep));
while (zonep != NULL && nmax) {
struct vm_zone zone;
char buf[32];
int n;
if (kvm_read(kd, (u_long)zonep, &zone, sizeof(zone)) != sizeof(zone))
break;
n = kvm_read(kd, (u_long)zone.zname, buf, sizeof(buf) - 1);
if (n < 0)
n = 0;
buf[n] = 0;
printf(
"%-15.15s %-7d %-7d %4d/%dK\n",
buf,
zone.ztotal - zone.zfreecnt,
zone.ztotal,
(zone.ztotal - zone.zfreecnt) * zone.zsize / 1024,
zone.ztotal * zone.zsize / 1024
);
zused_bytes += (zone.ztotal - zone.zfreecnt) * zone.zsize;
ztotal_bytes += zone.ztotal * zone.zsize;
--nmax;
zonep = zone.znext;
}
printf(
"------------------------------------------\n"
"%-15.15s %-7s %-7s %4d/%dK\n\n",
"TOTAL",
"",
"",
zused_bytes / 1024,
ztotal_bytes / 1024
);
}
/*
* kread reads something from the kernel, given its nlist index.
*/