Home / Linux  / Free up cache and buffers on a Linux system

Free up cache and buffers on a Linux system

swao rhel memory Linux kernel Centos cache

OS having great features in management that system used to clear the of the buffer periodically itself but sometimes system uses so much memory for disk or we want some free memory from volatile storage which is not usable by RAM and even if it is not in used RAM is not in used. Read the data from is faster than using disk of course , It can be possible for some data system not have for that data, so we can flush the buffer or memory .
Here we will see drop clean caches as well as reclaim inodes and dentries memory become free.
Free up the buffers cache :

Some signals in linux kernel parameter will drop various aspects of cached properly.Changing the numeric value in these parameter will free pagecache , inodes and dentries.
These below commands will be run as root user, if you are using linux through sudo user privilege you need to use sudo with some more parameter. Find below for both root user entry as well as sudo user Entry for free cache.

For linux root user

Free pagecache :

# echo 1 > /proc/sys/vm/drop_caches

Free dentries and inodes:

# echo 2 > /proc/sys/vm/drop_caches

Free pagecache, dentries and inodes:

# echo 3 > /proc/sys/vm/drop_caches

For sudo privileged users :

To clear pagecache :

$ sudo sh -c 'echo 1 >/proc/sys/vm/drop_caches'

To clear dentries and inodes:

$ sudo sh -c 'echo 2 >/proc/sys/vm/drop_caches'

To clear pagecache, dentries and inodes:

$ sudo sh -c 'echo 3 >/proc/sys/vm/drop_caches'

How to setup automated clear memory cache through shell script and cron ?

Here we are creating a shell script to automate the free up memory cache. Now create a bash shell
Script file like we are creating file named as freecache.sh and insert below lines into this.

#!/bin/bash  # shell script by www.techtransit.org  , we are using echo 3 which will free pagecache,dentries and inodes.  echo 3 > /proc/sys/vm/drop_caches

Now set the executable permission on the bash shell script file.

# chmod 755 freecache.sh

Let schedule this script on daily basis in cron in after midnight at 1 A.M like below.
Run the crontab –e command like below.

# crontab –e

Insert below line in crontab file.

0  1   *   *   *   freecache.sh

A Linux Geek with Freelance Contributor, Server/ Cloud Administrator having experience in Open Source and Cloud Technologies.

Review overview


Time limit is exhausted. Please reload CAPTCHA.