日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux 进程 释放内存,Linux 释放内存方法和原理

發(fā)布時(shí)間:2023/12/1 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 进程 释放内存,Linux 释放内存方法和原理 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

今天驚愕地發(fā)現(xiàn),主節(jié)點(diǎn)上8G內(nèi)存被不知道什么進(jìn)程吃掉了整整6G有余,正常的計(jì)算快要維持不下去了,遂處理之。

先看看內(nèi)存使用狀況

[root@node1 ~]# free -m

total used free shared buffers cached

Mem: 8004 6557 1446 0 163 5630

-/+ buffers/cache: 763 7240

Swap: 1983 0 1983

其中:

total 內(nèi)存總數(shù)

used 已經(jīng)使用的內(nèi)存數(shù)

free 空閑的內(nèi)存數(shù)

shared 多個(gè)進(jìn)程共享的內(nèi)存總額

buffers Buffer Cache和cached Page Cache 磁盤緩存的大小

-buffers/cache 的內(nèi)存數(shù):used - buffers - cached

+buffers/cache 的內(nèi)存數(shù):free + buffers + cached

可用的memory=free memory+buffers+cached

把內(nèi)存里的數(shù)據(jù)暫時(shí)寫到硬盤里

[root@node1 ~]# sync

修改 /proc/sys/vm/drop_caches文件(/proc/sys/vm/drop_caches的默認(rèn)值為0)

[root@node1 ~]# echo 3 > /proc/sys/vm/drop_caches

[root@node1 ~]# cat /proc/sys/vm/drop_caches

再看內(nèi)存

[root@node1 ~]# free -m

total used free shared buffers cached

Mem: 8004 631 7372 0 0 60

-/+ buffers/cache: 570 7433

Swap: 1983 0 1983

終于釋放出來了。

有關(guān)/proc/sys/vm/drop_caches的用法在下面進(jìn)行了說明(原文:http://www.linuxinsight.com/proc_sys_vm_drop_caches.html):

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.

This tunable was added in 2.6.16.

真實(shí)情況是 “當(dāng)有某程序需要占用大內(nèi)存時(shí)linux會(huì)自動(dòng)釋放cache”

linux的理念是內(nèi)存空著不用白不用,因此會(huì)使用空閑內(nèi)存來做buffer和cache。

我的一臺(tái)虛擬機(jī)運(yùn)行了JBOSS,在運(yùn)行一段時(shí)間后,查看內(nèi)存使用情況:

[root@JBOSS ~]# free -m

total used free shared buffers cached

Mem: 3949 2928 1021 0 308 1278

-/+ buffers/cache: 1341 2608

Swap: 4094 0 4094

可以看出,內(nèi)存已用2928M,但實(shí)際除去 buffers/cache后實(shí)際只使用了1341M。

你若不管它,內(nèi)存是不會(huì)釋放的,而且也沒必要釋放。

總結(jié)

以上是生活随笔為你收集整理的linux 进程 释放内存,Linux 释放内存方法和原理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。