Cache cleanup in CentOS (drop_caches)

Source: Internet
Author: User

Cache cleanup in CentOS (drop_caches)

When reading and writing files, the Linux kernel caches the files in the Memory to improve the Read and Write efficiency and speed. This is Cache Memory ).
The Cache Memory is not automatically released even after the program runs. This will cause the program to read and write files frequently, and the available physical memory will be very small.
In fact, this Cache Memory will be automatically released when you need to use the Memory, so you don't have to worry about no Memory available.
You can also manually release the Cache Memory.

Official documentation for clearing cache (drop_caches): http://www.kernel.org/doc/Documentation/sysctl/vm.txt

========================================================== ======================================
Drop_caches

Writing to this will cause the kernel to drop clean caches, as well
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
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 varous 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
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 3) into drop_caches.
========================================================== ======================================
# Cat/proc/sys/vm/drop_caches
0 // The default value is 0; 1: Clear page cache; 2: Clear inode and directory tree cache; 3: Clear all caches
[Root @ bak ~] #Sync // Note: Use the sync command to synchronize data to the disk before clearing the cache
[Root @ bak ~] #Free-m
Total used free shared buffers cached
Mem: 15898 3029 12869 0 191 1064
-/+ Buffers/cache: 1772 14125
Swap: 31999 0 31999
[Root @ bak ~] #Echo 3>/proc/sys/vm/drop_caches
[Root @ bak ~] #Free-m // The cache is obviously reduced
Total used free shared buffers cached
Mem: 15898 1770 14128 0 1 30
-/+ Buffers/cache: 1738 14160
Swap: 31999 0 31999

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.