我要纯净 - 拒绝流氓,51纯净!

当前位置:首页 > 系统教程 > Linux教程 > 详细页面

Linux系统内存莫名被占用,该如何清空缓存释放找回

发布日期:2020-07-21 来源于:网络 编辑:我要纯净网

  今天用spot on light 查了一下开发服务器的内存占用,只剩下60MB,用下面的方法就可以实现清空缓存,频繁的文件访问会导致系统的Cache使用量大增。

Linux系统内存莫名被占用,该如何清空缓存释放找回

  首先使用free -m查看剩余内存

  [root@Oracle ~]# free -m

  total used free shared buffers cached

  Mem: 3383 3319 63 0 97 2395

  -/+ buffers/cache: 826 2556

  Swap: 1983 195 1788

  total 内存总数 used 已经使用的内存数 free 空闲的内存数 shared 多个进程共享的内存总额

  说明,释放前最好sync一下,防止丢数据。

  使用方式 : sync

  使用说明 : Linux 系统中欲写入硬盘的资料有的时候会了效率起见,

  会写到 filesystem buffer 中,这个 buffer 是一块记忆体空间,

  如果欲写入硬盘的资料存于此 buffer 中,而系统又突然断电的话,

  那么资料就会流失了,sync 指令会将存于 buffer 中的资料强制写入硬盘中。

  [root@oracle ~]# echo 1 > /proc/sys/vm/drop_caches

  [root@oracle ~]# sysctl -p

  [root@oracle ~]# free -m

  total used free shared buffers cached

  Mem: 3383 1952 1431 0 1 1136

  -/+ buffers/cache: 814 2568

  Swap: 1983 195 1788

  说明:

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

  0 – 不释放

  1 – 释放页缓存

  2 – 释放dentries和inodes

  3 – 释放所有缓存

  数字1是用来清空最近放问过的文件页面缓存

  数字2是用来清空文件节点缓存和目录项缓存

  数字3是用来清空1和2所有内容的缓存。

  2>. 关于drop_caches的官方说明如下:

  Writing to this file causes the kernel to drop clean caches,dentries and inodes from memory, causing that memory to becomefree.

  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.

评论留言

    留言与评论(共有 条评论)
    验证码:

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载