Created
January 19, 2018 21:38
-
-
Save jermdw/fc9ab0ebd53630b9a1a84f1f3487e083 to your computer and use it in GitHub Desktop.
Linux KSM Init Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # | |
| # Author: Marin Atanasov Nikolov <[email protected]> | |
| # http://dnaeon.github.io/enable-ksm-during-boot-time-on-linux/ | |
| # | |
| ### BEGIN INIT INFO | |
| # Provides: ksm | |
| # Required-Start: | |
| # Required-Stop: | |
| # X-Start-Before: | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: Enable and disable KVM KSM | |
| # Description: Enables and disables the KVM Kernel Samepage Merging | |
| # feature of the kernel | |
| ### END INIT INFO | |
| set -e | |
| . /lib/lsb/init-functions | |
| do_start() { | |
| echo 1 > /sys/kernel/mm/ksm/run | |
| log_success_msg "Enabling Kernel Samepage Merging" | |
| } | |
| do_stop() { | |
| echo 0 > /sys/kernel/mm/ksm/run | |
| log_success_msg "Disabling Kernel Samepage Merging" | |
| } | |
| do_status() { | |
| local ksm_status | |
| ksm_status=$( cat /sys/kernel/mm/ksm/run ) | |
| if [ ${ksm_status} -eq 1 ]; then | |
| log_success_msg "Kernel Samepage Merging is enabled" | |
| else | |
| log_success_msg "Kernel Samepage Merging is disabled" | |
| fi | |
| } | |
| case "${1}" in | |
| start) | |
| do_start | |
| ;; | |
| reset|stop) | |
| do_stop | |
| ;; | |
| status) | |
| do_status | |
| ;; | |
| reload|restart|force-reload) | |
| do_stop | |
| do_start | |
| ;; | |
| *) | |
| log_success_msg "usage: ${0} {start|stop|status|reload|restart|force-reload|reset}" >&2 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment