[build] Set heap limit to min(60%, 4gb) for containers if unset#246073
[build] Set heap limit to min(60%, 4gb) for containers if unset#246073jbudz merged 15 commits intoelastic:mainfrom
Conversation
| if [ "$ELASTIC_CONTAINER" = "true" ] && ! echo "$ALL_NODE_OPTIONS" | grep -q -- '--max-old-space-size'; then | ||
| max_old_space_percentage=75 | ||
| heap_mb= | ||
| cgroup_memory_limit_bytes=$(cat /sys/fs/cgroup/memory.max 2>/dev/null || cat /sys/fs/cgroup/memory/memory.limit_in_bytes 2>/dev/null) |
There was a problem hiding this comment.
Watch out for cgroup v1 "unlimited" (/sys/fs/cgroup/memory/memory.limit_in_bytes often returns a huge number like 9223372036854771712): cgroup_memory_limit_bytes * 75 can overflow shell arithmetic and end up negative, so you won’t set any default. It's safer to divide first (limit_mb=$((bytes/1024/1024)), then heap_mb=$((limit_mb*75/100))) and/or treat huge values as “no limit”.
| max_old_space_percentage=75 | ||
| heap_mb= | ||
| cgroup_memory_limit_bytes=$(cat /sys/fs/cgroup/memory.max 2>/dev/null || cat /sys/fs/cgroup/memory/memory.limit_in_bytes 2>/dev/null) | ||
| mem_available_kb=$(grep -E '^MemAvailable:' /proc/meminfo 2>/dev/null | grep -Eo '[0-9]+') |
There was a problem hiding this comment.
Some POSIX oddities: prefer printf '%s' "$ALL_NODE_OPTIONS" | grep ... over echo and consider awk '/^MemAvailable:/ {print $2}' /proc/meminfo instead of grep -Eo for portability.
|
Pinging @elastic/kibana-operations (Team:Operations) |
|
@jbudz I had a conversation with @sophiec20 where she gave the idea of us going up in steps to avoid potential OOMs. For example, initially raise to 60% and then to 75%. What do you think of that approach vs the current one? |
|
It would be good to hear from @rudolf if that approach is sufficient for ECK #245742 |
💚 Build Succeeded
Metrics [docs]
History
|
|
Starting backport for target branches: 9.3 |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
…tic#246073) 1) Should only apply to containers 1) Default heap size should not be > 4Gb 1) Default heap size should be 75% of available memory 1) Configured --max-old-space-size should override defaults Containers now set the default Node.js heap to 75% of available memory up to a maximum of 4096mb. Previously this was set to 50%.
…tic#246073) ### Testing 1) Should only apply to containers 1) Default heap size should not be > 4Gb 1) Default heap size should be 75% of available memory 1) Configured --max-old-space-size should override defaults ### Release note Containers now set the default Node.js heap to 75% of available memory up to a maximum of 4096mb. Previously this was set to 50%.
…tic#246073) ### Testing 1) Should only apply to containers 1) Default heap size should not be > 4Gb 1) Default heap size should be 75% of available memory 1) Configured --max-old-space-size should override defaults ### Release note Containers now set the default Node.js heap to 75% of available memory up to a maximum of 4096mb. Previously this was set to 50%.
Testing
Release note
Containers now set the default Node.js heap to 75% of available memory up to a maximum of 4096mb. Previously this was set to 50%.