Manually clean up memory and Cache method under Linux /proc/sys/vm/drop_caches

Manually clean up memory and Cache method under Linux /proc/sys/vm/drop_caches

Usage principle :

In the Linux system, in order to speed up the reading speed of data, by default, some data will not be directly written to the hard disk, but will be temporarily stored in the memory. If a data is repeatedly written, the speed must be fast, but there are One problem, in case of restart, shutdown, or abnormal power failure, because the data has not been stored in the hard disk, the data update will be abnormal. At this time, you need to command sync to write the data, that is #sync, the data that has not been updated in memory will be written to the hard disk. Of course, under normal circumstances, when the system is shut down, the synchronous detection of the memory data and the hard disk data will be performed automatically to ensure that the hard disk data is up-to-date when the system is shut down.

Instructions:

Frequent file access will lead to a large increase in the system's Cache usage

$ free -g

Run sync to write the dirty contents back to disk
$sync

Clean up the free cache by modifying the drop_caches of the proc system
$echo 3 > /proc/sys/vm/drop_caches

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 notfreeable, the user should run "sync" first in order to make sure allcached objects are freed.
This tunable was added in 2.6.16.


Modify /etc/sysctl.conf and add the following options, the memory will not
continue to increase =163 vm.overcommit_memory=2 vm.lowmem_reserve_ratio=32 32 8 kern.maxvnodes=3







The above settings are relatively rough, so that the role of the cache is basically unable to play. Appropriate adjustments to the condition of the machine are required to find the best compromise.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326535120&siteId=291194637