From owner-freebsd-bugs Tue Feb 27 21:10:15 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 3099737B71D for ; Tue, 27 Feb 2001 21:10:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f1S5A2F20349; Tue, 27 Feb 2001 21:10:02 -0800 (PST) (envelope-from gnats) Received: from legolas.groupofnine.net (shortbus.jaded.net [216.94.132.8]) by hub.freebsd.org (Postfix) with ESMTP id BD3C937B71A for ; Tue, 27 Feb 2001 21:06:34 -0800 (PST) (envelope-from pjp@legolas.groupofnine.net) Received: (from pjp@localhost) by legolas.groupofnine.net (8.11.2/8.11.1) id f1S56X199280; Wed, 28 Feb 2001 00:06:33 -0500 (EST) (envelope-from pjp) Message-Id: <200102280506.f1S56X199280@legolas.groupofnine.net> Date: Wed, 28 Feb 2001 00:06:33 -0500 (EST) From: Peter Philipp Reply-To: pjp@daemonium.com To: FreeBSD-gnats-submit@freebsd.org Cc: code-warriors@groupofnine.net X-Send-Pr-Version: 3.113 Subject: kern/25445: /usr/src/usr.bin/vmstat/vmstat.c & /usr/src/sys/sys/malloc.h type differences Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 25445 >Category: kern >Synopsis: kernel statistics are displayed in wrong types and wrap into negative >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 Feb 27 21:10:01 PST 2001 >Closed-Date: >Last-Modified: >Originator: Peter Philipp >Release: FreeBSD 5.0-CURRENT i386 >Organization: Daemonium >Environment: System: FreeBSD legolas.groupofnine.net 5.0-CURRENT FreeBSD 5.0-CURRENT #4: Sun Feb 25 21:48:35 EST 2001 pjp@legolas.groupofnine.net:/usr/obj/usr/src/sys/LEGOLAS i386 >Description: vmstat -m reports wrong kernel statistics due to a type mismatch in printing vmstat.c's totreq in domem(). Fix includes a bit more fixing of unsigned types. >How-To-Repeat: let a busy web server run for a few days. >Fix: This really has bigger problems that are much more complex (and needs some smart advice) in regards to the type definitions of the members in struct malloc_type and also kmembuckets (sys/malloc.h). I'm of the opinion for example that ks_calls in malloc_type should be unsigned as it's a total count from 0 and should never be negative. I'm unsure of the some others as I've looked for any dependencies in the /usr/src tree but it seems to be only vmstat for ks_inuse, ks_calls and ks_maxused. I've changed those to unsigned and also declared the type of integer they are. This could perhaps make the people with the alpha port happy. Much of those structs remain to be just 'long' and should perhaps be changed to their respective posix integer type. /usr/src/sys/sys/malloc.h patch --- malloc.h.orig Tue Feb 27 22:49:28 2001 +++ malloc.h Tue Feb 27 23:32:55 2001 @@ -55,9 +55,9 @@ long ks_memuse; /* total memory held in bytes */ 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 */ - long ks_maxused; /* maximum number ever used */ + u_int32_t ks_inuse; /* # of packets of this type currently in use */ + u_int64_t ks_calls; /* total packets of this type ever allocated */ + u_int32_t 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 */ u_short ks_limblocks; /* number of times blocked for hitting limit */ @@ -102,7 +102,7 @@ struct kmembuckets { caddr_t kb_next; /* list of free blocks */ caddr_t kb_last; /* last free block */ - int64_t kb_calls; /* total calls to allocate this size */ + u_int64_t kb_calls; /* total calls to allocate this size */ long kb_total; /* total number of blocks allocated */ long kb_elmpercl; /* # of elements in this sized allocation */ long kb_totalfree; /* # of free elements in this bucket */ ==== /usr/src/usr.bin/vmstat/vmstat.c patch --- vmstat.c.orig Tue Feb 27 23:33:53 2001 +++ vmstat.c Tue Feb 27 23:44:41 2001 @@ -761,7 +761,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; + u_int64_t totreq = 0; const char *name; struct malloc_type kmemstats[MAX_KMSTATS], *kmsp; char *kmemnames[MAX_KMSTATS]; @@ -841,7 +842,7 @@ for (i = 0, ks = &kmemstats[0]; i < nkms; i++, ks++) { if (ks->ks_calls == 0) continue; - (void)printf("%13s%6ld%6ldK%7ldK%6ldK%9ld%5u%6u", + (void)printf("%13s%6lu%6ldK%7luK%6ldK%9qu%5u%6u", ks->ks_shortdesc, ks->ks_inuse, (ks->ks_memuse + 1023) / 1024, (ks->ks_maxused + 1023) / 1024, @@ -866,7 +867,7 @@ totreq += ks->ks_calls; } (void)printf("\nMemory Totals: In Use Free Requests\n"); - (void)printf(" %7ldK %6ldK %8ld\n", + (void)printf(" %7ldK %6ldK %8qu\n", (totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq); } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message