zoukankan      html  css  js  c++  java
  • /proc/sys/vm/drop_caches 清理缓存

    1. 使用方法

    /proc/sys/vm/drop_caches默认是0

    # echo 1 > /proc/sys/vm/drop_caches; free pagecache, use
    # echo 2 > /proc/sys/vm/drop_caches; free dentries and inodes
    # echo 3 > /proc/sys/vm/drop_caches; free pagecache, dentries and inodes

    注意:使用之前需要先sync,将缓存刷到磁盘中。

    2. 实验

    单位:MB
    
    # free -m
                  total        used        free      shared  buff/cache   available
    Mem:           1825         381        1363           8          79        1413
    Swap:             0           0           0
    # cp /etc/* /mytest/
    # free -m
                  total        used        free      shared  buff/cache   available
    Mem:           1825         382        1341           8         101        1412
    Swap:             0           0           0
    
    过一段时间:
    
    # free -m
                  total        used        free      shared  buff/cache   available
    Mem:           1825         382        1341           8         101        1412
    Swap:             0
    
    # cat /proc/sys/vm/drop_caches
    0
    
    # sync
    
    # echo 3 > /proc/sys/vm/drop_caches
    # free -m
                  total        used        free      shared  buff/cache   available
    Mem:           1825         382        1405           8          37        1413
    Swap:  

    3. 写个脚本做这个事情

    # cat cleanup_cache.sh 
    #!/bin/sh
    # drop_caches for every 5 mins
    
    drop_caches() {
        echo "Drop caches."
        sync
        echo 3 > /proc/sys/vm/drop_caches &
        return 0
    }
    
    while true; do
        sleep 300
        drop_caches
    done
    
    exit 0

    4. 结论

    Linux内核默认保持drop_cache的值是0,不建议经常修改它。

  • 相关阅读:
    java学习笔记(2)
    java学习笔记(1)
    python3自用utils(备忘录)
    关于ubuntu环境的一切
    vim中F5编译运行代码
    kafka入门教程
    python中datetime的常用功能
    Hbase实战教程(转)
    根据时间戳(毫秒)计算年龄
    如何在Debian 10上安装Python 3.8
  • 原文地址:https://www.cnblogs.com/hellokitty2/p/10088042.html
Copyright © 2011-2022 走看看