Linux内存cached释放


Linux内存cached释放

我们用free命令查看系统内存使用情况的时候会发现:

#free -m
1、total = used + free
2、cached比较大,甚至我遇见过内存剩余只有7M的情况,这个时候cached非常大,基本上接近等于total了,这个时候打开文件或者传输文件的时候可用内存很小,程序可能就会用到交换分区swap了,所以会发现机器速度变慢的情况


如何解决这个导致机器变慢的问题呢?
罪魁祸首就是内存都被cached了,free的基本没有了
所以我们应该想想如何把cached内存释放出来
重启机器肯定是可以解决,但是我们肯定是不能用这样的办法


释放方法有三种(系统默认值是0,释放之后你可以再改回0值):
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


果然如此,这样立刻解决了内存问题。
root@localhost ~]# free -m
            total      used      free    shared    buffers    cached
Mem:        15940      7187      8753          0        326      4824
-/+ buffers/cache:      2035      13905
Swap:        18127          0      18127
[root@localhost ~]#  echo "1" > /proc/sys/vm/drop_caches
^[[A^[[A[root@localhfree -m
            total      used      free    shared    buffers    cached
Mem:        15940      1903      14037          0          0        29
-/+ buffers/cache:      1874      14066
Swap:        18127          0      18127

相关阅读:

Linux高端内存映射(上)
Linux高端内存映射(中)
Linux高端内存映射(中)

相关内容