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

18,368

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.

Share:
18,368

Related videos on Youtube

Kusalananda
Author by

Kusalananda

Updated on September 18, 2022

Comments

  • Kusalananda
    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 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
    
    • Admin
      Admin almost 13 years
      I 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
      Admin over 12 years
      they 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
      Admin about 11 years
      "This top output from iPhone is different from the top on Linux" — isn't a surprise, is it?
  • Nikhil Mulley
    Nikhil Mulley over 12 years
    Another 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
    Johan about 11 years
    What 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.