| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| . /etc/rc.d/init.d/functions |
| |
| if [ -f /etc/sysconfig/ksm ]; then |
| . /etc/sysconfig/ksm |
| fi |
| |
| prog=ksm |
| RETVAL=0 |
| |
| |
| default_max_kernel_pages () { |
| local total pagesize |
| total=`awk '/^MemTotal:/ {print $2}' /proc/meminfo` |
| pagesize=`getconf PAGESIZE` |
| echo $[total * 1024 / pagesize / 2] |
| } |
| |
| start() { |
| echo -n $"Starting $prog: " |
| KSM_MAX_KERNEL_PAGES=${KSM_MAX_KERNEL_PAGES:-`default_max_kernel_pages`} |
| echo $KSM_MAX_KERNEL_PAGES > /sys/kernel/mm/ksm/max_kernel_pages |
| echo 1 > /sys/kernel/mm/ksm/run |
| RETVAL=$? |
| [ $RETVAL = 0 ] && success $"$prog startup" || failure $"$prog startup" |
| echo |
| return $RETVAL |
| } |
| |
| stop() { |
| echo -n $"Stopping $prog: " |
| echo 0 > /sys/kernel/mm/ksm/run |
| RETVAL=$? |
| [ $RETVAL = 0 ] && success $"$prog shutdown" || failure $"$prog shutdown" |
| echo |
| } |
| |
| case "$1" in |
| start) |
| start |
| ;; |
| stop) |
| stop |
| ;; |
| status) |
| is_run=`cat /sys/kernel/mm/ksm/run` |
| RETVAL=$? |
| if [ $is_run -eq 1 ]; then |
| echo $"$prog is running" |
| else |
| echo $"$prog is not running" |
| fi |
| ;; |
| restart) |
| stop |
| start |
| ;; |
| condrestart) |
| ;; |
| *) |
| echo $"Usage: $prog {start|stop|restart|condrestart|status|help}" |
| RETVAL=3 |
| esac |
| |
| exit $RETVAL |