Skip to content

Commit 5451686

Browse files
author
Mohammad Yosefpor
committed
fix: memory detection for ES on cgroupv2
1 parent e7f2386 commit 5451686

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

elasticsearch/run.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,21 @@ if [[ "$CONTAINER_MEM_LIMIT" =~ $regex ]]; then
5151
warn "Downgrading the CONTAINER_MEM_LIMIT to $(($num / BYTES_PER_MEG))m because ${CONTAINER_MEM_LIMIT} will result in a larger heap then recommended."
5252
fi
5353

54+
55+
#check cgroup version
56+
info "Inspecting cgroup version..."
57+
if [ -r "/sys/fs/cgroup/cgroup.controllers" ]; then
58+
#cgroup v2
59+
info "Detected cgroup v2"
60+
mem_file="/sys/fs/cgroup/memory.max"
61+
else
62+
#cgroup v1
63+
info "Detected cgroup v1"
64+
mem_file="/sys/fs/cgroup/memory/memory.limit_in_bytes"
65+
fi
66+
5467
#determine max allowable memory
5568
info "Inspecting the maximum RAM available..."
56-
mem_file="/sys/fs/cgroup/memory/memory.limit_in_bytes"
5769
if [ -r "${mem_file}" ]; then
5870
max_mem="$(cat ${mem_file})"
5971
if [ ${max_mem} -lt ${num} ]; then

0 commit comments

Comments
 (0)