Skip to content

Memory leak fixes#4

Merged
sipsma merged 2 commits into
dagger:masterfrom
sipsma:test-fix
Jan 28, 2025
Merged

Memory leak fixes#4
sipsma merged 2 commits into
dagger:masterfrom
sipsma:test-fix

Conversation

@sipsma
Copy link
Copy Markdown

@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
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