set swap and memory limit according to the hdware when starting the service

modified:   install_shell/cgroup-d5000-install/set_libcgroup.sh
This commit is contained in:
Peng Zhihui
2014-05-19 16:25:38 +08:00
parent 27bffeaf37
commit bc58cd0433

View File

@@ -6,29 +6,7 @@ if [ -z $1 ];then
fi
#设置cgconfig和cgred服务的配置文件
total_mem=`free -m | grep -i "mem" | awk '{print $2}'`
total_swap=`free -m | grep -i "swap" | awk '{print $2}'`
cpus=`cat /proc/cpuinfo | grep processor | wc -l`
((cpus=cpus-2))
if [ ${cpus} -lt 0 ]; then
cpus=0
fi
numa=`numactl --show`
if [ $? -eq 0 ]; then
# memory_nodes=`numactl --hardware | sed -n '1p' | awk '{print $2}'`
memory_nodes=`numactl --hardware | grep "nodes" | awk '{print $4}' | sed -e "s/(//g" | sed -e "s/)//g"`
else
memory_nodes=0
fi
#if [ ${memory_nodes} -ne 0 ]; then
# ((memory_nodes--))
#fi
echo "Starting set the cgconfig.conf..."
cgconfig="group $1_limits {
perm {
task {
@@ -65,35 +43,9 @@ mount {
cgrules="$1: * /$1_limits"
if [ ${total_mem} -le 500 ]; then
mem_root=100
else
mem_root=$((${total_mem}/10))
if [ ${mem_root} -lt 100 ]; then
mem_root=100
elif [ ${mem_root} -ge 100 ] && [ ${mem_root} -le 500 ]; then
mem_root=500
elif [ ${mem_root} -gt 2000 ]; then
mem_root=2000
fi
fi
mem=$((${total_mem}-${mem_root}))
swap=$((${total_swap}/2))
sed -i "/^[^#]/d" /etc/cgconfig.conf
sed -i "/^$/d" /etc/cgconfig.conf
echo "$cgconfig" >> /etc/cgconfig.conf
sed -i "s/var_cpus/${cpus}/g" /etc/cgconfig.conf
sed -i "s/var_nodes/${memory_nodes}/g" /etc/cgconfig.conf
sed -i "s/var_mem/${mem}/g" /etc/cgconfig.conf
sed -i "s/var_swap/$(($mem+$swap))/g" /etc/cgconfig.conf
echo "$cgconfig" > /etc/cgconfig.conf.tmp
echo "Starting set cgrules.conf..."
sed -i "/^[^#]/d" /etc/cgrules.conf
sed -i "/^$/d" /etc/cgrules.conf
echo "$cgrules" >> /etc/cgrules.conf