Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

How to clear or drop the cache buffer pages from Linux memory

Date: 2011-01-02 00:00:00 -0400

Introduction

Cache in Linux memory is where the Kernel stores the information it may need later, as memory is incredible faster than disk, it is great that the Linux Kernel takes care about that.

Anyway you can also manipulate how the cache behaves, there usually no need to do that, as Linux Operating system is very efficient in managing your computer memory, and will automatically free the RAM and drop the cache if some application needs memory.

Let’s see how to force Linux to drop the cache from memory.

drop_caches

Since Kernel 2.6.16, you can control how cache behaves, there are four possible “positions” for the switch.

0 -> Will give the Kernel full control to the cache memory 1 -> Will free the page cache 2 -> Will free dentries and inodes 3 -> Will free dentries and inodes as well as page cache

So, just enter those values to the file /proc/sys/vm/drop_caches, with echo, and as root:

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

or

sync; echo 1 > /proc/sys/vm/drop_caches

or

sync; echo 2 > /proc/sys/vm/drop_caches

or

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

You may want to read a little bit more about The buffer cache

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.