summaryrefslogtreecommitdiffstats
path: root/usr.bin/vmstat
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2001-01-23 00:31:56 +0000
committerdes <des@FreeBSD.org>2001-01-23 00:31:56 +0000
commitefffbed31834d7743921db52be55535b15374d1f (patch)
treec905242cdbce3adb57ad17168deb655a6a221fef /usr.bin/vmstat
parent16f8aaa40931ee553642e7309e95513393276953 (diff)
downloadFreeBSD-src-efffbed31834d7743921db52be55535b15374d1f.zip
FreeBSD-src-efffbed31834d7743921db52be55535b15374d1f.tar.gz
Use the vm.zone sysctl rather that grope through the zone allocator's
internal data structures.
Diffstat (limited to 'usr.bin/vmstat')
-rw-r--r--usr.bin/vmstat/vmstat.c67
1 files changed, 15 insertions, 52 deletions
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index 9c5f151..a5c17f8 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -59,7 +59,6 @@ static const char rcsid[] =
#include <sys/vmmeter.h>
#include <vm/vm_param.h>
-#include <vm/vm_zone.h>
#include <ctype.h>
#include <err.h>
@@ -866,59 +865,23 @@ domem()
void
dozmem()
{
- static SLIST_HEAD(vm_zone_list, vm_zone) zlist;
- 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"
- );
-
- SLIST_INIT(&zlist);
- kread(X_ZLIST, &zlist, sizeof(zlist));
- zonep = SLIST_FIRST(&zlist);
-
- 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))
+ char *buf;
+ size_t bufsize;
+
+ buf = NULL;
+ bufsize = 1024;
+ for (;;) {
+ if ((buf = realloc(buf, bufsize)) == NULL)
+ err(1, "realloc()");
+ if (sysctlbyname("vm.zone", buf, &bufsize, 0, NULL) == 0)
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 = SLIST_NEXT(&zone, zent);
+ if (errno != ENOMEM)
+ err(1, "sysctl()");
+ bufsize *= 2;
}
- printf(
- "------------------------------------------\n"
- "%-15.15s %-7s %-7s %4d/%dK\n\n",
- "TOTAL",
- "",
- "",
- zused_bytes / 1024,
- ztotal_bytes / 1024
- );
+ buf[bufsize] = '\0'; /* play it safe */
+ (void)printf("%s\n\n", buf);
+ free(buf);
}
/*
OpenPOWER on IntegriCloud