Why the value of VSIZE in top is different from the value of VSZ (Virtual set size) in ps

iosiphoneosxpstop

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 of ps on linux), but what's the definition of VSIZE in top? 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

Best Answer

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 Question