runtime: decorate anonymous memory mappings #71546
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
Implementation
Issues describing a semantics-preserving change to the Go implementation.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Linux 5.17 has introduced an API to name the anonymous memory areas:
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, …)
.This API is already leveraged by the glibc to give an insight of what each anonymous memory area is used for.
See:
Thanks to that,
/proc/<pid>/maps
and/proc/<pid>/smaps
provide information about what each anonymous memory area is used for:See the lines with
[anon: glibc: …]
It could be valuable to have something similar for Go programs.
One use-case that comes to my mind is profiling multi-languages programs that are mixing Go and native C libraries.
With a pure 100% Go program, knowing where the memory allocations are coming from can be done with
pprof
.But
pprof
profiles only the Go code.In a program mixing Go and C libraries, we first need to know if the memory allocation we’re hunting is coming from the Go part or the C part.
Labeling the anonymous memory regions would help for that.
I have already drafted a proof of concept in CL #646095: https://go-review.googlesource.com/c/go/+/646095 that makes the following Go program:
produce this output:
See the lines with
[anon: Go: …]
Thanks to CL #646095, we can know track which memory has been allocated by the Go runtime vs. by the C part.
Rather than labeling all anonymous areas with the same
Go
label, I decided to mimic the glibc behavior and to provide more information about which part of the Go runtime allocated them. But the exact labels can probably be improved.The text was updated successfully, but these errors were encountered: