Skip to content

[build] Set heap limit to min(60%, 4gb) for containers if unset#246073

Merged
jbudz merged 15 commits intoelastic:mainfrom
jbudz:node-container-heap
Jan 7, 2026
Merged

[build] Set heap limit to min(60%, 4gb) for containers if unset#246073
jbudz merged 15 commits intoelastic:mainfrom
jbudz:node-container-heap

Conversation

@jbudz
Copy link
Contributor

@jbudz jbudz commented Dec 11, 2025

Testing

  1. Should only apply to containers
  2. Default heap size should not be > 4Gb
  3. Default heap size should be 60% of available memory
  4. 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%.

@jbudz jbudz changed the title [build] Set heap limit to min(75%, 4gb) for containers Dec 11, 2025
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)
Copy link
Member

@tylersmalley tylersmalley Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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”.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed f058323

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]+')
Copy link
Member

@tylersmalley tylersmalley Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed 193bacf

@jbudz jbudz requested a review from Copilot December 19, 2025 20:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@jbudz jbudz added Team:Operations Kibana-Operations Team backport:skip This PR does not require backporting backport:version Backport to applied version labels v8.19.10 ci:build-all-platforms ci:build-os-packages and removed backport:skip This PR does not require backporting labels Dec 19, 2025
@jbudz jbudz marked this pull request as ready for review December 19, 2025 20:58
@jbudz jbudz requested a review from a team as a code owner December 19, 2025 20:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

@jbudz jbudz added the release_note:feature Makes this part of the condensed release notes label Dec 19, 2025
Copy link
Contributor

@mistic mistic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mistic
Copy link
Contributor

mistic commented Dec 23, 2025

@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?

@jbudz
Copy link
Contributor Author

jbudz commented Dec 23, 2025

It would be good to hear from @rudolf if that approach is sufficient for ECK

#245742
Related to elastic/cloud-on-k8s#8621

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

@jbudz jbudz added v9.3.0 and removed v8.19.10 labels Jan 6, 2026
@jbudz jbudz merged commit 24b2dd5 into elastic:main Jan 7, 2026
17 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 9.3

https://github.com/elastic/kibana/actions/runs/20769746009

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
9.3 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 246073

Questions ?

Please refer to the Backport tool documentation

@rudolf rudolf mentioned this pull request Jan 7, 2026
jbudz added a commit to jbudz/kibana that referenced this pull request Jan 7, 2026
…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%.
dej611 pushed a commit to dej611/kibana that referenced this pull request Jan 8, 2026
…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%.
devamanv pushed a commit to devamanv/kibana that referenced this pull request Jan 12, 2026
…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%.
@jbudz jbudz changed the title [build] Set heap limit to min(75%, 4gb) for containers if unset Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels ci:build-all-platforms ci:build-os-packages release_note:feature Makes this part of the condensed release notes Team:Operations Kibana-Operations Team v9.3.0 v9.4.0

6 participants