ZZ How to Flush Memory Cache on Linux Server

http://tecadmin.net/flush-memory-cache-on-linux-server/#


Many times systems faced low memory issues of Linux systems running a while. The reason is that Linux uses so much memory for disk cache is because the RAM is wasted, if it isn’t used. Cache is used to keep data to use frequently by operating system. Reading data from cache if 1000’s time faster than reading data from hard drive.
It’s good for os to get data from cache in memory. But if any data not found in the cache, it reads from hard disk. So it’s no problem to flush cache memory. This article has details about how to Flush Memory Cache on Linux Server.

Clear Linux Buffer Cache:

There are three options available to flush cache of Linux memory. Use one of below as per your requirements.

  • Free pagecache, dentries and inodes in cache memory
    # sync; echo 3 > /proc/sys/vm/drop_caches
    
  • Free dentries and inodes use following command
    # sync; echo 2 > /proc/sys/vm/drop_caches
    
  • Free pagecache only use following command
    # sync; echo 1 > /proc/sys/vm/drop_caches
    
Schedule Cron to Flush Cache Regularly

Its a good idea to schedule following in crontab to automatically flush cache on regular interval.

# crontab -l

0 * * *  * sync; echo 3 > /proc/sys/vm/drop_caches

The above cron will execute on every hour and flushes the cached memory on system.

Find Cache Memory uses in Linux

Use free command to find out cache memory uses by Linux system. Output of free command is like below

# free -m

Sample Output

             total       used       free     shared    buffers     cached
Mem:           992        406        586          0        155        134
-/+ buffers/cache:        116        876
Swap:         2015          0       2015

Last column is showing cached memory ( 134 MB) by system. -m option is used for showing memory details in MB’s.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值