Fix unbounded memory growth with perfmaps/JIT dumps #2265
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?
We have seen unbounded growth of memory in customer environments in JITed scenarios where perfmaps/jitdumps are used.
What?
The memory usage of this code path is entirely held by
newStringConverter
andDeduplicate
: https://pprof.me/c801111f0576cba2f7dc3feb77ad7008/?profileType=profile%3Ainuse_space%3Abytes%3Aspace%3Abytes&filter_by_function=github.com%2Fparca-dev%2Fparca-agent%2Fpkg%2Fperf.ReadPerfMap&search_string=github.com%2Fparca-dev%2Fparca-agent%2Fpkg%2Fperf.ReadPerfMapHow?
This patch replaces the string converter with a string dictionary to reduce memory usage caused by duplicate strings, and compacts it together with the deduplicated perfmap entries, which previously were holding however many entries were in the perfmap, even if the majority was deduplicated.
Test Plan
Unit tests are passing and we ultimately have to test this in customer environments as it can only be observed in long-running environments.
Further notes
If this is not good enough, ultimately the perfmap should be read from the bottom up to never even load "outdated" entries in the first place, I'd only want to implement that though if this doesn't already fix things.
If do do go down that route these two would be helpful:
rscanner
to scan the perfmap from bottom to top