Date: 27 Nov 2001 22:23:51 -0000 From: ryanb@goddamnbastard.org To: FreeBSD-gnats-submit@freebsd.org, ru@freebsd.org, tmm@freebsd.org Subject: bin/32342: vmstat(8) and totreq declaration Message-ID: <20011127222351.8677.qmail@bjorn.goddamnbastard.org>
next in thread | raw e-mail | index | archive | help
>Number: 32342
>Category: bin
>Synopsis: vmstat.c: certain variables appear to have wrong declaration
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Nov 27 14:30:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: ryan beasley
>Release: FreeBSD 4.4-STABLE i386
>Organization:
>Environment:
FreeBSD 4.3-STABLE i386 from 2001.07.09 00:00GMT + misc patches.
vmstat.c 1.38.2.4 (relevant code still in -CURRENT 1.51)
>Description:
In vmstat.c, totreq is declared as a long, though the ks_calls
(sys/malloc.h) that it's based from is int64_t. On one of our
machines, the following output was returned from vmstat -m.
Memory Totals: In Use Free Requests
12615K 21482K -2105873852
Relevant snips of code from vmstat.c 1.38.2.4:
760: long totuse = 0, totfree = 0, totreq = 0;
861: totreq += ks->ks_calls;
864: (void)printf(" %7ldK %6ldK %8ld\n",
865: (totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq);
With patch listed below, new output is as follows:
Memory Totals: In Use Free Requests
12601K 21496K 10779019213
>How-To-Repeat:
To be honest, not sure, outside of lots of malloc calls as defined in
sys/malloc.h as opposed to stdlib.h. I'm not a skilled coder.
>Fix:
To be consistent with the declarations in sys/malloc.h:
--- src/usr.bin/vmstat/vmstat.c.orig Tue Nov 27 14:45:14 2001
+++ src/usr.bin/vmstat/vmstat.c Tue Nov 27 15:14:16 2001
@@ -758,7 +758,8 @@
register struct malloc_type *ks;
register int i, j;
int len, size, first, nkms;
- long totuse = 0, totfree = 0, totreq = 0;
+ long totuse = 0, totfree = 0;
+ int64_t totreq = 0;
const char *name;
struct malloc_type kmemstats[MAX_KMSTATS], *kmsp;
char buf[1024];
@@ -862,7 +863,7 @@
totreq += ks->ks_calls;
}
(void)printf("\nMemory Totals: In Use Free Requests\n");
- (void)printf(" %7ldK %6ldK %8ld\n",
+ (void)printf(" %7ldK %6ldK %8lld\n",
(totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq);
}
Another quickie -- should sys/malloc.h receive modifications similar
to the one below? (Of course, anything using these structures might
need some patching as well ...)
--- src/sys/sys/malloc.h.orig Tue Nov 27 15:56:32 2001
+++ src/sys/sys/malloc.h Tue Nov 27 15:56:43 2001
@@ -56,7 +56,7 @@
long ks_limit; /* most that are allowed to exist */
long ks_size; /* sizes of this thing that are allocated */
long ks_inuse; /* # of packets of this type currently in use */
- int64_t ks_calls; /* total packets of this type ever allocated */
+ u_int64_t ks_calls; /* total packets of this type ever allocated */
long ks_maxused; /* maximum number ever used */
u_long ks_magic; /* if it's not magic, don't touch it */
const char *ks_shortdesc; /* short description */
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011127222351.8677.qmail>
