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.

I'm not an expert on linux so I do apologize in advance for the silly question. I have a vps machine with ubuntu 10.04 and 512Mb of RAM. I'm trying to guess how much memory is available after running the mongodb daemon.

If I run free -m I get

             total       used       free     shared    buffers     cached
Mem:           496        489          6          0          4        452
-/+ buffers/cache:         33        462
Swap:          511          4        507

If I run ps euf I get

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       948  0.0  0.0   5928   472 tty6     Ss+  Aug25   0:00 /sbin/getty 384
root       947  0.0  0.0   5928   472 tty5     Ss+  Aug25   0:00 /sbin/getty 384
root       946  0.0  0.0   5928   472 tty4     Ss+  Aug25   0:00 /sbin/getty 384
root       945  0.0  0.0   5928   472 tty3     Ss+  Aug25   0:00 /sbin/getty 384
root       944  0.0  0.0   5928   472 tty2     Ss+  Aug25   0:00 /sbin/getty 384
root       943  0.0  0.1  51856   536 hvc0     Ss   Aug25   0:00 /bin/login -- 
root       978  0.0  0.4  20580  2424 hvc0     S    Aug25   0:01  \_ -bash TERM=
root      7593  0.0  0.1  10332   524 hvc0     T    Aug25   0:00      \_ nano he
root     12576  0.7  3.1 122520 16220 hvc0     Sl   07:42   0:12      \_ ./mongo
root     12599  0.0  0.2  16300  1060 hvc0     R+   08:09   0:00      \_ ps euf

So it seems that less than 5% of memory is used by processes but I have only 6Mb of free memory... why?

share|improve this question

2 Answers 2

up vote 9 down vote accepted

The buffers and cache are dynamically sized. If processes need more space, then it is taken from the buffers and the cache.

The key is to look at the second line ("-/+ buffers/cache").

Mem:           496        489          6          0          4        452
-/+ buffers/cache:         33        462

Notice that the free in the second line (462) is the sum of 6 (free), 4 (buffers) and 452 (cached). This is the real amount of free space. If this falls too low, then the system would start swapping processes out of memory to swap space.

So in reality, you are using 33MB of memory and have available 462MB - probably slightly less since you would still need some buffers for i/o.

share|improve this answer
    
Great and clear explanation. Thanks! –  mamoo Aug 27 '11 at 15:32

Apart from the correct explanation by Arcege, there are also two other misconceptions hidden in your interpretation of ps euf.

  1. The command ps euf does not list all the processes - you should use ps axeuf for that.

  2. Percentages of used memory for each process are given, as you can see, rounded to 0.1%. So adding them up will give erroneous results - (roughly) all processes use some memory - even if it is less then 0.1%. If there are, for instance, 20 processes that use 0.05%, they'd add up to 1%, not 0%.

share|improve this answer

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.