Memory leak fixes#4
Merged
Merged
Conversation
Passing solver.state around as a session.Group results in the solver.state being stored in cache refs, which makes cache ref memory leaks significantly worse. Signed-off-by: Erik Sipsma <erik@sipsma.dev>
Based on testing, each of the three usages of SetFinalizer in buildkit are broken in that they make the memory unfreeable. Most likely this is somehow related to cyclic data structures, but SetFinalizer is very tricky to use correctly so could be something else. Either way, you can empirically see their usage results in unfreeable memory by looking at the heap.alloc.garbage metric when running `viewcore breakdown`. That metric indicates memory in the heap that's not referenced but has not been released. With the SetFinalizers in place, the garbage accumulates to over a GB when running TestModule for a few mins. It never goes down even with manual GC triggers and GOMEMLIMIT settings that force the GC to free as much memory as it can. Removing any one of the SetFinalizers reduces that garbage metric by a few hundred MBs, but removing all of them reduces it down to negligible levels. Signed-off-by: Erik Sipsma <erik@sipsma.dev>
jedevc
approved these changes
Jan 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
See individual commit msgs for details
Side note: I did not end up changing the global
contenthash.defaultManagercache because it doesn't seem to be needed with the other fixes here in place and I don't want to risk performance regressions around that for now.