JavaScript must be enabled in order for you to see "WP Copy Data Protect" effect. However, it seems JavaScript is either disabled or not supported by your browser. To see full result of "WP Copy Data Protector", enable JavaScript by changing your browser options, then try again.

Drop Caches of Memory in Linux(After 2.6.16)


今天要來記錄最近剛好碰到記憶體都被Cache佔住後,竟然不能再開其他的程序,如上圖Cache的數字就是被佔住的部分,只能透過釋放記憶體(Drop Caches)來得到更多Free的使用空間(一般使用在已經沒有Free的部分可用),所以廢話不多說,直接上實作,如下:

1) 安裝htop並檢視釋放記憶體前的情況(未釋放前的使用量為398MB)
#yum -y install htop
#htop

2) 透過Proc來做釋放記憶體(drop_caches預設為0,1為釋放Pagecache[捨棄一般沒使用的Cache],2為釋放Dentries&Inodes,3為釋放Pagecache[1]+Dentries&Inodes[2],但較不建議因容易造成系統錯誤)
#man proc
...
/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(8) first.
...
#cat /proc/sys/vm/drop_caches
0
#echo 2 > /proc/sys/vm/drop_caches
#sync ; echo 0 > /proc/sys/vm/drop_caches

3) 檢視釋放記憶體後的情況(未釋放前的使用量為294MB)
#htop

#vmstat -S m
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 16456 3 52 0 0 0 1 3 0 0 0 100 0 0

◎以上就是Drop Caches的簡易範例,至於詳細的部分可參考Jserv的文章,累了,收工!

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
This site is protected by WP-CopyRightPro