有很多種方法可以查看Linux 記憶體的使用狀況,如vmstat、free、nmon等,這裡以 free 指令為例
[root@db01 ~]# free
total used free shared buffers cached
Mem: 5144296 3008448 2135848 0 8600 2819464
-/+ buffers/cache: 180384 4963912
Swap: 6160376 18484 6141892
這裡buffers是放即將被寫入硬碟資料的緩衝區;而cache則是資料預先自硬碟讀取暫存在記憶體的暫存區。Linux 作業系統傾向會把資料cache在記憶體中,即使應用程式結束,也不會立即將cache的資料清除。
以下介紹如何把cache的資料清除:
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
To free pagecache:
- echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
- echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
- echo 3 > /proc/sys/vm/drop_caches
As this is a non-destructive operation, and dirty objects are not freeable, the user should run "sync" first in order to make sure all cached objects are freed.
沒有留言:
張貼留言