Skip to content

Commit 674666f

Browse files
authored
[ISSUE #198] support nameserver run on cgroup v2 (#199)
* [ISSUE #198] support nameserver run on cgroup v2 * fix when QUOTA equal to 'max'
1 parent d5e797b commit 674666f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

images/namesrv/alpine/runserver-customize.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,31 @@ calculate_heap_sizes()
5555
case "`uname`" in
5656
Linux)
5757
system_memory_in_mb=`free -m| sed -n '2p' | awk '{print $2}'`
58-
system_memory_in_mb_in_docker=$(($(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)/1024/1024))
58+
if [ -f /sys/fs/cgroup/memory/memory.limit_in_bytes ]; then
59+
system_memory_in_mb_in_docker=$(($(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)/1024/1024))
60+
elif [ -f /sys/fs/cgroup/memory.max ]; then
61+
system_memory_in_mb_in_docker=$(($(cat /sys/fs/cgroup/memory.max)/1024/1024))
62+
else
63+
error_exit "Can not get memory, please check cgroup"
64+
fi
5965
if [ $system_memory_in_mb_in_docker -lt $system_memory_in_mb ];then
6066
system_memory_in_mb=$system_memory_in_mb_in_docker
6167
fi
68+
6269
system_cpu_cores=`egrep -c 'processor([[:space:]]+):.*' /proc/cpuinfo`
63-
system_cpu_cores_in_docker=$(($(cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us)/$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us)))
70+
if [ -f /sys/fs/cgroup/cpu/cpu.cfs_quota_us ]; then
71+
system_cpu_cores_in_docker=$(($(cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us)/$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us)))
72+
elif [ -f /sys/fs/cgroup/cpu.max ]; then
73+
QUOTA=$(cut -d ' ' -f 1 /sys/fs/cgroup/cpu.max)
74+
PERIOD=$(cut -d ' ' -f 2 /sys/fs/cgroup/cpu.max)
75+
if [ "$QUOTA" == "max" ]; then # no limit, see https://docs.kernel.org/admin-guide/cgroup-v2.html#cgroup-v2-cpu
76+
system_cpu_cores_in_docker=$system_cpu_cores
77+
else
78+
system_cpu_cores_in_docker=$(($QUOTA/$PERIOD))
79+
fi
80+
else
81+
error_exit "Can not get cpu, please check cgroup"
82+
fi
6483
if [ $system_cpu_cores_in_docker -lt $system_cpu_cores -a $system_cpu_cores_in_docker -ne 0 ];then
6584
system_cpu_cores=$system_cpu_cores_in_docker
6685
fi

0 commit comments

Comments
 (0)