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,不建议经常修改它。

  • 相关阅读:
    程序员的基本修养之二
    jQuery学习之二
    面向对象程序的设计模式
    Mysql的复杂语句
    养成良好的做事风格
    前端模板学习bootstrap
    23. Merge k Sorted Lists
    953. Verifying an Alien Dictionary
    Daily Coding Problem: Problem #541
    396. Rotate Function
  • 原文地址:https://www.cnblogs.com/hellokitty2/p/10088042.html
Copyright © 2011-2022 走看看