Subject: top and swap
To: None <tech-userlevel@netbsd.org>
From: Zafer Aydogan <zafer@aydogan.de>
List: tech-userlevel
Date: 12/12/2007 19:39:08
hello list,

here is a patch written by Johann Franz that extends top's swap
statistic to include the amount of swap in use, as a percentage. It
looks like this:
Swap: 216M Total, 6164K Used, 210M Free, 2% Inuse
if no swap is in use, it looks like this:
Swap: 216M Total, 216M Free

The patch applies on current and on netbsd-4.
To take effect, you have to swapctl -d and remount swap or reboot.

Have Fun, Zafer.


Index: machine/m_netbsd15.c
===================================================================
RCS file: /cvsroot/src/usr.bin/top/machine/m_netbsd15.c,v
retrieving revision 1.25
diff -u -r1.25 m_netbsd15.c
--- machine/m_netbsd15.c	16 Feb 2006 20:50:57 -0000	1.25
+++ machine/m_netbsd15.c	12 Dec 2007 13:47:19 -0000
@@ -151,9 +151,9 @@
 	NULL
 };

-int swap_stats[4];
+int swap_stats[5];
 char *swapnames[] = {
-	"K Total, ", "K Used, ", "K Free, ",
+	"K Total, ", "K Used, ", "K Free, ", "% Inuse",
 	NULL
 };

@@ -388,7 +388,7 @@
 	memory_stats[4] = pagetok(uvmexp.filepages);
 	memory_stats[5] = pagetok(uvmexp.free);

-	swap_stats[0] = swap_stats[1] = swap_stats[2] = 0;
+	swap_stats[0] = swap_stats[1] = swap_stats[2] = swap_stats[3] = 0;

 	do {
 		nswap = swapctl(SWAP_NSWAP, 0, 0);
@@ -418,10 +418,11 @@
 		swap_stats[0] = dbtob(totalsize) / 1024;
 		swap_stats[1] = dbtob(totalinuse) / 1024;
 		swap_stats[2] = dbtob(totalsize) / 1024 - swap_stats[1];
+		swap_stats[3] = 100 * dbtob(totalinuse) / dbtob(totalsize);
 	} while (0);

 	memory_stats[6] = -1;
-	swap_stats[3] = -1;
+	swap_stats[4] = -1;

 	/* set arrays and strings */
 	si->cpustates = cpu_states;