linux服务手动释放buff/cache缓存

1.free -m/free -hm 查看内存使用情况

 2.echo 3 >/proc/sys/vm/drop_caches 

[root@bin]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1734         477         222           0        1034        1101
Swap:             0           0           0
[root@bin]# echo 3 >/proc/sys/vm/drop_caches 
[root@bin]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1734         478        1183           0          72        1146
Swap:             0           0           0

在系统中除了内存将被耗尽的时候可以清缓存以外,我们还可以使用下面这个文件来人工触发缓存清除的操作:

echo 1 > /proc/sys/vm/drop_caches // 表示清除pagecache。
echo 2 > /proc/sys/vm/drop_caches // 表示清除回收slab分配器中的对象(包括目录项缓存和inode缓存)。slab分配器是内核中管理内存的一种机制,其中很多缓存数据实现都是用的pagecache。
echo 3 > /proc/sys/vm/drop_caches // 表示清除pagecache和slab分配器中的缓存对象。


缓存清理场景:

如果服务器上运行内存型占用较大的服务或者数据库,经过一定的时间,会将系统中的buff/cache占满,导致性能急剧下降,甚至频繁使用swap区进行数据交换。从而导致io也到达瓶颈。

 

注:生产环境慎用,清空缓存之前确认是否存在正在运行的数据。

posted @ 2022-11-09 17:27  BlogMemory  阅读(1042)  评论(0编辑  收藏  举报