Linux系統中的記憶體清理和釋放命令歸納

來源:互聯網
上載者:User

   # 清理步驟

  # 清理前記憶體使用量情況

  代碼如下:

  free -m

  # 開始清理

  代碼如下:

  echo 1 > /proc/sys/vm/drop_caches

  # 清理後記憶體使用量情況

  代碼如下:

  free -m

  完成!

  # 查看記憶體條數命令:

  複製代碼

  代碼如下:

  dmidecode | grep -A16 "Memory Device$"

  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

  sync

  # 釋放前最好sync一下,防止丟資料。因為LINUX的核心機制,一般情況下不需要特意去釋放已經使用的cache。這些cache起來的內容可以增加檔案以及的讀寫速度。

  # 先說下free命令怎麼看記憶體

  代碼如下:

  $free

  total used free shared buffers cached

  Mem: 1535052 918928 616124 0 2512 82964

  -/+ buffers/cache: 833452 701600

  Swap: 0 0 0

  # 第一行用全域角度描述系統使用的記憶體狀況:

  total——總實體記憶體

  used——已使用記憶體,一般情況這個值會比較大,因為這個值包括了cache+應用程式使用的記憶體

  free——完全未被使用的記憶體

  shared——應用程式共用記憶體

  buffers——緩衝,主要用於目錄方面,inode值等(ls大目錄可看到這個值增加)

  cached——緩衝,用於已開啟的檔案

  total = used + free

  used = buffers+cached (maybe add shared also)

  第二行描述應用程式的記憶體使用量:

  前個值表示-buffers/cache——應用程式使用的記憶體大小,used減去緩衝值

  後個值表示+buffers/cache——所有可供應用程式使用的記憶體大小,free加上緩衝值

  -buffers/cache=used-buffers-cached

  +buffers/cache=free+buffers+cached

  第三行表示swap的使用:

  used——已使用

  free——未使用

  手動執行sync命令(描述:sync 命令運行 sync 子常式。如果必須停止系統,則運行 sync 命令以確保檔案系統的完整性。sync 命令將所有未寫的系統緩衝區寫到磁碟中,包含已修改的 i-node、已延遲的塊 I/O 和讀寫對應檔)

  echo 3 > /proc/sys/vm/drop_caches

  cat /proc/sys/vm/drop_caches

  3

  !將/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

  # 原文連結:http://levi.cg.am/?p=3224

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.