How to free up buffers and cache on a Linux/Ubuntu system

In this short article, we will see how to empty buffers and cache on a Linux/Ubuntu system.

To free up pagecache, run the command below as root:

echo 1 > /proc/sys/vm/drop_caches.         [Ubuntu clear cache ]

To free up inodes and dentries, issue the command below as root:

echo 2 > /proc/sys/vm/drop_caches

To free up both pagecache, dentries and inodes, execute the command below as root:

echo 3 > /proc/sys/vm/drop_caches

The above commands are executed as root. Using sudo, the syntax will need to be modified slightly as follows :

sudo sh -c ‘echo 1 >/proc/sys/vm/drop_caches’

sudo sh -c ‘echo 2 >/proc/sys/vm/drop_caches’

sudo sh -c ‘echo 3 >/proc/sys/vm/drop_caches’

Using the following chain of commands, will free up the buffers cache :

free && sync && echo 3 > /proc/sys/vm/drop_caches && free [linux clear buffer cache]

Peeking into the contents of the buffers and cache

In order to analyze the contents of the buffers and cache, you can check the page linux-ftools. This is convenient in case you want to see which files are currently being cached.

Read: How to get more storage space on your Android

Using fincore

This tool which is not available in the repo, will help you see what files are being cached within a specific directory.

For instance, you could run the command below :

fincore –pages=false –summarize –only-cached *

For more on fincore, visit this page.

Disable the swap

In order to disable your swap , run the command :

swapoff -a

To see the effects of this, issue the command free beforehand and after the execution.

Read: How to increase swap space in Linux

To re-enable it, just issue the following command:

swapon -a


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

amin nahdy

Amin Nahdy, an aspiring software engineer and a computer geek by nature as well as an avid Ubuntu and open source user. He is interested in information technology especially Linux based ecosystem as well as Windows and MacOS. He loves to share and disseminate knowledge to others in a transparent and responsible way.

Leave a Reply

Close Menu