Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
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
add comment

2 Answers 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.

share|improve this answer
    
Then i don't get why my memory is almost used up. Those two processes are at the top, beneath it all other processes use < 5MB res memory. –  Fabian Zeindl May 25 '12 at 8:18
    
Oh. i see, linux is using all that for i/o buffers? –  Fabian Zeindl May 25 '12 at 8:18
1  
Yes, the "Mem" and "+/- buffers/cache" lines can be a little confusing, but there's another question here that has some explanation. For what you're probably expecting for free memory, I'd look at the "free" column of the "+/-" row. –  John Flatness May 25 '12 at 18:14
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.