linux清理buffer缓存脚本

1、清理缓存脚本
复制代码
[root@host-172-21-210-62 opt]# more cleanCache.sh
#!/bin/bash
#每24小时清除一次缓存
echo "开始清除缓存"
sync;sync;sync #写入硬盘,防止数据丢失
sleep 10 #延迟10秒
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
复制代码
2、清理前buff情况
[root@host-172-21-210-62 ~]# free -g
              total        used        free      shared  buff/cache   available
Mem:             31           4           6           1          19          24
Swap:             0           0           0
3、清理buff
[root@host-172-21-210-62 opt]# sh cleanCache.sh
4、清理后缓存情况
[root@host-172-21-210-62 opt]# free -g
              total        used        free      shared  buff/cache   available
Mem:             31           4          23           1           2          24
Swap:             0           0           0
drop_caches的详细文档如下:
复制代码
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
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
As this is a non-destructive operation, and dirty objects are notfreeable, the user should run “sync” first in order to make sure allcached objects are freed.
This tunable was added in 2.6.16.
复制代码

 

posted @   苍茫宇宙  阅读(491)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示