2009-09-16 09:38:29 +00:00
|
|
|
#!/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
|
|
|
|
#
|
2009-11-03 15:14:32 +00:00
|
|
|
# chkconfig: 345 84 16
|
2009-09-16 09:38:29 +00:00
|
|
|
# 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:
|
2009-11-03 15:14:32 +00:00
|
|
|
# Default-Start: 3 4 5
|
2009-09-16 09:38:29 +00:00
|
|
|
# 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: "
|
2010-03-10 18:09:38 +00:00
|
|
|
if [ -f /sys/kernel/mm/ksm/max_kernel_pages ]; then
|
|
|
|
KSM_MAX_KERNEL_PAGES=${KSM_MAX_KERNEL_PAGES:-`default_max_kernel_pages`}
|
|
|
|
echo $KSM_MAX_KERNEL_PAGES > /sys/kernel/mm/ksm/max_kernel_pages
|
|
|
|
fi
|
2009-09-16 09:38:29 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2009-10-09 14:34:17 +00:00
|
|
|
status() {
|
|
|
|
if [ ! -f /sys/kernel/mm/ksm/run ] ; then
|
|
|
|
echo $"$prog not supported"
|
|
|
|
RETVAL=1
|
|
|
|
else if [ "$(cat /sys/kernel/mm/ksm/run 2>/dev/null)" != "1" ]; then
|
|
|
|
echo $"$prog is not running"
|
|
|
|
RETVAL=1
|
|
|
|
else
|
|
|
|
echo $"$prog is running"
|
|
|
|
RETVAL=0
|
|
|
|
fi; fi
|
|
|
|
}
|
|
|
|
|
2009-09-16 09:38:29 +00:00
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
status)
|
2009-10-09 14:34:17 +00:00
|
|
|
status
|
2009-09-16 09:38:29 +00:00
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
;;
|
2009-09-16 17:31:15 +00:00
|
|
|
condrestart)
|
|
|
|
;;
|
2009-09-16 09:38:29 +00:00
|
|
|
*)
|
2009-09-16 17:31:15 +00:00
|
|
|
echo $"Usage: $prog {start|stop|restart|condrestart|status|help}"
|
2009-09-16 09:38:29 +00:00
|
|
|
RETVAL=3
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $RETVAL
|