From owner-freebsd-bugs Tue Nov 27 14:30:20 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 CA00B37B41A for ; Tue, 27 Nov 2001 14:30:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id fARMU1m15758; Tue, 27 Nov 2001 14:30:01 -0800 (PST) (envelope-from gnats) Received: from smtp-1.enteract.com (smtp-1.enteract.com [207.229.143.33]) by hub.freebsd.org (Postfix) with ESMTP id 3B3DD37B405 for ; Tue, 27 Nov 2001 14:23:53 -0800 (PST) Received: from bjorn.goddamnbastard.org (bjorn.goddamnbastard.org [216.80.6.225]) by smtp-1.enteract.com (Postfix) with SMTP id 5FE4C76BF for ; Tue, 27 Nov 2001 16:23:52 -0600 (CST) Received: (qmail 8678 invoked by uid 1000); 27 Nov 2001 22:23:51 -0000 Message-Id: <20011127222351.8677.qmail@bjorn.goddamnbastard.org> Date: 27 Nov 2001 22:23:51 -0000 From: ryanb@goddamnbastard.org Reply-To: ryanb@goddamnbastard.org To: FreeBSD-gnats-submit@freebsd.org, ru@freebsd.org, tmm@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/32342: vmstat(8) and totreq declaration Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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