Subject: bin/511: /bin/ps -u does not show correct %MEM.
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: None <nor@aecl.ntt.JP>
List: netbsd-bugs
Date: 10/11/1994 19:35:04
>Number:         511
>Category:       bin
>Synopsis:       /bin/ps -u does not show correct %MEM.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Oct 11 19:35:03 1994
>Originator:     Noriyuki Takahashi
>Organization:
NTT LSI Laboratories, Kanagawa 243-01 Japan.
>Release:        
>Environment:
NetBSD-1.0B (Oct. 2 tar ball form iastate), i386
>Description:
	/bin/ps -u does not show correct %MEM. In /usr/src/bin/ps/print.c,
	line 576, 

	fracmem = ((float)e->e_vm.vm_rssize + szptudot)/CLSIZE/mempages;

	'vm_rssize' and 'szptudot' are in PAGES, but 'mempages' seems to
	be have a value in BITS. As a result, 'fracmem' is assigned much
	less value than it should be. 
>How-To-Repeat:
	% ps -u
>Fix:
One of the following patches may be work. (Two patches are exclusive.
Use of both patches does not work.)

%%%% patch to /usr/src/bin/ps/nlist.c
--- nlist.c	Wed Oct 12 11:14:29 1994
+++ nlist.c.old	Wed Oct 12 11:13:43 1994
@@ -109,7 +109,6 @@
 		eval = rval = 1;
 	}
 	mempages -= tmp;
-	mempages /= NBPG;
 #else
 	if (kread(X_ECMX, mempages)) {
 		warnx("ecmx: %s", kvm_geterr(kd));
%%% end of patch

Alternative is,
%%% patch to /usr/src/bin/ps/print.c
--- print.c.old	Wed Oct 12 11:15:30 1994
+++ print.c	Wed Oct 12 11:16:55 1994
@@ -572,7 +572,7 @@
 	/* XXX want pmap ptpages, segtab, etc. (per architecture) */
 	szptudot = UPAGES;
 	/* XXX don't have info about shared */
-	fracmem = ((float)e->e_vm.vm_rssize + szptudot)/CLSIZE/mempages;
+	fracmem = ((float)((e->e_vm.vm_rssize + szptudot)*NBPG))/CLSIZE/mempages;
 #endif
 	return (100.0 * fracmem);
 }
%%% end of patch
>Audit-Trail:
>Unformatted: