From: Austin Clements Date: Thu, 16 Mar 2017 21:02:24 +0000 (-0400) Subject: runtime: disallow malloc or panic in scavenge X-Git-Tag: go1.9beta1~1099 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=df6025bc0d7746fdf40a39398e5d8799ccf78a55;p=gostls13.git runtime: disallow malloc or panic in scavenge Mallocs and panics in the scavenge path are particularly nasty because they're likely to silently self-deadlock on the mheap.lock. Avoid sinking lots of time into debugging these issues in the future by turning these into immediate throws. Change-Id: Ib36fdda33bc90b21c32432b03561630c1f3c69bc Reviewed-on: https://go-review.googlesource.com/38293 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index e08680023d..8cd78d460a 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -991,6 +991,11 @@ func scavengelist(list *mSpanList, now, limit uint64) uintptr { } func (h *mheap) scavenge(k int32, now, limit uint64) { + // Disallow malloc or panic while holding the heap lock. We do + // this here because this is an non-mallocgc entry-point to + // the mheap API. + gp := getg() + gp.m.mallocing++ lock(&h.lock) var sumreleased uintptr for i := 0; i < len(h.free); i++ { @@ -998,6 +1003,7 @@ func (h *mheap) scavenge(k int32, now, limit uint64) { } sumreleased += scavengelist(&h.freelarge, now, limit) unlock(&h.lock) + gp.m.mallocing-- if debug.gctrace > 0 { if sumreleased > 0 {