linux内存释放

来源:互联网 发布:网上值机软件 编辑:程序博客网 时间:2024/05/22 11:23

在Linux下,内存不会自动释放。当频繁读取文件过多之后就会出现free内存很小的表象,效果如下:

image1.png

请注意,上图显示已使用内存:7364432,是包含后面buffers和cached的。并不代表实际物理内存使用到了7.3G,实际使用的物理内存是下面显示去掉buffers和cache后的:828144。我们看到cached居然使用了6G之多,其实就是上面说的内存没有自动释放而已。。如果想手动释放内存,请执行下面命令即可。

释放内存:

/bin/sync/bin/echo "1">/proc/sys/vm/drop_caches


操作之后再来看看内存使用情况:

image2.png

相关引用如下:

/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.

0 0
原创粉丝点击