Skip to content

feat: automatically set GOMEMLIMIT - #16260

Open
timonegk wants to merge 1 commit into
grafana:mainfrom
timonegk:automemlimit
Open

feat: automatically set GOMEMLIMIT#16260
timonegk wants to merge 1 commit into
grafana:mainfrom
timonegk:automemlimit

Conversation

@timonegk

Copy link
Copy Markdown
Contributor

What this PR does

This PR adds automemlimit to automatically set GOMEMLIMIT based on the available memory for the application. It makes Mimir more resilient by preventing OOM kills because garbage collection is run based on this setting. automemlimit is a standard of setting GOMEMLIMIT used, e.g., by kube-state-metrics, prometheus, prometheus-operator, alertmanager, and istio.
If you prefer, I can also make it optional or add additional flags.
This PR is an alternative to calculating the environment variable in the Helm Chart which requires a lot of templating logic (e.g. #12341).

Which issue(s) this PR fixes or relates to

Fixes #10860

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]. If changelog entry is not needed, please add the changelog-not-needed label to the PR.
  • about-versioning.md updated with experimental features.

@timonegk
timonegk requested review from a team and stevesg as code owners July 30, 2026 13:02
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Signed commits report

All 1 commit between main and automemlimit have verified signatures. ✅

@timonegk
timonegk force-pushed the automemlimit branch 5 times, most recently from 6e6b89a to 6d6c9ac Compare July 30, 2026 13:57
@ldufr

ldufr commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

🤖 Automated comment

The CHANGELOG has just been cut to prepare for the next release. Please rebase main and eventually move the CHANGELOG entry added / updated in this PR to the top of the CHANGELOG.md document. Thanks!

Closes grafana#10860

Signed-off-by: Timon Engelke <timon.engelke@inovex.de>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 78c8e85. Configure here.

Comment thread cmd/mimir/main.go
"slices"
"strings"

_ "github.com/KimMachineGun/automemlimit"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ballast conflicts with auto GOMEMLIMIT

Medium Severity

Enabling automemlimit sets GOMEMLIMIT from the cgroup memory limit while Mimir still allocates large ballasts (ruler default 1GiB, distributor 1GiB, querier 256Mi). Ballast counts as live memory under GOMEMLIMIT, so when ballast is near or above the auto-set limit the GC thrashes permanently. Helm already warns about this for manually set GOMEMLIMIT; automatic enabling makes it much easier to hit, especially for ruler deployments that set a modest memory limit.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 78c8e85. Configure here.

@timonegk timonegk Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the ballast pattern is no longer good practice, setting GOMEMLIMIT and GOGC should be able to replace it. But that would of course be a bigger change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Idea: Automatically set GOMEMLIMIT for Mimir components

2 participants