0

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"

Thanks

1 Answers1

0

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.