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

Open
siebenmann opened this Issue Oct 7, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@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?

Yes.

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 (
        "fmt"
        "os"
        "runtime"
        "time"
)

func main() {
        var ms runtime.MemStats
        fmt.Printf("PID %d\n", os.Getpid())
        runtime.ReadMemStats(&ms)
        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 this to the Go1.12 milestone Oct 8, 2018

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Oct 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment