国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Linux > 正文

linux如何手動(dòng)釋放內(nèi)存

2024-08-28 00:01:33
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
  當(dāng)在Linux下頻繁存取文件后,物理內(nèi)存會(huì)很快被用光,當(dāng)程序結(jié)束后,內(nèi)存不會(huì)被正常釋放,因此有時(shí)候是需要我們手動(dòng)釋放的,那么具體釋放方法是:
  /proc是一個(gè)虛擬文件系統(tǒng),我們可以通過(guò)對(duì)它的讀寫(xiě)操作做為與kernel實(shí)體間進(jìn)行通信的一種手段。也就是說(shuō)可以通過(guò)修改/proc中的文件,來(lái)對(duì)當(dāng)前kernel的行為做出調(diào)整。那么我們可以通過(guò)調(diào)整/proc/sys/vm/drop_caches來(lái)釋放內(nèi)存。操作如下:
  [root@server test]# cat /proc/sys/vm/drop_caches
  0
  首先,/proc/sys/vm/drop_caches的值,默認(rèn)為0。
  [root@server test]# sync
  手動(dòng)執(zhí)行sync命令(描述:sync 命令運(yùn)行 sync 子例程。如果必須停止系統(tǒng),則運(yùn)行sync 命令以確保文件系統(tǒng)的完整性。sync 命令將所有未寫(xiě)的系統(tǒng)緩沖區(qū)寫(xiě)到磁盤中,包含已修改的 i-node、已延遲的塊 I/O 和讀寫(xiě)映射文件)
  [root@server test]# echo 3 > /proc/sys/vm/drop_caches
  [root@server test]# cat /proc/sys/vm/drop_caches
  3
  將/proc/sys/vm/drop_caches值設(shè)為3
  [root@server test]# free -m
  total used free shared buffers cached
  Mem: 249 66 182 0 0 11
  -/+ buffers/cache: 55 194
  Swap: 511 0 511
  再來(lái)運(yùn)行free命令,會(huì)發(fā)現(xiàn)現(xiàn)在的used為66MB,free為182MB,buffers為0MB,cached為11MB。那么有效的釋放了buffer和cache。
  ◎ 有關(guān)/proc/sys/vm/drop_caches的用法在下面進(jìn)行了說(shuō)明
  /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
  are not freeable, the user should run sync first.
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 秦皇岛市| 施秉县| 环江| 闻喜县| 龙川县| 宜川县| 阿合奇县| 扎鲁特旗| 乐平市| 浦城县| 凌源市| 岳普湖县| 墨竹工卡县| 镇雄县| 新丰县| 安吉县| 石屏县| 柯坪县| 武强县| 鄄城县| 建阳市| 晋江市| 望城县| 于都县| 苍南县| 全椒县| 绥宁县| 太仆寺旗| 七台河市| 麻阳| 建始县| 家居| 临武县| 湘西| 克东县| 廉江市| 临邑县| 长汀县| 定襄县| 莲花县| 同仁县|