Browse files

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
Run-TryBot: Austin Clements <>
TryBot-Result: Gobot Gobot <>
Reviewed-by: Rick Hudson <>
  • Loading branch information...
aclements committed Mar 16, 2017
1 parent 13ae271 commit df6025bc0d7746fdf40a39398e5d8799ccf78a55
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/runtime/mheap.go
@@ -991,13 +991,19 @@ 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()
var sumreleased uintptr
for i := 0; i < len(; i++ {
sumreleased += scavengelist(&[i], now, limit)
sumreleased += scavengelist(&h.freelarge, now, limit)
if debug.gctrace > 0 {
if sumreleased > 0 {

0 comments on commit df6025b

Please sign in to comment.