今天用spot on light 查了一下開發(fā)服務(wù)器的內(nèi)存占用,只剩下60MB
用下面的方法就可以實現(xiàn)清空緩存
頻繁的文件訪問會導(dǎo)致系統(tǒng)的Cache使用量大增
首先使用free -m查看剩余內(nèi)存
[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 內(nèi)存總數(shù) used 已經(jīng)使用的內(nèi)存數(shù) free 空閑的內(nèi)存數(shù) shared 多個進程共享的內(nèi)存總額
說明,釋放前最好sync一下,防止丟數(shù)據(jù)。
使用方式 : sync
使用說明 : Linux 系統(tǒng)中欲寫入硬盤的資料有的時候會了效率起見,
會寫到 filesystem buffer 中,這個 buffer 是一塊記憶體空間,
如果欲寫入硬盤的資料存于此 buffer 中,而系統(tǒng)又突然斷電的話,
那么資料就會流失了,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是一個虛擬文件系統(tǒng),我們可以通過對它的讀寫操作作為與kernel實體間進行通信的一種手段。也就是說可以通過修改/proc中的文件,來對 當(dāng)前kernel的行為做出調(diào)整。也就是說我們可以通過調(diào)整/proc/sys/vm/drop_caches來釋放內(nèi)存。
0 – 不釋放
1 – 釋放頁緩存
2 – 釋放dentries和inodes
3 – 釋放所有緩存
數(shù)字1是用來清空最近放問過的文件頁面緩存
數(shù)字2是用來清空文件節(jié)點緩存和目錄項緩存
數(shù)字3是用來清空1和2所有內(nèi)容的緩存。
2>. 關(guān)于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.