Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Aug 2009 14:39:33 +0000 (UTC)
From:      Stanislav Sedov <stas@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r196244 - head/usr.sbin/pstat
Message-ID:  <200908151439.n7FEdXom073317@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: stas
Date: Sat Aug 15 14:39:33 2009
New Revision: 196244
URL: http://svn.freebsd.org/changeset/base/196244

Log:
  - Avoid overflowing the swap size counters in human-readable mode
    by introducing the new CONVERT_BLOCKS macro which operates on
    sizes already converted to number of blocks.  With this macro
    it is not longer needed to perform needless multiplication by
    blocksize just to divide on it later in CONVERT macro.
  
  Approved by:	re (kib)
  MFC after:	1 week

Modified:
  head/usr.sbin/pstat/pstat.c

Modified: head/usr.sbin/pstat/pstat.c
==============================================================================
--- head/usr.sbin/pstat/pstat.c	Sat Aug 15 11:52:40 2009	(r196243)
+++ head/usr.sbin/pstat/pstat.c	Sat Aug 15 14:39:33 2009	(r196244)
@@ -460,6 +460,7 @@ getfiles(struct xfile **abuf, size_t *al
  */
 
 #define CONVERT(v)	((int64_t)(v) * pagesize / blocksize)
+#define CONVERT_BLOCKS(v)	((int64_t)(v) * pagesize)
 static struct kvm_swap swtot;
 static int nswdev;
 
@@ -492,10 +493,10 @@ print_swap_line(const char *swdevname, i
 	printf("%-15s %*jd ", swdevname, hlen, CONVERT(nblks));
 	if (humanflag) {
 		humanize_number(usedbuf, sizeof(usedbuf),
-		    CONVERT(blocksize * bused), "",
+		    CONVERT_BLOCKS(bused), "",
 		    HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
 		humanize_number(availbuf, sizeof(availbuf),
-		    CONVERT(blocksize * bavail), "",
+		    CONVERT_BLOCKS(bavail), "",
 		    HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
 		printf("%8s %8s %5.0f%%\n", usedbuf, availbuf, bpercent);
 	} else {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908151439.n7FEdXom073317>