Skip to content

Commit 3dbd1eb

Browse files
committed
MEDIUM: Add Cgroups v1 and v2 limits to MEMLIMIT and GOMEMLIMIT calculation
1 parent 744f122 commit 3dbd1eb

File tree

2 files changed

+31
-0
lines changed
  • fs/etc/services.d
    • haproxy
    • ingress-controller

2 files changed

+31
-0
lines changed

fs/etc/services.d/haproxy/run

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,19 @@
22

33
MEMLIMIT=$(free -m | awk '/Mem:/ {print int($2 * 2 / 3)}')
44

5+
CG_LIMIT_FILE="/sys/fs/cgroup/memory/memory.limit_in_bytes"
6+
if [ -f "/sys/fs/cgroup/cgroup.controllers" ]; then
7+
CG_LIMIT_FILE="/sys/fs/cgroup/memory.max"
8+
fi
9+
10+
if [ -r "${CG_LIMIT_FILE}" ]; then
11+
MEMLIMIT_CG=$(awk '{print int($1 / 1024 / 1024 * 2 / 3)}' "${CG_LIMIT_FILE}")
12+
13+
if [ ${MEMLIMIT_CG} -lt ${MEMLIMIT} ]; then
14+
MEMLIMIT=${MEMLIMIT_CG}
15+
fi
16+
fi
17+
18+
echo "Memory limit for HAProxy: ${MEMLIMIT}MiB"
19+
520
exec /usr/local/sbin/haproxy -W -db -m "${MEMLIMIT}" -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/haproxy-aux.cfg
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
#!/usr/bin/with-contenv sh
22

33
MEMLIMIT=$(free -m | awk '/Mem:/ {print int($2 / 3)}')
4+
5+
CG_LIMIT_FILE="/sys/fs/cgroup/memory/memory.limit_in_bytes"
6+
if [ -f "/sys/fs/cgroup/cgroup.controllers" ]; then
7+
CG_LIMIT_FILE="/sys/fs/cgroup/memory.max"
8+
fi
9+
10+
if [ -r "${CG_LIMIT_FILE}" ]; then
11+
MEMLIMIT_CG=$(awk '{print int($1 / 1024 / 1024 / 3)}' "${CG_LIMIT_FILE}")
12+
13+
if [ ${MEMLIMIT_CG} -lt ${MEMLIMIT} ]; then
14+
MEMLIMIT=${MEMLIMIT_CG}
15+
fi
16+
fi
17+
418
export GOMEMLIMIT="${MEMLIMIT}MiB"
519

20+
echo "Memory limit for Ingress Controller: ${GOMEMLIMIT}"
21+
622
exec /haproxy-ingress-controller --with-s6-overlay ${EXTRA_OPTIONS}

0 commit comments

Comments
 (0)