Linux系統(tǒng)中的內(nèi)存清理和釋放命令歸納小記
# 清理步驟
# 清理前內(nèi)存使用情況
# 開(kāi)始清理
# 清理后內(nèi)存使用情況
完成!
# 查看內(nèi)存條數(shù)命令:
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一下,防止丟數(shù)據(jù)。因?yàn)長(zhǎng)INUX的內(nèi)核機(jī)制,一般情況下不需要特意去釋放已經(jīng)使用的cache。這些cache起來(lái)的內(nèi)容可以增加文件以及的讀寫(xiě)速度。
# 先說(shuō)下free命令怎么看內(nèi)存
total used free shared buffers cached
Mem: 1535052 918928 616124 0 2512 82964
-/+ buffers/cache: 833452 701600
Swap: 0 0 0
# 第一行用全局角度描述系統(tǒng)使用的內(nèi)存狀況:
total——總物理內(nèi)存
used——已使用內(nèi)存,一般情況這個(gè)值會(huì)比較大,因?yàn)檫@個(gè)值包括了cache+應(yīng)用程序使用的內(nèi)存
free——完全未被使用的內(nèi)存
shared——應(yīng)用程序共享內(nèi)存
buffers——緩存,主要用于目錄方面,inode值等(ls大目錄可看到這個(gè)值增加)
cached——緩存,用于已打開(kāi)的文件
total = used + free
used = buffers+cached (maybe add shared also)
第二行描述應(yīng)用程序的內(nèi)存使用:
前個(gè)值表示-buffers/cache——應(yīng)用程序使用的內(nèi)存大小,used減去緩存值
后個(gè)值表示+buffers/cache——所有可供應(yīng)用程序使用的內(nèi)存大小,free加上緩存值
-buffers/cache=used-buffers-cached
+buffers/cache=free+buffers+cached
第三行表示swap的使用:
used——已使用
free——未使用
手動(dòng)執(zhí)行sync命令(描述:sync 命令運(yùn)行 sync 子例程。如果必須停止系統(tǒng),則運(yùn)行 sync 命令以確保文件系統(tǒng)的完整性。sync 命令將所有未寫(xiě)的系統(tǒng)緩沖區(qū)寫(xiě)到磁盤(pán)中,包含已修改的 i-node、已延遲的塊 I/O 和讀寫(xiě)映射文件)
echo 3 > /proc/sys/vm/drop_caches
cat /proc/sys/vm/drop_caches
3
!將/proc/sys/vm/drop_caches值設(shè)為3
# 有關(guān)/proc/sys/vm/drop_caches的用法在下面進(jìn)行了說(shuō)明
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
# 原文鏈接:<a >http://levi.cg.am/?p=3224</a>
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信