Why the value of VSIZE in top is different from the value of VSZ (Virtual set size) in ps?
Linux memory system is filled with many routines of memory optimization utilities and memory sharing, making the very idea of how memory is shared and being consumed among, a cumbersome approach.The output of ps and other ps related commands all work up their output from data under /proc
filesystem. Particularly ps
, RSS(resident size memory) and VSIZE(Virtual memory size) are both important, however VSIZE does not show the accurate usage of the memory and the difference between VSIZE and rss is what is actually intended and allocated to the program during the initialization but may not be referenced yet.
Like the program may have lots of libraries linked but they are not loaded yet because they are not referenced yet in the actual program runtime. RSS gives the total memory actually used by the program but may not give a true picture of the memory consumption, since most of the memory allocated may be shared with other instances of the same process or other processes. Looking under /proc/<processid>/maps
may give a rough idea of how the memory has been used but they quiet can be misleading sometimes. Use pmap -x <pid>
from commandline, useful to see the spreadup is.
The often better utilities are free
and vmstat
. free
will give you overall current memory consumption details and vmstat can be used to see how often it is being updated.
Related videos on Youtube
![Kusalananda](https://i.stack.imgur.com/vjTWE.jpg?s=256&g=1)
Kusalananda
Updated on September 18, 2022Comments
-
Kusalananda almost 2 years
I know VSZ in
ps
is for the total address space allocated for the app and is sometimes aliased as vsize (mentioned in man page ofps
on linux), but what's the definition of VSIZE intop
? This top output from iPhone is different from the top on Linux:PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE 1875 emma 0.0% 0:30.83 7 139 932 17868K 5328K 29M 181M root# ps -eo pid,rss,vsz|grep 1875 1875 29324 441324
-
Admin almost 13 yearsI can't reproduce this on any of my darwin machines. It makes me think the shell that they setup on the iphone had a weird blocksize set?
-
Admin over 12 yearsthey look to be calculating RSIZE/rss the same way, but ps is reporting a vsz 2.5x larger than that reported by top. maybe
top
on IOS doesn't include shared objects in vsize, or something. -
Admin about 11 years"This top output from iPhone is different from the top on Linux" — isn't a surprise, is it?
-
-
Nikhil Mulley over 12 yearsAnother reason or thoughtful explanation why ps should NOT be considered to be giving correct process memory usage. Read this at virtualthreads.blogspot.com/2006/02/…
-
Johan about 11 yearsWhat the poster of this answer is trying to say is that the definition of memory used is complex and varied. There is no single place in the kernel where it is tracked and reported. The utilities perform their own interpretation of the numerous statistics that are reported by the kernel.