Activating kernel samepage merging (KSM)
OpenShift Virtualization can activate kernel samepage merging (KSM) when nodes are overloaded. KSM deduplicates identical data found in the memory pages of virtual machines (VMs). If you have very similar VMs, KSM can make it possible to schedule more VMs on a single node.
Important
You must only use KSM with trusted workloads.
Prerequisites
-
Ensure that an administrator has configured KSM support on any nodes where you want OpenShift Virtualization to activate KSM.
About using OpenShift Virtualization to activate KSM
You can configure OpenShift Virtualization to activate kernel samepage merging (KSM) when nodes experience memory overload.
Configuration methods
You can enable or disable the KSM activation feature for all nodes by using the OpenShift Container Platform web console or by editing the HyperConverged custom resource (CR). The HyperConverged CR supports more granular configuration.
- CR configuration
-
You can configure the KSM activation feature by editing the
spec.configuration.ksmConfigurationstanza of theHyperConvergedCR.-
You enable the feature and configure settings by editing the
ksmConfigurationstanza. -
You disable the feature by deleting the
ksmConfigurationstanza. -
You can allow OpenShift Virtualization to enable KSM on only a subset of nodes by adding node selection syntax to the
ksmConfiguration.nodeLabelSelectorfield.
Note
Even if the KSM activation feature is disabled in OpenShift Virtualization, an administrator can still enable KSM on nodes that support it.
-
KSM node labels
OpenShift Virtualization identifies nodes that are configured to support KSM and applies the following node labels:
kubevirt.io/ksm-handler-managed: "false"-
This label is set to
"true"when OpenShift Virtualization activates KSM on a node that is experiencing memory overload. This label is not set to"true"if an administrator activates KSM. kubevirt.io/ksm-enabled: "false"-
This label is set to
"true"when KSM is activated on a node, even if OpenShift Virtualization did not activate KSM.
These labels are not applied to nodes that do not support KSM.
Configuring KSM activation by using the web console
You can allow OpenShift Virtualization to activate kernel samepage merging (KSM) on all nodes in your cluster by using the OpenShift Container Platform web console.
-
From the side menu, click Virtualization → Overview.
-
Select the Settings tab.
-
Select the Cluster tab.
-
Expand Resource management.
-
Enable or disable the feature for all nodes:
-
Set Kernel Samepage Merging (KSM) to on.
-
Set Kernel Samepage Merging (KSM) to off.
-
Configuring KSM activation by using the CLI
You can enable or disable OpenShift Virtualization’s kernel samepage merging (KSM) activation feature by editing the HyperConverged custom resource (CR). Use this method if you want OpenShift Virtualization to activate KSM on only a subset of nodes.
-
You have installed the OpenShift CLI (
oc).
-
Open the
HyperConvergedCR in your default editor by running the following command:$ oc edit hyperconverged kubevirt-hyperconverged -n openshift-cnv -
Edit the
ksmConfigurationstanza:-
To enable the KSM activation feature for all nodes, set the
nodeLabelSelectorvalue to{}. For example:apiVersion: hco.kubevirt.io/v1beta1 kind: HyperConverged metadata: name: kubevirt-hyperconverged namespace: openshift-cnv spec: configuration: ksmConfiguration: nodeLabelSelector: {} # ... -
To enable the KSM activation feature on a subset of nodes, edit the
nodeLabelSelectorfield. Add syntax that matches the nodes where you want OpenShift Virtualization to enable KSM. For example, the following configuration allows OpenShift Virtualization to enable KSM on nodes where both<first_example_key>and<second_example_key>are set to"true":apiVersion: hco.kubevirt.io/v1beta1 kind: HyperConverged metadata: name: kubevirt-hyperconverged namespace: openshift-cnv spec: configuration: ksmConfiguration: nodeLabelSelector: matchLabels: <first_example_key>: "true" <second_example_key>: "true" # ... -
To disable the KSM activation feature, delete the
ksmConfigurationstanza. For example:apiVersion: hco.kubevirt.io/v1beta1 kind: HyperConverged metadata: name: kubevirt-hyperconverged namespace: openshift-cnv spec: configuration: # ...
-
-
Save the file.
Additional resources
-
Managing kernel samepage merging in the Red Hat Enterprise Linux (RHEL) documentation