Drop caches

From Leo's Notes
Revision as of 03:58, 14 March 2022 by Leo (talk | contribs) (Created page with "In Linux since 2.6.16, you can drop caches to clear out kernel memory that's used by page caches and/or inode and dentry caches. To free pagecache: {{highlight|lang=terminal|code= # echo 1 > /proc/sys/vm/drop_caches }} To free dentries and inodes: {{highlight|lang=terminal|code= # echo 2 > /proc/sys/vm/drop_caches }} To free pagecache, dentries and inodes: {{highlight|lang=terminal|code= echo 3 > /proc/sys/vm/drop_caches }} On some systems especially with low memory,...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 14 March 2022, at 03:58.

In Linux since 2.6.16, you can drop caches to clear out kernel memory that's used by page caches and/or inode and dentry caches.

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

On some systems especially with low memory, you may want to run this periodically to prevent the kernel memory from fragmenting. You may wish to add a cronjob that does this:

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