Created
November 19, 2010 08:42
-
-
Save keymon/706261 to your computer and use it in GitHub Desktop.
# :Author: Hector Rivas Gandara
#
# Based on comments in # - http://www.webupd8.org/2010/11/alternative-to-200-lines-kernel-patch.html
# - http://lkml.org/lkml/2010/11/16/330
#
# This script enables the Lennart Poettering cgroup alternative to #
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# cgroup-ctl.sh | |
# | |
# :Author: Hector Rivas Gandara | |
# | |
# Based on comments in | |
# - http://www.webupd8.org/2010/11/alternative-to-200-lines-kernel-patch.html | |
# - http://lkml.org/lkml/2010/11/16/330 | |
# | |
# This script enables the Lennart Poettering cgroup alternative to | |
# increase desktop responsiness. | |
# | |
# Copy it to /usr/local/bin. | |
# You can add it to your rc.local (as root) | |
# | |
# echo "/usr/local/bin/cgroup-ctl.sh init" >> /etc/rc.local | |
# chmod +x /etc/rc.local | |
# | |
# You can add it to your bashrc for interactive console sessions or | |
# to the /etc/rc.local to use it globally | |
# | |
# | |
REAL_SCRIPT_PATH=$(cd $(dirname $0); pwd)/$(basename $0) | |
# Change as needed. It is said that Ubuntu uses /dev (unconfirmed by me) | |
CGROUP_CPU_PATH=/dev/cgroup/cpu | |
#CGROUP_CPU_PATH=/sys/fs/cgroup/cpu | |
print_help() { | |
cat <<EOF | |
Usage: | |
$0 (setup|release|init [pid]) | |
setup: Initializes cgroup. | |
release: Called to release the resource. | |
init: Called to enable it for actual process or to given pid | |
EOF | |
} | |
case $1 in | |
setup) | |
mkdir -p $CGROUP_CPU_PATH | |
mount -t cgroup cgroup $CGROUP_CPU_PATH -o cpu | |
mkdir -p -m 0777 $CGROUP_CPU_PATH/user | |
echo "1" > $CGROUP_CPU_PATH/user/notify_on_release | |
echo "$REAL_SCRIPT_PATH release" > $CGROUP_CPU_PATH/release_agent | |
;; | |
release) | |
rm -rf $CGROUP_CPU_PATH/$1 | |
;; | |
init) | |
[ ! -z "$2" ] && PID=$2 || PID=$(ps -H h -o ppid -p $$ | tr -d ' ') | |
if ! ps -p $PID > /dev/null; then | |
echo "$0: Pid $PID not found" 1>&2 | |
exit 1 | |
fi | |
mkdir -m 0700 /dev/cgroup/cpu/user/$PID && \ | |
echo $$ > /dev/cgroup/cpu/user/$PID/tasks | |
;; | |
*) | |
print_help | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment