Skip to content
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: L2 arena maps are not accounted for in any runtime.MemStats field #28062

siebenmann opened this issue Oct 7, 2018 · 1 comment


Copy link

@siebenmann siebenmann commented Oct 7, 2018

What version of Go are you using (go version)?

go version devel +2bb91e093c, but this is also true in go 1.11.1 and every version since ec25210 landed.

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

linux/amd64, but the issue is general.

What did you do?

Build and run this program on linux/amd64 and compare its reported value for MemStats.Sys against the value that eg pmap will report.

import (

func main() {
        var ms runtime.MemStats
        fmt.Printf("PID %d\n", os.Getpid())
        fmt.Printf("MemStats %#v\n", ms)
        time.Sleep(time.Second * 100000)

On my machine, there is a significant difference; MemStats.Sys is short by 32 MB or so and shows very little allocation outside of HeapSys. If you look at the Linux kernel memory map (with eg pmap) or use strace -e trace=%memory on the program, it is clearly false, because there is a large 32 MB allocation that is not reflected in MemStats. This allocation is the L2 arena map, allocated in *mheap.syAlloc (currently here). Because this allocation is made by calling persistentalloc() with the last parameter being nil, it is not accounted for in any memstats value, and on modest Go programs it may amount to a significant amount of their runtime OS level memory usage.

(If this is deliberate I believe it's not the right approach, but I suspect it may be an oversight and the CL for the commit doesn't contain any discussion of it either way that I could see. The related heapArena structure is accounted for, for example.)

@ianlancetaylor ianlancetaylor added the NeedsInvestigation label Oct 8, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Oct 8, 2018
Copy link

@ianlancetaylor ianlancetaylor commented Oct 8, 2018

CC @aclements

@andybons andybons removed this from the Go1.12 milestone Feb 12, 2019
@andybons andybons added this to the Go1.13 milestone Feb 12, 2019
@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019
@andybons andybons added this to the Go1.14 milestone Jul 8, 2019
@rsc rsc removed this from the Go1.14 milestone Oct 9, 2019
@rsc rsc added this to the Backlog milestone Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

4 participants