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

cmd/compile: runtime.gcBgMarkWorker.func1 is heap allocated #14999

Closed
aclements opened this issue Mar 28, 2016 · 5 comments
Closed

cmd/compile: runtime.gcBgMarkWorker.func1 is heap allocated #14999

aclements opened this issue Mar 28, 2016 · 5 comments
Milestone

Comments

@aclements
Copy link
Member

  1. What version of Go are you using (go version)?
    go version go1.6 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
    linux/amd64

The closure passed to gopark by gcBgMarkWorker is heap allocated even though it captures no variables. In fact, the constructed closure contains only the code pointer, which is never supposed to happen. This is particularly bad since it's causing an unexpected allocation inside the garbage collector itself. Also strange is that this is an implicit allocation in the runtime, which is supposed to be disallowed.

This happens on master with SSA as well (not too surprising; it's probably a frontend issue).

$ go1.6 build -a -gcflags -S runtime
...
"".gcBgMarkWorker t=1 size=1488 value=0 args=0x8 locals=0x70
    0x0000 00000 (src/runtime/mgc.go:1352)  TEXT    "".gcBgMarkWorker(SB), $112-8
    0x0000 00000 (src/runtime/mgc.go:1352)  MOVQ    (TLS), CX
    0x0009 00009 (src/runtime/mgc.go:1352)  CMPQ    SP, 16(CX)
    0x000d 00013 (src/runtime/mgc.go:1352)  JLS 1475
    0x0013 00019 (src/runtime/mgc.go:1352)  SUBQ    $112, SP
    0x0017 00023 (src/runtime/mgc.go:1352)  FUNCDATA    $0, gclocals·37a2283f5c69c342946cad8073b58fca(SB)
    0x0017 00023 (src/runtime/mgc.go:1352)  FUNCDATA    $1, gclocals·a96d92a3f832e9b072adea30fecea992(SB)
    0x0017 00023 (src/runtime/mgc.go:1357)  MOVQ    $0, BX
    0x0019 00025 (src/runtime/mgc.go:1357)  MOVQ    BX, "".park+96(SP)
    0x001e 00030 (src/runtime/mgc.go:1357)  MOVQ    BX, "".park+104(SP)
    0x0023 00035 (src/runtime/mgc.go:1359)  NOP
    0x0023 00035 (src/runtime/mgc.go:1359)  MOVQ    (TLS), BX
    0x002c 00044 (src/runtime/mgc.go:1359)  MOVQ    BX, "".gp+88(SP)
    0x0031 00049 (src/runtime/mgc.go:1360)  NOP
    0x0031 00049 (src/runtime/mgc.go:1360)  MOVQ    (TLS), CX
    0x003a 00058 (src/runtime/mgc.go:1360)  NOP
    0x003a 00058 (src/runtime/mgc.go:1360)  MOVQ    48(CX), AX
    0x003e 00062 (src/runtime/mgc.go:1360)  NOP
    0x003e 00062 (src/runtime/mgc.go:1360)  MOVL    216(AX), BP
    0x0044 00068 (src/runtime/mgc.go:1360)  NOP
    0x0044 00068 (src/runtime/mgc.go:1360)  INCL    BP
    0x0046 00070 (src/runtime/mgc.go:1360)  MOVL    BP, 216(AX)
    0x004c 00076 (src/runtime/mgc.go:1360)  NOP
    0x004c 00076 (src/runtime/mgc.go:1360)  NOP
    0x004c 00076 (src/runtime/mgc.go:1360)  NOP
    0x004c 00076 (src/runtime/mgc.go:1360)  MOVQ    48(CX), BP
    0x0050 00080 (src/runtime/mgc.go:1360)  MOVQ    BP, "".park+96(SP)
    0x0055 00085 (src/runtime/mgc.go:1361)  MOVQ    ""._p_+120(FP), BX
    0x005a 00090 (src/runtime/mgc.go:1361)  MOVQ    BX, "".park+104(SP)
    0x005f 00095 (src/runtime/mgc.go:1369)  LEAQ    "".work(SB), BX
    0x0066 00102 (src/runtime/mgc.go:1369)  MOVQ    BX, (SP)
    0x006a 00106 (src/runtime/mgc.go:1369)  ADDQ    $168, (SP)
    0x0072 00114 (src/runtime/mgc.go:1369)  PCDATA  $0, $1
    0x0072 00114 (src/runtime/mgc.go:1369)  CALL    "".notewakeup(SB)
    0x0077 00119 (src/runtime/mgc.go:1402)  LEAQ    "".park+96(SP), BX
    0x007c 00124 (src/runtime/mgc.go:1402)  XORQ    $0, BX
    0x0080 00128 (src/runtime/mgc.go:1402)  MOVQ    BX, "".~r1+80(SP)
# Bad closure type
    0x0085 00133 (src/runtime/mgc.go:1375)  LEAQ    type.struct { F uintptr }(SB), BX
    0x008c 00140 (src/runtime/mgc.go:1375)  MOVQ    BX, (SP)
    0x0090 00144 (src/runtime/mgc.go:1375)  PCDATA  $0, $2
# Bad allocation
    0x0090 00144 (src/runtime/mgc.go:1375)  CALL    runtime.newobject(SB)
    0x0095 00149 (src/runtime/mgc.go:1375)  MOVQ    8(SP), AX
    0x009a 00154 (src/runtime/mgc.go:1375)  NOP
    0x009a 00154 (src/runtime/mgc.go:1375)  LEAQ    "".gcBgMarkWorker.func1(SB), BP
    0x00a1 00161 (src/runtime/mgc.go:1375)  MOVQ    BP, (AX)
# Closure becomes first argument to gopark
    0x00a4 00164 (src/runtime/mgc.go:1402)  MOVQ    AX, (SP)
    0x00a8 00168 (src/runtime/mgc.go:1402)  MOVQ    "".~r1+80(SP), BX
    0x00ad 00173 (src/runtime/mgc.go:1402)  MOVQ    BX, 8(SP)
    0x00b2 00178 (src/runtime/mgc.go:1402)  LEAQ    go.string."GC worker (idle)"(SB), BX
    0x00b9 00185 (src/runtime/mgc.go:1402)  MOVQ    BX, 16(SP)
    0x00be 00190 (src/runtime/mgc.go:1402)  MOVQ    $16, 24(SP)
    0x00c7 00199 (src/runtime/mgc.go:1402)  MOVB    $20, 32(SP)
    0x00cc 00204 (src/runtime/mgc.go:1402)  MOVQ    $0, 40(SP)
    0x00d5 00213 (src/runtime/mgc.go:1402)  PCDATA  $0, $1
    0x00d5 00213 (src/runtime/mgc.go:1402)  CALL    "".gopark(SB)
...

/cc @RLH @rsc

@aclements aclements added this to the Go1.6.1 milestone Mar 28, 2016
@randall77
Copy link
Contributor

@dr2chase : could you take a look?

@rsc
Copy link
Contributor

rsc commented Mar 30, 2016

FWIW, this may not need to be Go 1.6.1. We thought this was involved in oversweeping, but it appears not to be. It was just standing nearby at the wrong time.

@dr2chase
Copy link
Contributor

Apparently an "OXXX" node is captured. Haven't tracked down where that came from, but I like the debugging output and may put that into a separate CL.

@dr2chase dr2chase assigned dr2chase and unassigned randall77 Mar 30, 2016
@gopherbot
Copy link

CL https://golang.org/cl/21322 mentions this issue.

@adg adg modified the milestones: Go1.6.1, Go1.6.2 Apr 7, 2016
@rsc
Copy link
Contributor

rsc commented Apr 7, 2016

This looked important but turns out not to be. Wait for Go 1.7.

@rsc rsc modified the milestones: Go1.7, Go1.6.2 Apr 7, 2016
@golang golang locked and limited conversation to collaborators Apr 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants