render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone
Blob Blame History Raw
#!/bin/bash
#
# ksm Kernel Samepage Merging
#
# Author: Dan Kenigsberg <danken@redhat.com>
#
# Copyright 2009 Red Hat, Inc. and/or its affiliates.
# Released under the GPL
#
# chkconfig: - 84 16
# description: The KSM init script starts and stops the ksm kernel thread.
# config: /etc/sysconfig/ksm
#
### BEGIN INIT INFO
# Provides: ksm
# Required-Start:
# Required-Stop:
# Should-Start:
# Short-Description: start and stop ksm
# Description: The KSM init script starts and stops the ksm kernel thread.
### END INIT INFO
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/ksm ]; then
. /etc/sysconfig/ksm
fi
prog=ksm
RETVAL=0
# unless KSM_MAX_KERNEL_PAGES is set, let ksm munch up to half of total memory.
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