-
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: decorate anonymous memory mappings #71546
Comments
Change https://go.dev/cl/646095 mentions this issue: |
Related Issues
Related Code Changes (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
I don't think this has to go through the proposal process. |
@L3n41c Do you know which Linux distros actually set CONFIG_ANON_VMA_NAME to enable this feature? I found that neither Debian nor Container-Optimized OS (which most of our Linux CI builders run) enable this feature, so PR_SET_VMA_ANON_NAME simply returns EINVAL. |
Change https://go.dev/cl/655895 mentions this issue: |
This adds a new godebug to control whether the runtime applies the anonymous memory mapping annotations added in https://go.dev/cl/646095. It is enabled by default. This has several effects: * The feature is only enabled by default when the main go.mod has go >= 1.25. * This feature can be disabled with GODEBUG=decoratemappings=0, or the equivalents in go.mod or package main. See https://go.dev/doc/godebug. * As an opaque setting, this option will not appear in runtime/metrics. * This setting is non-atomic, so it cannot be changed after startup. I am not 100% sure about my decision for the last two points. I've made this an opaque setting because it affects every memory mapping the runtime performs. Thus every mapping would report "non-default behavior", which doesn't seem useful. This setting could trivially be atomic and allow changes at run time, but those changes would only affect future mappings. That seems confusing and not helpful. On the other hand, going back to annotate or unannotate every previous mapping when the setting changes is unwarranted complexity. For #71546. Change-Id: I6a6a636c5ad551d76691cba2a6f668d5cff0e352 Reviewed-on: https://go-review.googlesource.com/c/go/+/655895 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Pratt <mpratt@google.com>
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: