2010年8月4日 星期三

釋放kernel cache增加記憶體空間

下這行指令將kernel中沒在使用的cache給釋放出來
sync;echo 1 > /proc/sys/vm/drop_caches

1是釋放pagecache
2是釋放dentries and inodes
3則是上面兩種一起釋放

/proc/sys/vm/drop_caches (since Linux 2.6.16)
Writing to this file causes the kernel to drop clean caches,
dentries and inodes from memory, causing that memory to become
free.

To free pagecache, use echo 1 > /proc/sys/vm/drop_caches;
to free dentries and inodes, use echo 2 > /proc/sys/vm/drop_caches;
to free pagecache, dentries and inodes, use echo 3 >
/proc/sys/vm/drop_caches.

Because this is a non-destructive operation and dirty objects
are not freeable, the user should run sync first.