前言
本文介绍如何在centos 中清理RAM Memory Cache, Buffer and Swap Space
清理脚本
clearcache.sh
#!/bin/bash
# Note, we are using "echo 3", but it is not recommended in production instead use "echo 1"
su -c "echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'" root
设置定时任务
crontab -e
0 4 * * * root /{path of file}/clearcache.sh
参数
- Clear PageCache only.
sync; echo 1 > /proc/sys/vm/drop_caches
- Clear dentries and inodes.
sync; echo 2 > /proc/sys/vm/drop_caches
- Clear PageCache, dentries and inodes.
sync; echo 3 > /proc/sys/vm/drop_caches
参考文献
http://man.linuxde.net/sync
https://www.tecmint.com/clear-ram-memory-cache-buffer-and-swap-space-on-linux/
网友评论