Article Title: how to clean up memory and Cache in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Frequent file access will increase the system Cache usage.
$ Free-m
Total used free shared buffers cached
Mem: 3955 3926 28 0 55 3459
-/+ Buffers/cache: 411 3544
Swap: 5726 0 5726
The free memory is reduced to dozens of megabytes, and the system runs slowly.
Run sync to write dirty content back to the hard disk
$ Sync
Clear free cache by modifying drop_caches of proc System
$ Echo 3>/proc/sys/vm/drop_caches
Drop_caches detailed documentation is as follows:
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 shoshould run "sync" first in order to make sure allcached objects are freed.
This tunable was added in 2.6.16.
After you add the following options to/etc/sysctl. conf, the memory will not continue to increase.
Vm. dirty_ratio = 1
Vm. dirty_background_ratio = 1
Vm. dirty_writeback_centisecs = 2
Vm. dirty_expire_centisecs = 3
Vm. drop_caches = 3
Vm. swappiness = 100
Vm. vfs_cache_pressure = 163
Vm. overcommit_memory = 2
Vm. lowmem_reserve_ratio = 32 32 8
Kern. maxvnodes = 3
The above settings are rough, so that the role of the cache is basically not available. You need to make appropriate adjustments based on the machine's conditions to find the best compromise.
Reprinted from: http://bbs.unixall.com/thread-1012-1-1.html