drop_caches

Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.

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

As this is a non-destructive operation, and dirty objects are not freeable, the user should run "sync" first in order to make sure all cached objects are freed.

This tunable was added in 2.6.16.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Proposed addition

I'd suggest adding the following to the second last sentence about 'sync': "...in order to make sure all cached objects are freed". Just to make it clear why the user 'should' run sync.

freeing cache

This is needed if Linux is aggressively swap thrashing, which normally does not occur. Also syncing and freeing cache will not help too much, as the root of the issue is something else. let linux manage memory in its own fashion, u try to compile programs from vanilla source with optimization flags suitable for your machine architecture.

drop_caches vs swappiness

You're right, but this tunable was never supposed to be used on production systems as an additional optimization, but rather as a tool for people doing various benchmarks and tests.

Linux kernel is really doing a good job managing memory, but if you prefer to push it in specific direction, there's another tunable with which you can achieve the desired effect: /proc/sys/vm/swappiness