Skip to content

Commit dfdd1ba

Browse files
committed
runtime: do not trigger GC on g0
GC acquires worldsema, which is a goroutine-level semaphore which parks goroutines. g0 can not be parked. Fixes #6193. R=khr, khr CC=golang-dev https://golang.org/cl/12880045
1 parent 87fdb8f commit dfdd1ba

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

src/pkg/runtime/mgc0.c

+8-21
Original file line numberDiff line numberDiff line change
@@ -1614,12 +1614,7 @@ addroots(void)
16141614
case Gdead:
16151615
break;
16161616
case Grunning:
1617-
if(gp != m->curg)
1618-
runtime·throw("mark - world not stopped");
1619-
if(g != m->g0)
1620-
runtime·throw("gc not on g0");
1621-
addstackroots(gp);
1622-
break;
1617+
runtime·throw("mark - world not stopped");
16231618
case Grunnable:
16241619
case Gsyscall:
16251620
case Gwaiting:
@@ -2046,7 +2041,7 @@ runtime·gc(int32 force)
20462041
// problems, don't bother trying to run gc
20472042
// while holding a lock. The next mallocgc
20482043
// without a lock will do the gc instead.
2049-
if(!mstats.enablegc || m->locks > 0 || runtime·panicking)
2044+
if(!mstats.enablegc || g == m->g0 || m->locks > 0 || runtime·panicking)
20502045
return;
20512046

20522047
if(gcpercent == GcpercentUnknown) { // first time through
@@ -2077,16 +2072,11 @@ runtime·gc(int32 force)
20772072
// we don't need to scan gc's internal state). Also an
20782073
// enabler for copyable stacks.
20792074
for(i = 0; i < (runtime·debug.gctrace > 1 ? 2 : 1); i++) {
2080-
if(g == m->g0) {
2081-
// already on g0
2082-
gc(&a);
2083-
} else {
2084-
// switch to g0, call gc(&a), then switch back
2085-
g->param = &a;
2086-
g->status = Gwaiting;
2087-
g->waitreason = "garbage collection";
2088-
runtime·mcall(mgc);
2089-
}
2075+
// switch to g0, call gc(&a), then switch back
2076+
g->param = &a;
2077+
g->status = Gwaiting;
2078+
g->waitreason = "garbage collection";
2079+
runtime·mcall(mgc);
20902080
// record a new start time in case we're going around again
20912081
a.start_time = runtime·nanotime();
20922082
}
@@ -2110,11 +2100,8 @@ runtime·gc(int32 force)
21102100
}
21112101
runtime·unlock(&finlock);
21122102
}
2113-
if(g->preempt) // restore the preemption request in case we've cleared it in newstack
2114-
g->stackguard0 = StackPreempt;
21152103
// give the queued finalizers, if any, a chance to run
2116-
if(g != m->g0)
2117-
runtime·gosched();
2104+
runtime·gosched();
21182105
}
21192106

21202107
static void

src/pkg/runtime/stack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ runtime·stackalloc(uint32 n)
105105
m->stackinuse++;
106106
return v;
107107
}
108-
return runtime·mallocgc(n, 0, FlagNoProfiling|FlagNoGC|FlagNoZero);
108+
return runtime·mallocgc(n, 0, FlagNoProfiling|FlagNoGC|FlagNoZero|FlagNoInvokeGC);
109109
}
110110

111111
void

0 commit comments

Comments
 (0)