Difference between revisions of "Kernel drop caches"
Jump to navigation
Jump to search
↑ https://unix.stackexchange.com/questions/87908/how-do-you-empty-the-buffers-and-cache-on-a-linux-system
(8 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | https://www.kernel.org/doc/Documentation/sysctl/vm.txt | ||
+ | # Emptying the buffers cache: <code>[[free -h]] && [[sync]] && echo 3 > [[/proc/sys/vm/drop_caches]] && free -h</code><ref>https://unix.stackexchange.com/questions/87908/how-do-you-empty-the-buffers-and-cache-on-a-linux-system</ref> | ||
− | + | drop_caches | |
− | + | ||
− | + | Writing to this will cause the kernel to drop clean caches, as well as | |
− | + | reclaimable slab objects like dentries and inodes. Once dropped, their | |
+ | memory becomes free. | ||
+ | |||
+ | To free pagecache: | ||
+ | echo 1 > [[/proc/sys/vm/]]drop_caches | ||
+ | To free reclaimable slab objects (includes [[dentries]] and [[inodes]]): | ||
+ | echo 2 > /proc/sys/vm/drop_caches | ||
+ | To free [[slab]] objects and pagecache: | ||
+ | echo 3 > /proc/sys/vm/drop_caches | ||
<pre> | <pre> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
This is a non-destructive operation and will not free any dirty objects. | This is a non-destructive operation and will not free any dirty objects. | ||
To increase the number of objects freed by this operation, the user may run | To increase the number of objects freed by this operation, the user may run | ||
Line 42: | Line 39: | ||
with your system. To disable them, echo 4 (bit 2) into drop_caches. | with your system. To disable them, echo 4 (bit 2) into drop_caches. | ||
</pre> | </pre> | ||
+ | |||
+ | == Related commands == | ||
+ | * Memory: <code>[[sar -r]]</code> | ||
+ | * [[Buffer]] | ||
== See also == | == See also == |
Latest revision as of 10:54, 7 February 2023
https://www.kernel.org/doc/Documentation/sysctl/vm.txt
- Emptying the buffers cache:
free -h && sync && echo 3 > /proc/sys/vm/drop_caches && free -h
[1]
drop_caches Writing to this will cause the kernel to drop clean caches, as well as reclaimable slab objects like dentries and inodes. Once dropped, their memory becomes free. To free pagecache: echo 1 > /proc/sys/vm/drop_caches To free reclaimable slab objects (includes dentries and inodes): echo 2 > /proc/sys/vm/drop_caches To free slab objects and pagecache: echo 3 > /proc/sys/vm/drop_caches
This is a non-destructive operation and will not free any dirty objects. To increase the number of objects freed by this operation, the user may run `sync' prior to writing to /proc/sys/vm/drop_caches. This will minimize the number of dirty objects on the system and create more candidates to be dropped. This file is not a means to control the growth of the various kernel caches (inodes, dentries, pagecache, etc...) These objects are automatically reclaimed by the kernel when memory is needed elsewhere on the system. Use of this file can cause performance problems. Since it discards cached objects, it may cost a significant amount of I/O and CPU to recreate the dropped objects, especially if they were under heavy use. Because of this, use outside of a testing or debugging environment is not recommended. You may see informational messages in your kernel log when this file is used: cat (1234): drop_caches: 3 These are informational only. They do not mean that anything is wrong with your system. To disable them, echo 4 (bit 2) into drop_caches.
Related commands[edit]
See also[edit]
sync
- Memory: memory pages, RAM, virsh Memory Commands, OOM, meminfo,
vmstat
, NAND, DDR,lsmem
,/dev/shm
,/proc/meminfo
,sar -r
, IOMMU,pmem
, Memory management, Garbage collector, THP, Linux Huge Page TLB
Advertising: