Drop caches: Difference between revisions

From Leo's Notes
This page was last edited on 14 March 2022, at 04:02.
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,..."
 
No edit summary
Line 1: Line 1:
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.
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.
 
{| class="wikitable"
To free pagecache:
!
{{highlight|lang=terminal|code=
!
|-
|To free page cache:
|{{highlight|lang=terminal|code=
# echo 1 > /proc/sys/vm/drop_caches
# echo 1 > /proc/sys/vm/drop_caches
}}
}}
To free dentries and inodes:
|-
 
|To free dentries and inodes:
{{highlight|lang=terminal|code=
|{{highlight|lang=terminal|code=
# echo 2 > /proc/sys/vm/drop_caches
# echo 2 > /proc/sys/vm/drop_caches
}}
}}
|-
|To free
|{{highlight|lang=terminal|code=
echo 3 > /proc/sys/vm/drop_caches
}}
|}
To free pagecache, dentries and inodes:
To free pagecache, dentries and inodes:


{{highlight|lang=terminal|code=
Drop caches does not drop dirty pages.  To free even more memory, you can flush these dirty pages with <code>sync</code> first.
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:
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:

Revision as of 04:02, 14 March 2022

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 page cache:
# echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
# echo 2 > /proc/sys/vm/drop_caches
To free
echo 3 > /proc/sys/vm/drop_caches


To free pagecache, dentries and inodes:

Drop caches does not drop dirty pages. To free even more memory, you can flush these dirty pages with sync first.

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