-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
runtime: CGo thread stacks stay in physical memory #71150
Comments
what if you run it with |
@seankhliao It uses more memory ( |
While goroutine stacks can grow and shrink, cgo calls do not run on the goroutine stack [1]. Instead cgo calls run on what we call the "system stack". i.e., the pthread-allocated stack for the thread that the goroutine is currently executing on. This pthread stack does not ever shrink (or grow), which is why you see the resident memory stick around. I suppose that we could theoretically have the GC / This is somewhat related to #14592, as exiting threads would free their stack. [1] Because it might be too small, and we can't grow the stack while running C code like we can while running Go code. cc @golang/runtime |
Go version
go1.23.4 linux/amd64
Output of
go env
in your module/workspace:What did you do?
What did you see happen?
After the program pauses on the
select
call, RSS is497MB
for 150 OS threads. I see many segments of size3132KB
in thepmap
output - my uninformed guess is that these are thread stacks but it's unclear why they are still in physical memory.What did you expect to see?
RSS to fall much lower for the process - low enough just to support the Go runtime. This is a toy example but I'm seeing the same behaviour slowly "leak" memory for a real long-lived Go process that uses CGo.
The text was updated successfully, but these errors were encountered: