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
#
Justin M. Forbes 8e8b4c
# chkconfig: 345 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:
Justin M. Forbes 8e8b4c
# Default-Start: 3 4 5
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: "
Justin M. Forbes 563054
    if [ -f /sys/kernel/mm/ksm/max_kernel_pages ]; then
Justin M. Forbes 563054
        KSM_MAX_KERNEL_PAGES=${KSM_MAX_KERNEL_PAGES:-`default_max_kernel_pages`}
Justin M. Forbes 563054
        echo $KSM_MAX_KERNEL_PAGES > /sys/kernel/mm/ksm/max_kernel_pages
Justin M. Forbes 563054
    fi
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 6d739f
status() {
Mark McLoughlin 6d739f
    if [ ! -f /sys/kernel/mm/ksm/run ] ; then
Mark McLoughlin 6d739f
        echo $"$prog not supported"
Mark McLoughlin 6d739f
        RETVAL=1
Mark McLoughlin 6d739f
    else if [ "$(cat /sys/kernel/mm/ksm/run 2>/dev/null)" != "1" ]; then
Mark McLoughlin 6d739f
        echo $"$prog is not running"
Mark McLoughlin 6d739f
        RETVAL=1
Mark McLoughlin 6d739f
    else
Mark McLoughlin 6d739f
        echo $"$prog is running"
Mark McLoughlin 6d739f
        RETVAL=0
Mark McLoughlin 6d739f
    fi; fi
Mark McLoughlin 6d739f
}
Mark McLoughlin 6d739f
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 6d739f
        status
Mark McLoughlin b11220
	;;
Mark McLoughlin b11220
  restart)
Mark McLoughlin b11220
	stop
Mark McLoughlin b11220
	start
Mark McLoughlin b11220
	;;
Mark McLoughlin cd8d5c
  condrestart)
Mark McLoughlin cd8d5c
        ;;
Mark McLoughlin b11220
  *)
Mark McLoughlin cd8d5c
	echo $"Usage: $prog {start|stop|restart|condrestart|status|help}"
Mark McLoughlin b11220
	RETVAL=3
Mark McLoughlin b11220
esac
Mark McLoughlin b11220
Mark McLoughlin b11220
exit $RETVAL