[linux] 手動清除Linux上的Cache

  • 4035
  • 0

最近工作上遇到linux 的server memory常常滿載, 可用記憶體不足.
所以需要清理一下.

上網查了一下, 幾行簡單的指令就可以做到了.

 執行清除指令前要使用sync指令, 以避免錯誤訊息.

$ sync
# Freeing the page cache
$echo 1 > /proc/sys/vm/drop_caches
# Free dentries and inodes
$ echo 2 > /proc/sys/vm/drop_caches
# Free the page cache, dentries and the inodes.
$ echo 3 > /proc/sys/vm/drop_caches

三個階段做完即可.

 

另外可以用以下幾個指令查詢一下記憶體前後變化.

$ free -m
$ top
$ ps -aux
$ watch cat /proc/meminfo
$ vmstat