From ryanb@bjorn.goddamnbastard.org  Tue Nov 27 14:23:54 2001
Return-Path: <ryanb@bjorn.goddamnbastard.org>
Received: from smtp-1.enteract.com (smtp-1.enteract.com [207.229.143.33])
	by hub.freebsd.org (Postfix) with ESMTP id 3B3DD37B405
	for <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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
Subject: vmstat(8) and totreq declaration
X-Send-Pr-Version: 3.2

>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:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 27 14:30:01 PST 2001
>Closed-Date:    Mon Apr 08 03:51:58 PDT 2002
>Last-Modified:  Mon Apr 08 03:51:58 PDT 2002
>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:
State-Changed-From-To: open->analyzed 
State-Changed-By: asmodai 
State-Changed-When: Sun Apr 7 06:41:36 PDT 2002 
State-Changed-Why:  
I've looked at it. 

Better would be to use uint64_t instead of u_int64_t, since the latter is 
more BSD specific and the first more POSIX. 

I will run this past Jeff R. and Alan Cox. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=32342 
State-Changed-From-To: analyzed->closed 
State-Changed-By: asmodai 
State-Changed-When: Mon Apr 8 03:51:27 PDT 2002 
State-Changed-Why:  
Slightly different patch committed. 

Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=32342 
>Unformatted:
