Memory allocated in runtime.asmcgocall is not freed under some circumstances #27600
Labels
FrozenDueToAge
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?Problem
I'm not sure if this is really Go runtime's issue, but I have been encouraged by @aclements to open a new issue after short discussion in #16843.
There is a small Go application that uses RocksDB via CGO wrapper library. RocksDB is actually written in C++, but also exposes plain C API. There are two ways of interaction between C++ and Go parts of the application:
Go -> C -> C++
: Go just calls C API;Go -> C -> C++ -> C -> Go
: user-defined part of RocksDB - aMergeOperator
- is implemented in Go, and then passed to C++ through function pointer tricks (consider 1, 2). This means that some Go call stacks are not terminated in the C++ part, but pass through C++ part to Go part again.The problem is in linear memory comsumption growth that occurres at the time of database iteration. I can't find out if it's caused by some of Go runtime optimisations, or Linux just don't take back released memory, or is it a memory leak that happens somewhere between programming languages. The available tools seem not to be sufficient to investigate the reasons of this behavior.
In order to reproduce this issue, please follow the instructions.
Call the application, also turn on
go tool pprof
(or http://localhost:6060/debug/pprof/heap?debug=1) andhtop
, and you'll see that:RSS
is about 605 MB;HeapSys
is about 65 MB;estimate-table-readers-mem
) are about 13 MB;So the question is where are the remaining
605 - (65 + 13) = 527 MB
. They are not released even after a half of an our after the iteration stop.On the chart produced by
massif-visualizer
we see that something happens inruntime.asmcgocall
, but it's hard to find out, what's exactly:I will appreciate if someone could comment this issue from the point of Go runtime and CGO internals and give an advice about the tools and best practices of debugging.
The text was updated successfully, but these errors were encountered: