linux 內存清理/釋放命令

1.清理前內存使用狀況 
free -m

2.開始清理  
echo 1 > /proc/sys/vm/drop_caches

3.清理後內存使用狀況 
free -m

4.完成!

查看內存條數命令: node

dmidecode | grep -A16  " Memory Device$ "

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 緩存

# sync
# echo 1 > /proc/sys/vm/drop_caches
  echo 2 > /proc/sys/vm/drop_caches
  echo 3 > /proc/sys/vm/drop_caches yii

cache釋放:
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 ide

說明,釋放前最好sync一下,防止丟數據。 this

由於LINUX的內核機制,通常狀況下不須要特地去釋放已經使用的cache。這些cache起來的內容能夠增長文件以及的讀寫速度。
先說下free命令怎麼看內存 spa

[root@yuyii proc] #  free

total   used   free     shared buffers cached
Mem: 515588 295452 220136 0      2060   64040
-/+ buffers/cache: 229352 286236
Swap: 682720 112 682608

其中第一行用全局角度描述系統使用的內存情況:
total——總物理內存
used——已使用內存,通常狀況這個值會比較大,由於這個值包括了cache+應用程序使用的內存
free——徹底未被使用的內存
shared——應用程序共享內存
buffers——緩存,主要用於目錄方面,inode值等(ls大目錄可看到這個值增長)
cached——緩存,用於已打開的文件
note:
    total=used+free
    used=buffers+cached (maybe add shared also) code

第二行描述應用程序的內存使用:
前個值表示-buffers/cache——應用程序使用的內存大小,used減去緩存值
後個值表示+buffers/cache——全部可供應用程序使用的內存大小,free加上緩存值
note:
   -buffers/cache=used-buffers-cached
   +buffers/cache=free+buffers+cached orm

第三行表示swap的使用:
used——已使用
free——未使用 server

手動執行sync命令(描述:sync 命令運行 sync 子例程。若是必須中止系統,則運行 sync 命令以確保文件系統的完整性。sync 命令將全部未寫的系統緩衝區寫到磁盤中,包含已修改的 i-node、已延遲的塊 I/O 和讀寫映射文件) 內存

[root@server test] #  echo 3 > /proc/sys/vm/drop_caches
[root@server test] #  cat /proc/sys/vm/drop_caches

                             !將/proc/sys/vm/drop_caches值設爲3

有關/proc/sys/vm/drop_caches的用法在下面進行了說明 /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
相關文章
相關標籤/搜索