博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux手动释放内存
阅读量:5773 次
发布时间:2019-06-18

本文共 2259 字,大约阅读时间需要 7 分钟。

[root@rusky ~]# free -m

                   total       used       free     shared    buffers     cached

Mem:          1011        343        667          0         34        218

-/+ buffers/cache:         91        919

Swap:         1992          0       1992

[root@rusky ~]# sync    把内存dirty数据同步到硬盘

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

[root@rusky ~]# echo 0 > /proc/sys/vm/drop_caches

[root@rusky ~]# free -m

                   total       used       free     shared    buffers     cached

Mem:          1011        124        886          0          0         36

-/+ buffers/cache:         87        923

Swap:         1992          0       1992

  注解:/proc是一个虚拟文件系统,我们可以通过对它的读写操作做为与kernel实体间进行通信的一种手段。也就是说可以通过修改 /proc中的文件,来对当前kernel的行为做出调整。那么我们就可以通过调整/proc/sys/vm/drop_caches来释放内存。

  手动执行sync命令是为了确保文件系统的完整性(描述:sync命令运行sync 子例程。如果必须停止系统,则运行sync命令以确保文件系统的完整性。sync命令将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件),所以这一步必须先做。

==============================================================

drop_caches

Writing to this will cause the kernel to drop clean caches, as well as reclaimable slab objects like dentries and inodes.  Once dropped, their memory becomes free.

To free pagecache:

         echo 1 > /proc/sys/vm/drop_caches

To free reclaimable slab objects (includes dentries and inodes):

         echo 2 > /proc/sys/vm/drop_caches

To free slab objects and pagecache:

         echo 3 > /proc/sys/vm/drop_caches

This is a non-destructive operation and will not free any dirty objects. To increase the number of objects freed by this operation, the user may run `sync' prior to writing to /proc/sys/vm/drop_caches.  This will minimize the number of dirty objects on the system and create more candidates to be dropped.

This file is not a means to control the growth of the various kernel caches (inodes, dentries, pagecache, etc...)  These objects are automatically reclaimed by the kernel when memory is needed elsewhere on the system.

Use of this file can cause performance problems.  Since it discards cached objects, it may cost a significant amount of I/O and CPU to recreate the dropped objects, especially if they were under heavy use.  Because of this, use outside of a testing or debugging environment is not recommended.

You may see informational messages in your kernel log when this file is used: cat (1234): drop_caches: 3

These are informational only.  They do not mean that anything is wrong with your system.  To disable them, echo 4 (bit 3) into drop_caches.

==============================================================

转载地址:http://cexux.baihongyu.com/

你可能感兴趣的文章
Qt Creator 使用技巧
查看>>
perl学习笔记(4)
查看>>
本地用户访问FTP服务,拒绝匿名用户访问
查看>>
Mockito测试静态注入
查看>>
提高EJB性能的十大技巧
查看>>
2G,3G,4G基站区分
查看>>
intellij idea 格式化代码
查看>>
Linux dstat监控工具
查看>>
开机启动流程分析
查看>>
linux查看版本信息
查看>>
我的友情链接
查看>>
百度RPC框架 BRPC 初体验
查看>>
php中将object 转 array数组形式
查看>>
java反射机制
查看>>
Java 面试题目最全集合1000+ 大放送,能答对70%就去BATJTMD试试~
查看>>
jfinal It is indirectly referenced from required
查看>>
服务器遭受***后的处理办法cc
查看>>
浮点数加法引发的问题:浮点数的二进制表示
查看>>
OSPF__配置
查看>>
C语言的内存对齐问题
查看>>