Subject: change to 'systat bufcache' display
To: None <tech-userlevel@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-userlevel
Date: 09/22/2004 11:39:22
Folks,

The following patch changes the display from 'systat bufcache' from

There are 24818 metadata buffers using            60537 kBytes of memory.
There are 41217 pages for cached file data using 164868 kBytes of memory.
There are  2766 pages for executables using       11064 kBytes of memory.
 
File System          Bufs used   %   kB in use   %  Bufsize kB   %  Util %
/home                    19010  76       44358  73       44570  74     100
/                         5808  23       15789  26       15967  26      99
 
Total:                   24818 100       60147  99       60537 100      99
 
 
to

   24818 metadata buffers using              60537 kBytes of memory (16%).
   41216 pages for cached file data using   164864 kBytes of memory (43%).
    2767 pages for executables using         11068 kBytes of memory ( 3%).
   44749 pages for anon (non-file) data     178996 kBytes of memory (47%).
    2104 free pages                           8416 kBytes of memory ( 2%).
 
File System          Bufs used   %   kB in use   %  Bufsize kB   %  Util %
/home                    19010  76       44358  73       44570  74     100
/                         5808  23       15789  26       15967  26      99

Total:                   24818 100       60147  99       60537 100      99

Anyone have any problems with me committing this?

Simon.
--
Simon Burge                                   <simonb@wasabisystems.com>
NetBSD Development, Support and Service:   http://www.wasabisystems.com/

Index: bufcache.c
===================================================================
RCS file: /cvsroot/src/usr.bin/systat/bufcache.c,v
retrieving revision 1.17
diff -d -p -u -r1.17 bufcache.c
--- bufcache.c	11 May 2004 21:56:20 -0000	1.17
+++ bufcache.c	22 Sep 2004 01:35:29 -0000
@@ -51,6 +51,7 @@ __RCSID("$NetBSD: bufcache.c,v 1.17 2004
 
 #include <err.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <kvm.h>
 #include <math.h>
 #include <nlist.h>
@@ -64,6 +65,7 @@ __RCSID("$NetBSD: bufcache.c,v 1.17 2004
 #include "extern.h"
 
 #define VCACHE_SIZE	50
+#define	PAGEINFO_ROWS	 5
 
 struct vcache {
 	int vc_age;
@@ -122,14 +124,14 @@ closebufcache(WINDOW *w)
 void
 labelbufcache(void)
 {
-	wmove(wnd, 1, 0);
-	wclrtoeol(wnd);
-	wmove(wnd, 2, 0);
-	wclrtoeol(wnd);
-	wmove(wnd, 3, 0);
-	wclrtoeol(wnd);
-	mvwaddstr(wnd, 4, 0,
-"File System          Bufs used   %   kB in use   %  Bufsize kB   %  Util %");
+	int i;
+
+	for (i = 0; i <= PAGEINFO_ROWS; i++) {
+		wmove(wnd, i, 0);
+		wclrtoeol(wnd);
+	}
+	mvwaddstr(wnd, PAGEINFO_ROWS + 1, 0, "File System          Bufs used"
+	    "   %   kB in use   %  Bufsize kB   %  Util %");
 	wclrtoeol(wnd);
 }
 
@@ -143,18 +145,38 @@ showbufcache(void)
 	NREAD(X_BUFMEM, &bufmem, sizeof(bufmem));
 
 	mvwprintw(wnd, 0, 0,
-	    "There are %*d metadata buffers using           %*ld kBytes of memory.",
-	    pgwidth, nbuf, kbwidth, bufmem/1024);
+	    "   %*d metadata buffers using             %*ld kBytes of "
+	    "memory (%2.0f%%).",
+	    pgwidth, nbuf, kbwidth, bufmem / 1024,
+	    ((bufmem * 100.0) + 0.5) / getpagesize() / uvmexp.npages);
 	wclrtoeol(wnd);
 	mvwprintw(wnd, 1, 0,
-	    "There are %*llu pages for cached file data using %*llu kBytes of memory.",
-	    pgwidth, (long long)uvmexp.filepages,
-	    kbwidth, (long long) uvmexp.filepages * getpagesize() / 1024);
+	    "   %*" PRIu64 " pages for cached file data using   %*"
+	    PRIu64 " kBytes of memory (%2.0f%%).",
+	    pgwidth, uvmexp.filepages,
+	    kbwidth, uvmexp.filepages * getpagesize() / 1024,
+	    (uvmexp.filepages * 100 + 0.5) / uvmexp.npages);
 	wclrtoeol(wnd);
 	mvwprintw(wnd, 2, 0,
-	    "There are %*llu pages for executables using      %*llu kBytes of memory.",
-	    pgwidth, (long long)uvmexp.execpages,
-	    kbwidth, (long long) uvmexp.execpages * getpagesize() / 1024);
+	    "   %*" PRIu64 " pages for executables using        %*"
+	    PRIu64 " kBytes of memory (%2.0f%%).",
+	    pgwidth, uvmexp.execpages,
+	    kbwidth, uvmexp.execpages * getpagesize() / 1024,
+	    (uvmexp.execpages * 100 + 0.5) / uvmexp.npages);
+	wclrtoeol(wnd);
+	mvwprintw(wnd, 3, 0,
+	    "   %*" PRIu64 " pages for anon (non-file) data     %*"
+	    PRIu64 " kBytes of memory (%2.0f%%).",
+	    pgwidth, uvmexp.anonpages,
+	    kbwidth, uvmexp.anonpages * getpagesize() / 1024,
+	    (uvmexp.anonpages * 100 + 0.5) / uvmexp.npages);
+	wclrtoeol(wnd);
+	mvwprintw(wnd, 4, 0,
+	    "   %*" PRIu64 " free pages                         %*"
+	    PRIu64 " kBytes of memory (%2.0f%%).",
+	    pgwidth, uvmexp.free,
+	    kbwidth, uvmexp.free * getpagesize() / 1024,
+	    (uvmexp.free * 100 + 0.5) / uvmexp.npages);
 	wclrtoeol(wnd);
 
 	if (nbuf == 0 || bufmem == 0) {
@@ -164,7 +186,7 @@ showbufcache(void)
 
 	tbuf = 0;
 	tvalid = tsize = 0;
-	lastrow = 5;	/* Leave room for header. */
+	lastrow = PAGEINFO_ROWS + 2;	/* Leave room for header. */
 	for (i = lastrow, ml = LIST_FIRST(&mount_list); ml != NULL;
 	    i++, ml = LIST_NEXT(ml, ml_entries)) {
 
@@ -213,7 +235,8 @@ initbufcache(void)
 
 	fetchuvmexp();
 	pgwidth = (int)(floor(log10((double)uvmexp.npages)) + 1);
-	kbwidth = (int)(floor(log10(uvmexp.npages * getpagesize() / 1024.0)) + 1);
+	kbwidth = (int)(floor(log10(uvmexp.npages * getpagesize() / 1024.0)) +
+	    1);
 
 	return(1);
 }