linux 清理內(nèi)存命令詳細(xì)介紹
linux 清理內(nèi)存命令
1.清理前內(nèi)存使用情況
free -m
2.開始清理
echo 1 > /proc/sys/vm/drop_caches
3.清理后內(nèi)存使用情況
free -m
4.完成!
查看內(nèi)存條數(shù)命令:
# sync # echo 1 > /proc/sys/vm/drop_caches echo 2 > /proc/sys/vm/drop_caches echo 3 > /proc/sys/vm/drop_caches
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
說明,釋放前最好sync一下,防止丟數(shù)據(jù)。
因?yàn)長(zhǎng)inux的內(nèi)核機(jī)制,一般情況下不需要特意去釋放已經(jīng)使用的cache。這些cache起來的內(nèi)容可以增加文件以及的讀寫速度。
先說下free命令怎么看內(nèi)存
[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
其中第一行用全局角度描述系統(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——緩存,用于已打開的文件
note:
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加上緩存值
note:
-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 命令將所有未寫的系統(tǒng)緩沖區(qū)寫到磁盤中,包含已修改的 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值設(shè)為3
有關(guān)/proc/sys/vm/drop_caches的用法在下面進(jìn)行了說明
/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
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- Linux系統(tǒng)下利用C程序輸出某進(jìn)程的內(nèi)存占用信息
- 解決Linux下php-fpm進(jìn)程過多導(dǎo)致內(nèi)存耗盡問題
- python監(jiān)控linux內(nèi)存并寫入mongodb(推薦)
- Linux內(nèi)存描述符mm_struct實(shí)例詳解
- Linux共享內(nèi)存實(shí)現(xiàn)機(jī)制的詳解
- Linux內(nèi)存泄漏檢測(cè)shell腳本
- 詳解Linux如何查看當(dāng)前占用CPU或內(nèi)存最多的幾個(gè)進(jìn)程
- Linux監(jiān)控cpu以及內(nèi)存使用情況之top命令(詳解)
- Linux 查看內(nèi)存插槽數(shù)、最大容量的方法
- 分別在Linux和Windows下設(shè)置JVM內(nèi)存的簡(jiǎn)單方法
- 詳解Linux內(nèi)核內(nèi)存管理架構(gòu)
相關(guān)文章
Apache2.4.x版wampserver本地php服務(wù)器如何讓外網(wǎng)訪問及啟用.htaccess
這篇文章主要介紹了Apache2.4.x版wampserver本地php服務(wù)器如何讓外網(wǎng)訪問及啟用.htaccess,需要的朋友可以參考下2015-02-02
Linux CentOS使用crontab設(shè)置定時(shí)重啟的方法
本篇介紹 crontab 設(shè)置定時(shí)任務(wù),并且把 crontab 加入到開機(jī)自啟動(dòng)中,感興趣的朋友跟隨腳本之家小編一起看看吧2018-08-08
Linux下遠(yuǎn)程連接MySQL數(shù)據(jù)庫的方法
本篇文章主要介紹了Linux下遠(yuǎn)程連接MySQL數(shù)據(jù)庫的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06
Linux中對(duì)MySQL優(yōu)化實(shí)例詳解
這篇文章主要介紹了Linux中對(duì)MySQL優(yōu)化實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-05-05
centos 7中添加一個(gè)新用戶并授權(quán)的步驟詳解
這篇文章主要給大家介紹了關(guān)于在centos 7中添加一個(gè)新用戶并授權(quán)的步驟,文中將實(shí)現(xiàn)的步驟介紹的非常詳細(xì),通過文中介紹的步驟可以輕松的創(chuàng)建一個(gè)新用戶并授權(quán),需要的朋友可以參考借鑒,下面來一起看看吧。2017-08-08

