×

OKD 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 OKD Virtualization to activate KSM.

About using OKD Virtualization to activate KSM

You can configure OKD 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 OKD 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 OKD 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 OKD Virtualization, an administrator can still enable KSM on nodes that support it.

KSM node labels

OKD 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 OKD 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 OKD 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 OKD Virtualization to activate kernel samepage merging (KSM) on all nodes in your cluster by using the OKD 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 OKD Virtualization’s kernel samepage merging (KSM) activation feature by editing the HyperConverged custom resource (CR). Use this method if you want OKD 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 kubevirt-hyperconverged
  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: kubevirt-hyperconverged
      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 OKD Virtualization to enable KSM. For example, the following configuration allows OKD 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: kubevirt-hyperconverged
      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: kubevirt-hyperconverged
      spec:
        configuration:
      # ...
  3. Save the file.