Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in blocks storage ingesters #2586

Merged

Conversation

pracucci
Copy link
Contributor

What this PR does:
In a production cluster running the blocks storage we've seen a large portion of the inuse heap retaining memory allocate by grpc.recvMsg(). This is caused by the fact that FromLabelAdaptersToLabelsWithCopy() doesn't do a deep copy but reuse input strings (which are read-only slice pointers).

In this PR we're fixing it doing a deep copy.

Credits: the root cause has been spotted and fixed by @pstibrany. I've just done double checks and opening the PR for it.

Given the same exact test scenario, this is the recvMsg() allocations before the fix:
Screen Shot 2020-05-12 at 17 29 12

And this is after the fix:
Screen Shot 2020-05-12 at 17 24 46

Which issue(s) this PR fixes:
N/A

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Marco Pracucci <marco@pracucci.com>
Copy link
Contributor

@gouthamve gouthamve left a comment

Choose a reason for hiding this comment

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

👍

Signed-off-by: Marco Pracucci <marco@pracucci.com>
@pracucci pracucci merged commit 6d4e8db into cortexproject:master May 13, 2020
@pracucci pracucci deleted the fix-memory-leak-blocks-storage branch May 13, 2020 06:16
return result
}

func copyString(in string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

In pkg/util/extract/extract.go we do string([]byte(label.Value))

Copy link
Contributor

Choose a reason for hiding this comment

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

I know, I was just afraid that Go compiler can easily optimize that away as no-op.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also in pkg/ingester/index/index.go yay DRY.

@bboreham
Copy link
Contributor

Very similar to #1897.

In the 'v1' ingester, index.add() does the copyString().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants