Thursday, July 12, 2012

To clear cache in RedHat /CentOS (Linux)

You can directly clear caches (pagecache, dentries and inodes) by /proc:
To free pagecache:
# sync && echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
# sync && echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
# sync && echo 3 > /proc/sys/vm/drop_caches

The “sync” command at the beginning will let us be sure that all cached objects are freed.
It is recommended that sync be run prior to passing the values to /proc/sys/vm/drop_caches.
Enabling drop_caches can cause deadlock if the system is under heavy memory and I/O load.
It is not recommended to use this feature on system experiencing heavy load.



To reduce inode/dentry time in the cache: /proc/sys/vm/vfs_cache_pressure

Controls the tendency of the kernel to reclaim the memory which is used for caching of directory and inode objects.

At the default value of vfs_cache_pressure=100 the kernel will attempt to reclaim dentries and inodes at a "fair" rate with respect to pagecache and swapcache reclaim.  Decreasing vfs_cache_pressure causes the kernel to prefer to retain dentry and inode caches. When vfs_cache_pressure=0, the kernel will never reclaim dentries and inodes due to memory pressure and this can easily lead to out-of-memory conditions.

Increasing vfs_cache_pressure beyond 100 causes the kernel to prefer to reclaim dentries and inodes.

You can change value of vfs_cache_pressure by making entry into sysctl.conf file.

# sysctl –a | grep vfs_cache_pressure
vfs_cache_pressure beyond = 1000

No comments:

Post a Comment