Commit f24323c9 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: fix spurious deadlock crashes

Fixes #4243.

R=golang-dev, iant
CC=golang-dev, sebastien.paolacci
https://golang.org/cl/6682050
parent 12cbc8ae
...@@ -343,6 +343,13 @@ MHeap_FreeLocked(MHeap *h, MSpan *s) ...@@ -343,6 +343,13 @@ MHeap_FreeLocked(MHeap *h, MSpan *s)
runtime·MSpanList_Insert(&h->large, s); runtime·MSpanList_Insert(&h->large, s);
} }
static void
forcegchelper(Note *note)
{
runtime·gc(1);
runtime·notewakeup(note);
}
// Release (part of) unused memory to OS. // Release (part of) unused memory to OS.
// Goroutine created at startup. // Goroutine created at startup.
// Loop forever. // Loop forever.
...@@ -356,7 +363,7 @@ runtime·MHeap_Scavenger(void) ...@@ -356,7 +363,7 @@ runtime·MHeap_Scavenger(void)
uintptr released, sumreleased; uintptr released, sumreleased;
byte *env; byte *env;
bool trace; bool trace;
Note note; Note note, *notep;
// If we go two minutes without a garbage collection, force one to run. // If we go two minutes without a garbage collection, force one to run.
forcegc = 2*60*1e9; forcegc = 2*60*1e9;
...@@ -385,7 +392,15 @@ runtime·MHeap_Scavenger(void) ...@@ -385,7 +392,15 @@ runtime·MHeap_Scavenger(void)
now = runtime·nanotime(); now = runtime·nanotime();
if(now - mstats.last_gc > forcegc) { if(now - mstats.last_gc > forcegc) {
runtime·unlock(h); runtime·unlock(h);
runtime·gc(1); // The scavenger can not block other goroutines,
// otherwise deadlock detector can fire spuriously.
// GC blocks other goroutines via the runtime·worldsema.
runtime·noteclear(&note);
notep = &note;
runtime·newproc1((byte*)forcegchelper, (byte*)&notep, sizeof(notep), 0, runtime·MHeap_Scavenger);
runtime·entersyscall();
runtime·notesleep(&note);
runtime·exitsyscall();
runtime·lock(h); runtime·lock(h);
now = runtime·nanotime(); now = runtime·nanotime();
if (trace) if (trace)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment