vineri, 3 iunie 2011

The myth of drop_caches

I will try to clarify the myth about drop_caches.

This along with other settings can be made in the folder /proc/sys/vm/ .

First, the files in this directory can be used to tune the operation
of the virtual memory (VM) subsystem of the Linux kernel and also to
writeout of dirty data to disk.

About drop_caches we can say that is only one of the options and not only make
causes the kernel to drop clean caches, and dentries inodes from memory,
the result causing that memory to become free.

We have three basic options :

  • to free pagecache: echo 1 > /proc/sys/vm/drop_caches
  • to free dentries and inodes: echo 2 > /proc/sys/vm/drop_caches
  • to free pagecache, dentries and inodes: echo 3 > /proc/sys/vm/drop_caches

Note that user should run sync first.

What happens then?

The answer is also simple and clear.

If you drop the cache than the CPU load go up.This happen because the cache is gone.

Also available RAM goes up, because the cache is empty.

Logical , the performance will suffer because you are not taking advantage of the cache.

Then over time, the caches will fill and this is a good thing, if you don't instruct Linux to drop the caches.

In reality dropping caches has little positive effect on performance, but in fact, it tends to have a negative effect in long term.

I hope I have correctly understood and explained, so if you think it is not, I wait your feedback.

4 comentarii:

Spider spunea...

There are certain cases where dropping your cache may well be very pertinent:
a) Any kind of benchmarking where you want to measure disk access. (or filesystem access)

b) After "large" jobs on files, kernel compile, openwrt-rebuild and such.

in the B case, the eviction will happen eventually no matter what, however manually giving the order may be a good hint for the system.

However, those are really special cases, and mostly, you should let the cache be, cache.

Baban Gaigole spunea...

clear explanation

jw spunea...
Acest comentariu a fost eliminat de autor.
Adi Riswan spunea...

What about echo 0 > /proc/sys/vm/drop_caches ?

i used to use the command in my cron job for refreshen up my centos's cache once a days :

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

and can u explain about "to have a negative effect in long term."

thank you, great post btw

Trimiteți un comentariu