2

free -m shows me the following in my system:

             total       used       free     shared    buffers     cached
Mem:          3954       3842        111          0        248       2585
-/+ buffers/cache:       1008       2945
Swap:         3811          4       3807

So memory looks pretty used up, but top sorted by memory shows the following top-processes:

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                                              
 8891 minecraf  20   0 2374m 277m 9.9m S    1  7.0   0:12.21 java                                                                                                                                                                  
 8704 root      39  19 2802m 272m  11m S    0  6.9   0:28.73 java      

The virtual memory used by java seems to be huge, but i learned on the internet that that's not a problem. So i guess my question is: Why does free show the virtual memory, if it's not that meaningful?

  • 3
    Just because this particular information might not be useful for your particular scenario, it doesn't mean that it isn't useful in other situations. – Chris Down May 24 '12 at 21:55

2 Answers2

2

The "Mem" line of free doesn't show virtual memory usage, it shows physical memory usage.

The "RES" (for resident) and "%MEM" columns from top shows you the same: the physical memory being used by each process.

free does show you the available and used swap space, and top has its "VIRT" column, both of which can be important. Roughly, swap space plus physical memory gives you your total possible virtual memory space. Get up to that limit and you'll start getting processes killed or unable to allocate memory and things will be bad.

0

The VIRT count can be huge, as you're able to map virtual memory to files or libraries. I have a small Java application running that uses ~6g VIRT memory but 59m RESident.

The virtual memory used by java seems to be huge, but i learned on the internet that that's not a problem

The reason the virtual memory isn't that important is that it's paged out to swap space (hdd store) when it isn't used or free resident memory is needed. The stuff in swap spaces goes there for a reason; cause it's used rarely (or not at all, but just referenced somewhere). If you're on a 64bit operating system, you can address a whole lot more than you use and let the virtual memory manager worry.

This blog post has some comments on virtual memory in programming: http://antirez.com/post/what-is-wrong-with-2006-programming.html

You shouldn't be swapping frequently used data from RAM to HDD in the first place, and that's why you're being told it's not a problem that Java allocates a lot of memory.