This question already has an answer here:

I learned and always think that linux free memory is the "free" of "-/+ buffers/cache" You can get this knowledge from lots of website. Meaning of the buffers/cache line in the output of free http://www.linuxatemyram.com/

[root@dev001 ~]# free
             total       used       free     shared    buffers     cached
Mem:      32877844   31422864    1454980          0    1358500     774612
-/+ buffers/cache:   29289752    3588092
Swap:      1048568      67984     980584
[root@dev001 ~]# mkdir /mnt/ramdisk
[root@dev001 ~]# mount -t tmpfs -o size=10g tmpfs /mnt/ramdisk
[root@dev001 ~]# cd /mnt/ramdisk/
[root@dev001 ramdisk]# dd if=/dev/zero of=1g bs=1024 count=$((1024*1024*10))
10485760+0 records in
10485760+0 records out
10737418240 bytes (11 GB) copied, 20.0645 s, 535 MB/s
[root@dev001 ramdisk]# ls -lh
total 10G
-rw-r--r-- 1 root root 10G Jul 26 21:09 1g
[root@dev001 ramdisk]# free 
             total       used       free     shared    buffers     cached
Mem:      32877844   32630940     246904          0     792364   10901876
-/+ buffers/cache:   20936700   11941144
Swap:      1048568      67984     980584
[root@dev001 ~]# umount /mnt/ramdisk
[root@dev001 ~]# free 
             total       used       free     shared    buffers     cached
Mem:      32877844   22128348   10749496          0     792416     416160
-/+ buffers/cache:   20919772   11958072
Swap:      1048568      67984     980584
[root@dev001 ~]# free
             total       used       free     shared    buffers     cached
Mem:      32877844   22127372   10750472          0     792432     416160
-/+ buffers/cache:   20918780   11959064
Swap:      1048568      67984     980584

While, these days, I found my server is out of memory, but when we do these things , the memory comes back. Any one can answer why is it?

  1. The free memory is 3,588,092(let's say 3.4G) and total memory is 32G, am I right?
  2. During this step, we haven't found any process that eat lots of memory via the command 'top', So we thought 3.4G free is not correct, we 100% sure free memory is at least 20G
  3. We mount our memory as a ramdisk to local, and wrote data into it, as you can see, it is 10G, and it is successful
  4. After unmount, the free memory rise to 11,959,064 how could it be?

Seems the free memory is not just the "free" of "-/+ buffers/cache"


marked as duplicate by mdpc, Ward, HBruijn Jul 29 '16 at 20:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Possible missing step 3a) we monitored what the VM system was doing while we did this. It is possible that it was freeing dirty pages by flushing them to disc, in order to free them for the ramdisc, while you were populating the ramdisc. When you destroyed the ramdisc, those pages were now free. – MadHatter Jul 27 '16 at 7:18
  • I would guess linux is smart enough to notice that you're copying zero bytes so it really does not need to use real RAM for pretty much any of your ramdisk. Try using fio instead of dd for testing the ramdisk. – Mikko Rantalainen Jan 13 '18 at 18:07

Used is a sum of Buffer+cache and actual system memory usage. In your case when you try mount your memory as a ramdisk to local it took memory from cache. If you observed cache size is reduced after unmount that partition because that cache memory again becomes free memory.

  • The 'Used' of '"-/+ buffers/cache" should already exclude the Buffer+Cache, before the 'mount', does it only have '3,588,092' free memory, how could I get 10G ramdisk if there is only 3G – Freeagle Jul 29 '16 at 6:27
  • Yes, If your cache have more then 10G consumption then it will take 3G from free and rest from the buffer and cache. – Murtuza Kolasavala Dec 10 '16 at 5:41

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