This is an automated email from the ASF dual-hosted git repository.
caigy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-operator.git
The following commit(s) were added to refs/heads/master by this push:
new 674666f [ISSUE #198] support nameserver run on cgroup v2 (#199)
674666f is described below
commit 674666fee4f65a5d8edb03d8322f8598fd52396d
Author: yangw <[email protected]>
AuthorDate: Mon Dec 25 15:10:42 2023 +0800
[ISSUE #198] support nameserver run on cgroup v2 (#199)
* [ISSUE #198] support nameserver run on cgroup v2
* fix when QUOTA equal to 'max'
---
images/namesrv/alpine/runserver-customize.sh | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/images/namesrv/alpine/runserver-customize.sh
b/images/namesrv/alpine/runserver-customize.sh
index eaf21ff..6b3bd71 100755
--- a/images/namesrv/alpine/runserver-customize.sh
+++ b/images/namesrv/alpine/runserver-customize.sh
@@ -55,12 +55,31 @@ calculate_heap_sizes()
case "`uname`" in
Linux)
system_memory_in_mb=`free -m| sed -n '2p' | awk '{print $2}'`
- system_memory_in_mb_in_docker=$(($(cat
/sys/fs/cgroup/memory/memory.limit_in_bytes)/1024/1024))
+ if [ -f /sys/fs/cgroup/memory/memory.limit_in_bytes ]; then
+ system_memory_in_mb_in_docker=$(($(cat
/sys/fs/cgroup/memory/memory.limit_in_bytes)/1024/1024))
+ elif [ -f /sys/fs/cgroup/memory.max ]; then
+ system_memory_in_mb_in_docker=$(($(cat
/sys/fs/cgroup/memory.max)/1024/1024))
+ else
+ error_exit "Can not get memory, please check cgroup"
+ fi
if [ $system_memory_in_mb_in_docker -lt $system_memory_in_mb ];then
system_memory_in_mb=$system_memory_in_mb_in_docker
fi
+
system_cpu_cores=`egrep -c 'processor([[:space:]]+):.*'
/proc/cpuinfo`
- system_cpu_cores_in_docker=$(($(cat
/sys/fs/cgroup/cpu/cpu.cfs_quota_us)/$(cat
/sys/fs/cgroup/cpu/cpu.cfs_period_us)))
+ if [ -f /sys/fs/cgroup/cpu/cpu.cfs_quota_us ]; then
+ system_cpu_cores_in_docker=$(($(cat
/sys/fs/cgroup/cpu/cpu.cfs_quota_us)/$(cat
/sys/fs/cgroup/cpu/cpu.cfs_period_us)))
+ elif [ -f /sys/fs/cgroup/cpu.max ]; then
+ QUOTA=$(cut -d ' ' -f 1 /sys/fs/cgroup/cpu.max)
+ PERIOD=$(cut -d ' ' -f 2 /sys/fs/cgroup/cpu.max)
+ if [ "$QUOTA" == "max" ]; then # no limit, see
https://docs.kernel.org/admin-guide/cgroup-v2.html#cgroup-v2-cpu
+ system_cpu_cores_in_docker=$system_cpu_cores
+ else
+ system_cpu_cores_in_docker=$(($QUOTA/$PERIOD))
+ fi
+ else
+ error_exit "Can not get cpu, please check cgroup"
+ fi
if [ $system_cpu_cores_in_docker -lt $system_cpu_cores -a
$system_cpu_cores_in_docker -ne 0 ];then
system_cpu_cores=$system_cpu_cores_in_docker
fi