Skip to content

Commit 757b91e

Browse files
authored
fix: Fix not reading limits when cgroup v2 used (kserve#107)
Docker image was not picking up memory limits when cgroup v2 was used. This lead to incorrect java heap memory limits that lead to crashes due to OOMKilled as described in kserve#106. Add extra check for limits in cgroup v2 file for the image to correctly read memory limits with both cgroup v1 and cgroup v2. Resolves kserve#106 --- Signed-off-by: funbiscuit <[email protected]>
1 parent de7836a commit 757b91e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/scripts/start.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,15 @@ fi
309309
echo $$ > ${ANCHOR_FILE}
310310

311311
if [ "$MEM_LIMIT_MB" = "" ]; then
312-
DOCKER_LIM_FILE="/sys/fs/cgroup/memory/memory.limit_in_bytes"
313-
314-
if [ -e "${DOCKER_LIM_FILE}" ]; then
315-
MEM_LIMIT_MB=$(($(cat ${DOCKER_LIM_FILE})/1024/1024))
316-
echo "Using process mem limit of ${MEM_LIMIT_MB}MiB from ${DOCKER_LIM_FILE}"
312+
CGROUP_V1_LIM_FILE="/sys/fs/cgroup/memory/memory.limit_in_bytes"
313+
CGROUP_V2_LIM_FILE="/sys/fs/cgroup/memory.max"
314+
315+
if [ -e "${CGROUP_V1_LIM_FILE}" ]; then
316+
MEM_LIMIT_MB=$(($(cat ${CGROUP_V1_LIM_FILE})/1024/1024))
317+
echo "Using process mem limit of ${MEM_LIMIT_MB}MiB from ${CGROUP_V1_LIM_FILE}"
318+
elif [ -e "${CGROUP_V2_LIM_FILE}" ]; then
319+
MEM_LIMIT_MB=$(($(cat ${CGROUP_V2_LIM_FILE})/1024/1024))
320+
echo "Using process mem limit of ${MEM_LIMIT_MB}MiB from ${CGROUP_V2_LIM_FILE}"
317321
else
318322
MEM_LIMIT_MB="1536"
319323
echo "No process mem limit provided or found, defaulting to ${MEM_LIMIT_MB}MiB"

0 commit comments

Comments
 (0)