今天用spot on light 查了一下開發服務器的內存占用,只剩下60MB
用下面的方法就可以實現清空緩存
頻繁的文件訪問會導致系統的Cache使用量大增
首先使用free -m查看剩余內存
[root@Oracle ~]# free -m
total used free shared buffers cached
Mem: 3383 3319 63 0 97 2395
-/+ buffers/cache: 826 2556
Swap: 1983 195 1788
total 內存總數 used 已經使用的內存數 free 空閑的內存數 shared 多個進程共享的內存總額
說明,釋放前最好sync一下,防止丟數據。
使用方式 : sync
使用說明 : Linux 系統中欲寫入硬盤的資料有的時候會了效率起見,
會寫到 filesystem buffer 中,這個 buffer 是一塊記憶體空間,
如果欲寫入硬盤的資料存于此 buffer 中,而系統又突然斷電的話,
那么資料就會流失了,sync 指令會將存于 buffer 中的資料強制寫入硬盤中。
[root@oracle ~]# echo 1 > /proc/sys/vm/drop_caches
[root@oracle ~]# sysctl -p
[root@oracle ~]# free -m
total used free shared buffers cached
Mem: 3383 1952 1431 0 1 1136
-/+ buffers/cache: 814 2568
Swap: 1983 195 1788
說明:
1>. /proc是一個虛擬文件系統,我們可以通過對它的讀寫操作作為與kernel實體間進行通信的一種手段。也就是說可以通過修改/proc中的文件,來對 當前kernel的行為做出調整。也就是說我們可以通過調整/proc/sys/vm/drop_caches來釋放內存。
0 – 不釋放
1 – 釋放頁緩存
2 – 釋放dentries和inodes
3 – 釋放所有緩存
數字1是用來清空最近放問過的文件頁面緩存
數字2是用來清空文件節點緩存和目錄項緩存
數字3是用來清空1和2所有內容的緩存。
2>. 關于drop_caches的官方說明如下:
Writing to this file causes the kernel to drop clean caches,dentries and inodes from memory, causing that memory to becomefree.
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.