Linux Free Memory by dropping caches
id : 4q2bcfgi1w
category : computer
blog : unixlinux
created : 07/30/10 - 08:39:31

Prerequisites
  • You needed to have at least a 2.6.16 kernel to use this tip.
# uname -a
Linux ****** 2.6.18-194.el5PAE #1 SMP Tue Mar 16 22:00:21 EDT 2010 i686 i686 i386 GNU/Linux


How
  • Use /proc/sys/vm/drop_caches to drop caches, just echo a number to it.

  • To free pagecache :
# echo 1 > /proc/sys/vm/drop_caches


  • To free dentries and inodes :
# echo 2 > /proc/sys/vm/drop_caches


To
  • free pagecache, dentries and inodes :
# echo 3 > /proc/sys/vm/drop_caches


  • This is a non-destructive operation and dirty objects are not freeable, run sync first!
# sync


Example
  • Before :
# free -m
             total       used       free     shared    buffers     cached
Mem:          4052        799       3253          0        131        610
-/+ buffers/cache:         57       3994
Swap:         1023          0       1023


  • After :
# sync ; echo 3 > /proc/sys/vm/drop_caches ; free
             total       used       free     shared    buffers     cached
Mem:       4149828      40548    4109280          0        236       7648
-/+ buffers/cache:      32664    4117164
Swap:      1048568          0    1048568


Related link