Blame ksm.init

Mark McLoughlin b11220
#!/bin/bash
Mark McLoughlin b11220
#
Mark McLoughlin b11220
# ksm          Kernel Samepage Merging
Mark McLoughlin b11220
#
Mark McLoughlin b11220
# Author:      Dan Kenigsberg <danken@redhat.com>
Mark McLoughlin b11220
#
Mark McLoughlin b11220
# Copyright 2009 Red Hat, Inc. and/or its affiliates.
Mark McLoughlin b11220
# Released under the GPL
Mark McLoughlin b11220
#
Mark McLoughlin b11220
# chkconfig: - 84 16
Mark McLoughlin b11220
# description: The KSM init script starts and stops the ksm kernel thread.
Mark McLoughlin b11220
# config: /etc/sysconfig/ksm
Mark McLoughlin b11220
#
Mark McLoughlin b11220
### BEGIN INIT INFO
Mark McLoughlin b11220
# Provides: ksm
Mark McLoughlin b11220
# Required-Start:
Mark McLoughlin b11220
# Required-Stop:
Mark McLoughlin b11220
# Should-Start:
Mark McLoughlin b11220
# Short-Description: start and stop ksm
Mark McLoughlin b11220
# Description: The KSM init script starts and stops the ksm kernel thread.
Mark McLoughlin b11220
### END INIT INFO
Mark McLoughlin b11220
Mark McLoughlin b11220
. /etc/rc.d/init.d/functions
Mark McLoughlin b11220
Mark McLoughlin b11220
if [ -f /etc/sysconfig/ksm ]; then
Mark McLoughlin b11220
    . /etc/sysconfig/ksm
Mark McLoughlin b11220
fi
Mark McLoughlin b11220
Mark McLoughlin b11220
prog=ksm
Mark McLoughlin b11220
RETVAL=0
Mark McLoughlin b11220
Mark McLoughlin b11220
# unless KSM_MAX_KERNEL_PAGES is set, let ksm munch up to half of total memory.
Mark McLoughlin b11220
default_max_kernel_pages () {
Mark McLoughlin b11220
    local total pagesize
Mark McLoughlin b11220
    total=`awk '/^MemTotal:/ {print $2}' /proc/meminfo`
Mark McLoughlin b11220
    pagesize=`getconf PAGESIZE`
Mark McLoughlin b11220
    echo $[total * 1024 / pagesize / 2]
Mark McLoughlin b11220
}
Mark McLoughlin b11220
Mark McLoughlin b11220
start() {
Mark McLoughlin b11220
    echo -n $"Starting $prog: "
Mark McLoughlin b11220
    KSM_MAX_KERNEL_PAGES=${KSM_MAX_KERNEL_PAGES:-`default_max_kernel_pages`}
Mark McLoughlin b11220
    echo $KSM_MAX_KERNEL_PAGES > /sys/kernel/mm/ksm/max_kernel_pages
Mark McLoughlin b11220
    echo 1 > /sys/kernel/mm/ksm/run
Mark McLoughlin b11220
    RETVAL=$?
Mark McLoughlin b11220
    [ $RETVAL = 0 ] && success $"$prog startup" || failure $"$prog startup"
Mark McLoughlin b11220
    echo
Mark McLoughlin b11220
    return $RETVAL
Mark McLoughlin b11220
}
Mark McLoughlin b11220
Mark McLoughlin b11220
stop() {
Mark McLoughlin b11220
    echo -n $"Stopping $prog: "
Mark McLoughlin b11220
    echo 0 > /sys/kernel/mm/ksm/run
Mark McLoughlin b11220
    RETVAL=$?
Mark McLoughlin b11220
    [ $RETVAL = 0 ] && success $"$prog shutdown" || failure $"$prog shutdown"
Mark McLoughlin b11220
    echo
Mark McLoughlin b11220
}
Mark McLoughlin b11220
Mark McLoughlin b11220
case "$1" in
Mark McLoughlin b11220
  start)
Mark McLoughlin b11220
	start
Mark McLoughlin b11220
	;;
Mark McLoughlin b11220
  stop)
Mark McLoughlin b11220
	stop
Mark McLoughlin b11220
	;;
Mark McLoughlin b11220
  status)
Mark McLoughlin b11220
        is_run=`cat /sys/kernel/mm/ksm/run`
Mark McLoughlin b11220
	RETVAL=$?
Mark McLoughlin b11220
        if [ $is_run -eq 1 ]; then
Mark McLoughlin b11220
            echo $"$prog is running"
Mark McLoughlin b11220
        else
Mark McLoughlin b11220
            echo $"$prog is not running"
Mark McLoughlin b11220
        fi
Mark McLoughlin b11220
	;;
Mark McLoughlin b11220
  restart)
Mark McLoughlin b11220
	stop
Mark McLoughlin b11220
	start
Mark McLoughlin b11220
	;;
Mark McLoughlin b11220
  signal)
Mark McLoughlin b11220
	signal
Mark McLoughlin b11220
	;;
Mark McLoughlin b11220
  *)
Mark McLoughlin b11220
	echo $"Usage: $prog {start|stop|restart|status|help}"
Mark McLoughlin b11220
	RETVAL=3
Mark McLoughlin b11220
esac
Mark McLoughlin b11220
Mark McLoughlin b11220
exit $RETVAL