0

I have three conflicting sources of information on a process' memory usage. I'm using gnome-terminal as the example process.

ps aux reports a usage of 624480 units for pid 31880 (I say units, because I don't know what it uses as unit), but according to https://superuser.com/a/117921/403466, it's in bytes.

Then I have /proc/31880/status which tells me it's the same amount, but the units are kB:

[...]
VmPeak:   624480 kB
VmSize:   624480 kB
VmLck:         0 kB
[...]

which translates to 624 MiB (completely impossible?); and finally I have gnome-system-monitor which gives me approx. 9.9 MiB.

Which one is correct?

Thomas
  • 6,362
Lev
  • 113

2 Answers2

2

They’re all correct: ps shows kibibytes, as does /proc/.../status. 610 MiB (624,480 kiB) is the process’ virtual size, which is the total amount of address space it has reserved (in its own mappings). 9.9 MiB is its resident size, which is the amount of memory it is actually using.

See Need explanation on Resident Set Size/Virtual Size for more details.

Stephen Kitt
  • 434,908
2

Install the smem package if you don't have it already. It is the most accurate. ps -eo pid,command,rss and ps -eo pid,command,size are both a bit inaccurate as they can either not report enough or just too much as they count the memory that's actually allocated.

smem shows the PID, User, Command, Swap, USS, PSS, and RSS. Run it and pay attention to the PSS column. That's the actual amount of physical memory being used and it also accounts for the proper amount of shared memory which is actually used. If you just want PID, Command, and PSS then you can pipe it into awk. For me, that would be columns 1, 3, and 6.

smem | awk '{print $1,$3,$6}'

Nasir Riley
  • 11,422