Module Name:    src
Committed By:   simonb
Date:           Sat Jul 16 10:36:19 UTC 2022

Modified Files:
        src/usr.bin/vmstat: vmstat.c

Log Message:
When operating on core files or /dev/mem when using the -M option,
use 64-bit math to calculate pool sizes.  Fixes overflow errors for
pools larger than 4GB and gives the correct output with "vmstat -m"
for in use, total allocation and utilisation numbers.


To generate a diff of this commit:
cvs rdiff -u -r1.254 -r1.255 src/usr.bin/vmstat/vmstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/vmstat/vmstat.c
diff -u src/usr.bin/vmstat/vmstat.c:1.254 src/usr.bin/vmstat/vmstat.c:1.255
--- src/usr.bin/vmstat/vmstat.c:1.254	Sat Jul 16 09:32:27 2022
+++ src/usr.bin/vmstat/vmstat.c	Sat Jul 16 10:36:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.254 2022/07/16 09:32:27 simonb Exp $ */
+/* $NetBSD: vmstat.c,v 1.255 2022/07/16 10:36:19 simonb Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020
@@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
 #if 0
 static char sccsid[] = "@(#)vmstat.c	8.2 (Berkeley) 3/1/95";
 #else
-__RCSID("$NetBSD: vmstat.c,v 1.254 2022/07/16 09:32:27 simonb Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.255 2022/07/16 10:36:19 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -1578,7 +1578,7 @@ dopool(int verbose, int wide)
 {
 	int first, ovflw;
 	void *addr;
-	long total, inuse, this_total, this_inuse;
+	uint64_t total, inuse, this_total, this_inuse;
 	struct {
 		uint64_t pt_nget;
 		uint64_t pt_nfail;
@@ -1674,8 +1674,8 @@ dopool(int verbose, int wide)
 			PRWORD(ovflw, " 0x%0*x", 6, 1,
 			    pp->pr_flags | pp->pr_roflags);
 
-		this_inuse = pp->pr_nout * pp->pr_size;
-		this_total = pp->pr_npages * pa.pa_pagesz;
+		this_inuse = (uint64_t)pp->pr_nout * pp->pr_size;
+		this_total = (uint64_t)pp->pr_npages * pa.pa_pagesz;
 		if (pp->pr_roflags & PR_RECURSIVE) {
 			/*
 			 * Don't count in-use memory, since it's part
@@ -1714,7 +1714,8 @@ dopool(int verbose, int wide)
 	inuse /= KILO;
 	total /= KILO;
 	(void)printf(
-	    "\nIn use %ldK, total allocated %ldK; utilization %.1f%%\n",
+	    "\nIn use %" PRIu64 "K, "
+	    "total allocated %" PRIu64 "K; utilization %.1f%%\n",
 	    inuse, total, (100.0 * inuse) / total);
 }
 

Reply via email to