×

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.

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.ksmConfiguration stanza of the HyperConverged CR.

  • You enable the feature and configure settings by editing the ksmConfiguration stanza.

  • You disable the feature by deleting the ksmConfiguration stanza.

  • You can allow OpenShift Virtualization to enable KSM on only a subset of nodes by adding node selection syntax to the ksmConfiguration.nodeLabelSelector field.

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.

Procedure
  1. From the side menu, click VirtualizationOverview.

  2. Select the Settings tab.

  3. Select the Cluster tab.

  4. Expand Resource management.

  5. 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.

Procedure
  1. Open the HyperConverged CR in your default editor by running the following command:

    $ oc edit hyperconverged kubevirt-hyperconverged -n openshift-cnv
  2. Edit the ksmConfiguration stanza:

    • To enable the KSM activation feature for all nodes, set the nodeLabelSelector value 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 nodeLabelSelector field. 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 ksmConfiguration stanza. For example:

      apiVersion: hco.kubevirt.io/v1beta1
      kind: HyperConverged
      metadata:
        name: kubevirt-hyperconverged
        namespace: openshift-cnv
      spec:
        configuration:
      # ...
  3. Save the file.