5.2. Tuning
the Page Cache
Page
Cache is a disk cache which holds data of files and executable programs, for
example pages with actual contents of files or block devices. Page Cache (disk
cache) is used to reduce the number of disk reads. To control the percentage of
total memory used for page cache in Red Hat Enterprise Linux 3, the following
kernel parameter can be changed:
# cat /proc/sys/vm/pagecache
1 15 30
The
above three values are usually good for database systems. It is not recommended
to set the third value very high, around 100, as it used to be with older Red
Hat Enterprise Linux 3 kernels. This can cause significant performance problems
for database systems. If you upgrade to a newer kernel like 2.4.21-37
,
then these values will automatically change to "1
15 30
" unless its set to different values in /etc/sysctl.conf
.
For information on tuning the pagecache
kernel parameter, see Understanding
Virtual Memory. Note this kernel parameter does not exist in Red Hat Enterprise
Linux 4.
The pagecache
parameters can be changed in the proc
file system without reboot:
# echo "1 15 30" > /proc/sys/vm/pagecache
Alternatively,
you can use sysctl(8)
to change it:
# sysctl -w vm.pagecache="1 15 30"
To
make the change permanent, add the following line to the file /etc/sysctl.conf
.
This file is used during the boot process.
# echo "vm.pagecache=1 15 30" >> /etc/sysctl.conf
With
Red Hat Enterprise Linux 4 and 5, the pagecache
is dynamically adjusted. You can adjust
the minimum free pages using the following command:
# echo 1024 > /proc/sys/vm/min_free_kbytes
To
make the change permanent, add the following line to the file /etc/sysctl.conf
:
# echo vm.min_free_kbytes=1024 >> /etc/sysctl.conf
The pagecache
pages can be reclaimed by adjusting
the swappiness
percentage as described in the next
section.
CentOS
6.X
设置:
echo vm.min_free_kbytes=20480000 >> /etc/sysctl.conf
查看:
#cat /proc/sys/vm/min_free_kbytes
强制回收缓存脚本:
cfree.sh
#! /bin/bash
freeMem=`free -g | grep 'Mem' | awk '{print $4}'`
if [ $freeMem -lt 30 ];
then
echo "1Free mem:"${freeMem}"G"
sync
echo 3 > /proc/sys/vm/drop_caches
echo "2Free mem:"${freeMem}"G"
fi