Subject: Re: `ps ux' command report negative memory usage value
To: NetBSD amd64 <port-amd64@NetBSD.org>
From: Nicolas Joly <njoly@pasteur.fr>
List: port-amd64
Date: 12/11/2003 10:50:53
On Wed, Dec 10, 2003 at 02:27:44PM +0100, Nicolas Joly wrote:
> 
> I just noticed that `ps ux' command report negative memory usage
> values :
> 
> njoly@calimero [~]> ps ux
> USER    PID %CPU %MEM VSZ  RSS TT STAT STARTED    TIME COMMAND
> njoly 14378  6.1 -1.2 100  788 p0 D+   11:46AM 0:00.54 flat2fasta ../flat/gbest
> njoly  6699  4.1 -1.7 416 1152 p1 D+    9:36AM 3:56.09 (cp)
> njoly   599  0.0 -1.0 548  688 ?? S     9:19AM 0:00.24 sshd: njoly@ttyp0 
> njoly   637  0.0  0.0 548    4 ?? SW    9:19AM 0:00.08 sshd: njoly@ttyp1 
> njoly  6835  0.0 -1.1 548  704 ?? S     9:36AM 0:00.04 sshd: njoly@ttyp2 
> njoly  6889  0.0  0.0 548    4 ?? SW   10:19AM 0:00.22 sshd: njoly@ttyp4 
> njoly 17359  0.0  0.0 548    4 ?? SW   11:43AM 0:00.00 sshd: njoly@ttyp5 
> njoly   595  0.0 -1.5 308  988 p0 Ss    9:19AM 0:00.14 -zsh 
> njoly    96  0.0  0.0 228    4 p1 SWs   9:19AM 0:00.04 -zsh 
> njoly  6648  0.0 -2.0 216 1292 p2 Ss    9:36AM 0:00.01 -zsh 
> njoly  9494  0.0 -1.1  76  728 p2 R+   11:47AM 0:00.00 ps ux 
> njoly  6757  0.0  0.0 240    4 p4 SWs+ 10:19AM 0:00.07 -zsh 
> njoly  7331  0.0  0.0 204    4 p5 SWs+ 11:43AM 0:00.02 -zsh 

I had a look at this and noticed that ps(1) use sysctl(3)+HW_PHYSMEM
to get the physical memory size.

But on machines with more than 2GB of memory, the returned value
becomes negative (int overflow) :

njoly@calimero [~]> sysctl hw | grep physmem
hw.physmem = -67571712
hw.physmem64 = 4227395584

This leads to an invalid percentage of real memory used by processes.
In that case, we'll need to switch to HW_PHYSMEM64 instead.

As this problem is not amd64 specific, i'll submit a PR.

-- 
Nicolas Joly

Biological Software and Databanks.
Institut Pasteur, Paris.