在Redhat RHEL 6,有一个功能,就是内存合并, 简单说,就是把相同的内存合并,这样可以让你的系统跑更多的虚拟机.不过肯定也会造成性能的影响.
默认这个功能是开启的.如何关闭, 什么时候关闭. 开启的时候,有什么地方可以优化.
看原文吧,还是有收获的.How to improve KVM performance by adjusting KSM
While the kernel-based virtual machine (KVM) is designed to self-optimize, there are a few parameters that can be adjusted to make a KVM host perform better. The most important of these is kernel samepage merging (KSM), a feature that allows the kernel to handle memory more efficiently. KSM allows the Linux kernel to recognize memory pages that contain the same content, then it can merge these memory pages, consolidating the data to one location to be referred to multiple times.
If KVM is used on a host, typically several guest operating systems (OSes) are activated and often these are running the same OS, which means that a huge amount of kernel pages are loaded multiple times. By applying KSM, more virtual machines (VMs) can be started using same amount of memory. In fact, KSM allows over-committing of VMs. But, there is a performance penalty for using KSM. In average environments the performance price is about 10%, which is a reason to turn KSM off in some environments.
In Red Hat Enterprise Linux 6 and Fedora 14, KSM is switched on by default. It is implemented by two services that are started automatically at system initialization: ksmd and ksmtuned. Administrators should judge their environment and determine whether to keep KSM on or turn it off.
Determining whether to use KSM, or turn it off
If the purpose is to run as many VMs as possible, and performance is not an issue, KSM should be kept running. For example, it allows running 40 VMs on a host normally capable of running 30 VMs, which means maximum hardware usage efficiency. But, if a server is running with a relatively small amount of VMs and performance is an issue, KSM should be turned off.
The best choice for any system will depend on the memory calculation made while creating the virtual environment. If there is enough physical RAM in the virtualization host to meet the memory needs of the VMs without KSM, it is better to switch it off. Use chkconfig ksmd off, chkconfig ksmtuned off, service ksmd off and service ksmtuned off to switch off all parts of KSM. But if a host is tight on memory, it’s better to keep it on.
Tuning KSM for best performance
When using KSM, some of its parameters can be tuned for best performance. They are located in a small configuration file named /etc/ksmtuned.conf:
# Configuration file for ksmtuned. # How long ksmtuned should sleep between tuning adjustments # KSM_MONITOR_INTERVAL=60 # Millisecond sleep between ksm scans for 16Gb server. # Smaller servers sleep more, bigger sleep less. # KSM_SLEEP_MSEC=10 # KSM_NPAGES_BOOST=300 # KSM_NPAGES_DECAY=-50 # KSM_NPAGES_MIN=64 # KSM_NPAGES_MAX=1250 # KSM_THRES_COEF=20 # KSM_THRES_CONST=2048 # uncomment the following if you want ksmtuned debug info # LOGFILE=/var/log/ksmtuned # DEBUG=1
The most important parameters in the configuration file is KSM_SLEEP_MSEC. The default value that is used on Fedora 14 is set for large servers. When running a few VMs on a host while using KSM, it’s better to give the host a higher sleep time. For example, try KSM_SLEEP_MSEC=50 to test the effect on the VMs.