Enable and disabling kernel same-page merging

To optimize CPU efficiency of your virtual machines (VMs), you can enable or disable kernel same-page merging (KSM) on the host.

Before you begin

  • Root access to your host system.

About this task

KSM improves memory density by sharing identical memory pages between VMs. Therefore, enabling KSM might improve memory efficiency of your VM deployment. However, enabling KSM also increases CPU utilization, and might negatively affect overall performance depending on the workload.

In RHEL 10, KSM is disabled by default. To enable KSM and test its impact on your VM performance, see the following instructions.

Procedure

  1. Enable KSM:
    Warning

    Enabling KSM increases CPU utilization and affects overall CPU performance.

    1. Install the ksmtuned service:
      # dnf install ksmtuned
    2. Start the service:
      • To enable KSM for a single session, use the systemctl utility to start the ksm and ksmtuned services.
        # systemctl start ksm
        # systemctl start ksmtuned
      • To enable KSM persistently, use the systemctl utility to enable the ksm and ksmtuned services.
        # systemctl enable ksm
        Created symlink /etc/systemd/system/multi-user.target.wants/ksm.service  /usr/lib/systemd/system/ksm.service
        # systemctl enable ksmtuned
        Created symlink /etc/systemd/system/multi-user.target.wants/ksmtuned.service  /usr/lib/systemd/system/ksmtuned.service
  2. Monitor the performance and resource consumption of VMs on your host to evaluate the benefits of activating KSM. Specifically, ensure that the additional CPU usage by KSM does not offset the memory improvements and does not cause additional performance issues. In latency-sensitive workloads, also pay attention to cross-NUMA page merges.
  3. Optional: If KSM has not improved your VM performance, disable it:
    • To disable KSM for a single session, use the systemctl utility to stop ksm and ksmtuned services.
      # systemctl stop ksm
      # systemctl stop ksmtuned
    • To disable KSM persistently, use the systemctl utility to disable ksm and ksmtuned services.
      # systemctl disable ksm
      Removed /etc/systemd/system/multi-user.target.wants/ksm.service.
      # systemctl disable ksmtuned
      Removed /etc/systemd/system/multi-user.target.wants/ksmtuned.service.
      Note

      Memory pages shared between VMs before deactivating KSM remain shared. To stop sharing, delete all the PageKSM pages in the system by using the following command:

      # echo 2 > /sys/kernel/mm/ksm/run

      However, this command increases memory usage, and might cause performance problems on your host or your VMs.