Enabling KSM

Using Kernel same-page merging can greatly reduce the amount of memory used on a Linux system, especially when the machine is used as a VM hypervisor. To enable KSM you can follow the steps below.
  • Optional, adjust the frequency in which the KSM service scans for duplicate memory pages
# grep SLEEP /etc/ksmtuned.conf
  • Enable and start the ksm-tuned and ksmservices:
# systemctl enable --now ksm ksmtuned
  • Force KSM to run now or wait for the service to do it on its own:
# echo 1 >/sys/kernel/mm/ksm/run
  • Once the scan is complete you should start seeing the number of shared memory pages increase and the amount of used memory reported by free decrease:
# grep -H . /sys/kernel/mm/ksm/pages_*

Leave a Reply

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