linux清理缓存_自动清理linux系统内存和Cache方法
1、手动清理内存和Cache方法Linux下清理内存和Cache方法 /proc/sys/vm/drop_caches频繁的文件访问会导致系统的Cache使用量大增$ free -mtotal used free shared buffers cachedMem: 3955 3926 28 0 55 3459-/+ buffers/cache: 411 3544Swap: 5726 0 5726f
1、手动清理内存和Cache方法
Linux下清理内存和Cache方法 /proc/sys/vm/drop_caches
频繁的文件访问会导致系统的Cache使用量大增
$ free -m
total used free shared buffers cached
Mem: 3955 3926 28 0 55 3459
-/+ buffers/cache: 411 3544
Swap: 5726 0 5726
free内存减少到几十兆,系统运行缓慢
运行sync将dirty的内容写回硬盘
清理内存和Cache方法:
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
2、自动清理内存和Cache方法,使用脚本自动清理
#!/bin/bash
# 清理系统缓存脚本
used=`free -m |awk 'NR==2' |awk '{print $3}'`
free=`free -m |awk 'NR==2' |awk '{print $4}'`
echo "===========================" >>/var/log/mem.log
date >> /var/log/mem.log
echo "Memory usage | [Use: ${used}MB][Free: ${free}MB]" >> /var/log/mem.log
if [ $free -le 500 ];then
sync && echo 1 > /proc/sys/vm/drop_caches
sync && echo 2 > /proc/sys/vm/drop_caches
sync && echo 3 > /proc/sys/vm/drop_caches
echo "OK" >> /var/log/mem.log
else
echo "Not required" >> /var/log/mem.log
fi
更多推荐
所有评论(0)