diff options
author | imp <imp@FreeBSD.org> | 1999-05-10 00:33:32 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 1999-05-10 00:33:32 +0000 |
commit | bb52f35f49b5851f96ce116101182b80dac05104 (patch) | |
tree | cf4924240c90f77bb2d5a26f55ca7f5f8710ccd2 /usr.bin | |
parent | 0259e8cd95061d06eeec1eb59f9ba437c0c44a97 (diff) | |
download | FreeBSD-src-bb52f35f49b5851f96ce116101182b80dac05104.zip FreeBSD-src-bb52f35f49b5851f96ce116101182b80dac05104.tar.gz |
Sometime since this file was written, the list of kernel malloc types
changed from a simple list to a circular one. We compensate by only
looping until we see the first address again. Before, things would
terminate because it was limited to 200 iterations. This lead to
bogus statistics and repeating stats for memory types.
This should be merged into 3.2, as the same bug is there.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/vmstat/vmstat.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index d5cec16..4a76397 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -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.32 1999/02/13 09:59:24 dillon Exp $"; + "$Id: vmstat.c,v 1.33 1999/02/15 14:15:28 bde Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -503,6 +503,9 @@ dovmstat(interval, reps) } (void)printf("%2d%2d%2d", total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw); +#ifdef pgtok +#undef pgtok +#endif #define pgtok(a) ((a) * sum.v_page_size >> 10) #define rate(x) (((x) + halfuptime) / uptime) /* round */ (void)printf("%8ld%6ld ", @@ -792,6 +795,8 @@ dointr() (void)printf("Total %8ld %8ld\n", inttotal, inttotal / uptime); } +#define MAX_KMSTATS 200 + void domem() { @@ -801,14 +806,15 @@ domem() int len, size, first, nkms; long totuse = 0, totfree = 0, totreq = 0; const char *name; - struct malloc_type kmemstats[200], *kmsp; - char *kmemnames[200]; + struct malloc_type kmemstats[MAX_KMSTATS], *kmsp, *first_kmsp; + char *kmemnames[MAX_KMSTATS]; char buf[1024]; struct kmembuckets buckets[MINBUCKET + 16]; kread(X_KMEMBUCKETS, buckets, sizeof(buckets)); kread(X_KMEMSTATISTICS, &kmsp, sizeof(kmsp)); - for (nkms = 0; nkms < 200 && kmsp != NULL; nkms++) { + first_kmsp = kmsp; + for (nkms = 0; nkms < MAX_KMSTATS && kmsp != NULL; nkms++) { if (sizeof(kmemstats[0]) != kvm_read(kd, (u_long)kmsp, &kmemstats[nkms], sizeof(kmemstats[0]))) err(1, "kvm_read(%p)", (void *)kmsp); @@ -816,9 +822,14 @@ domem() (u_long)kmemstats[nkms].ks_shortdesc, buf, sizeof(buf))) err(1, "kvm_read(%p)", (void *)kmemstats[nkms].ks_shortdesc); + buf[sizeof(buf) - 1] = '\0'; kmemstats[nkms].ks_shortdesc = strdup(buf); kmsp = kmemstats[nkms].ks_next; + if (kmsp == first_kmsp) + break; } + if (kmsp != NULL && nkms >= MAX_KMSTATS) + warnx("Truncated to the first %d types.", MAX_KMSTATS); (void)printf("Memory statistics by bucket size\n"); (void)printf( "Size In Use Free Requests HighWater Couldfree\n"); |