LinuxVirtualization

How to oversell resources on KVM nodes with KSM Tuned

Unlike OpenVZ virtualization, KVM is a full virtualization product which means you cannot oversell KVM some resources as standard. KVM nodes can oversell on CPU resources using KSM Tuned but you can’t oversell the space or the memory usage. This can cause issues with your available resources. For example, if you create a virtual server with 100GB of space and 10GB of RAM. You will immediately notice 100GB of space is lost and 10GB of RAM is also lost. This is quite wasteful because even though the new server will not be using 100GB of space or, anywhere near 10GB of ram. Those resources are no longer available for you to use.

Oversell Resources on KVM Nodes

Firstly, before we proceed you cannot oversell KVM space on KVM nodes, it’s just not possible. However, you can oversell memory by using a little program called KSM (kernel same-page merging). KSM was originally developed by Red Hat and it’s been included since Kernel version 2.6.32. You can save between 30% to 60% of your memory resources by activating KSM. After an hour look at your resource usage. You should see a vast improvement in the resources that you have available to use.

Install KSM Tuned

To oversell resources on KSM nodes install KSM Tuned. login to the host node as the root user and issue the below command to start KSM. Note, this should also start the ksmtuned service.

CentOS / AlmaLinux / RockyLinux 

yum install ksm
systemctl start ksm

Ubuntu / Debian

apt install ksmtuned
systemctl start ksmtuned

Ensure KSM is running by issuing the status commands

CentOS / AlmaLinux / RockyLinux

systemctl status ksm
systemctl status ksmtuned

Ubuntu / Debian

systemctl start ksmtuned

To automatically start KSM on boot turn it on using the chkconfig script or systemctl

CentOS / AlmaLinux / RockyLinux

systemctl enable ksm

Ubuntu / Debian

systemctl enable ksmtuned

You can use other switches with this script. Just swap start for the one required.

start
stop
restart
force-reload
condrestart
try-restart
status
retune
help

Extreme care should be taken when using KSM. If you overcommit too much of your resources your VPS Servers and the host will suffer problems. Only use KSM if you need it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button