Use the vm.zone sysctl rather that grope through the zone allocator's

internal data structures.
This commit is contained in:
Dag-Erling Smørgrav 2001-01-23 00:31:56 +00:00
parent 97ace1c6ac
commit bec62dd817
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=71404

View File

@ -59,7 +59,6 @@ static const char rcsid[] =
#include <sys/vmmeter.h> #include <sys/vmmeter.h>
#include <vm/vm_param.h> #include <vm/vm_param.h>
#include <vm/vm_zone.h>
#include <ctype.h> #include <ctype.h>
#include <err.h> #include <err.h>
@ -866,59 +865,23 @@ domem()
void void
dozmem() dozmem()
{ {
static SLIST_HEAD(vm_zone_list, vm_zone) zlist; char *buf;
vm_zone_t zonep; size_t bufsize;
int nmax = 512;
int zused_bytes = 0;
int ztotal_bytes = 0;
printf( buf = NULL;
"\n" bufsize = 1024;
"%-16s%-8s%-8s%-8s\n", for (;;) {
"ZONE", if ((buf = realloc(buf, bufsize)) == NULL)
"used", err(1, "realloc()");
"total", if (sysctlbyname("vm.zone", buf, &bufsize, 0, NULL) == 0)
"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))
break; break;
n = kvm_read(kd, (u_long)zone.zname, buf, sizeof(buf) - 1); if (errno != ENOMEM)
if (n < 0) err(1, "sysctl()");
n = 0; bufsize *= 2;
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);
} }
printf( buf[bufsize] = '\0'; /* play it safe */
"------------------------------------------\n" (void)printf("%s\n\n", buf);
"%-15.15s %-7s %-7s %4d/%dK\n\n", free(buf);
"TOTAL",
"",
"",
zused_bytes / 1024,
ztotal_bytes / 1024
);
} }
/* /*