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
KSM_SLEEP_MSEC=100
  • 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_*
/sys/kernel/mm/ksm/pages_shared:595109
/sys/kernel/mm/ksm/pages_sharing:2529197
/sys/kernel/mm/ksm/pages_to_scan:64
/sys/kernel/mm/ksm/pages_unshared:5129616
/sys/kernel/mm/ksm/pages_volatile:529083

Leave a Reply

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

*

code