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

Memory leak fixes #4

Merged
merged 2 commits into from
Jan 28, 2025
Merged

Memory leak fixes #4

merged 2 commits into from
Jan 28, 2025

Conversation

sipsma
Copy link

@sipsma sipsma commented Jan 28, 2025

See individual commit msgs for details

Side note: I did not end up changing the global contenthash.defaultManager cache 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.

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>
@sipsma sipsma merged commit 9c8ee9e into dagger:master Jan 28, 2025
87 of 89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants