Clean up memory and Cache method under Linux /proc/sys/vm/drop

  

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

Frequent file access will cause system Cache usage Big increase

$ free -mtotal used free shared buffers cachedMem: 3955 3926 28 0 55 3459-/+ buffers/cache: 411 3544Swap: 5726 0 5726

free memory reduced to tens of megabytes , the system runs slowly

Run sync to write the contents of the dirty to the hard disk $sync

clean the cache$echo 3 > /proc/sys/vm/drop_caches by modifying the proc system's drop_caches

The detailed documentation for drop_caches 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_cachesTo free dentries and inodes:* echo 2 > /proc/sys/vm/drop_cachesTo free pagecache, dentries and inodes:* echo 3 > /proc/sys/vm/drop_cachesAs 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 After adding the following options, the memory will not increase continuously vm.dirty_ratio = 1vm.dirty_background_ratio= 1vm.dirty_writeback_centisecs=2vm.dirty_expire_centisecs=3vm.drop_caches=3vm.swappiness=100vm.vfs_cache_pressure=163vm.overcommit_memory=2vm.lowmem_reserve_ratio=32 32 8kern.maxvnodes=3

The above settings are rude, making cache The effect is basically impossible to play. Need to adjust the machine according to the condition of the machine to find the best compromise.

Copyright © Windows knowledge All Rights Reserved