// Stop the world.
runtime·semacquire(&runtime·worldsema, false);
g->m->gcing = 1;
- g->m->locks++;
runtime·stoptheworld();
// Update stats so we can dump them.
// Start up the world again.
g->m->gcing = 0;
+ g->m->locks++;
runtime·semrelease(&runtime·worldsema);
runtime·starttheworld();
g->m->locks--;
return
}
releasem(mp)
+ mp = nil
if panicking != 0 {
return
startTime := gonanotime()
mp = acquirem()
mp.gcing = 1
+ releasem(mp)
stoptheworld()
+ if mp != acquirem() {
+ gothrow("gogc: rescheduled")
+ }
clearpools()
semrelease(&worldsema)
starttheworld()
releasem(mp)
+ mp = nil
// now that gc is done, kick off finalizer thread if needed
if !concurrentSweep {
{
uint32 i;
uintptr sumreleased;
- MStats stats;
MHeap *h;
h = &runtime·mheap;
sumreleased += scavengelist(&h->freelarge, now, limit);
if(runtime·debug.gctrace > 0) {
- runtime·ReadMemStats(&stats);
if(sumreleased > 0)
runtime·printf("scvg%d: %D MB released\n", k, (uint64)sumreleased>>20);
+ // TODO(dvyukov): these stats are incorrect as we don't subtract stack usage from heap.
+ // But we can't call ReadMemStats on g0 holding locks.
runtime·printf("scvg%d: inuse: %D, idle: %D, sys: %D, released: %D, consumed: %D (MB)\n",
- k, stats.heap_inuse>>20, stats.heap_idle>>20, stats.heap_sys>>20,
- stats.heap_released>>20, (stats.heap_sys - stats.heap_released)>>20);
+ k, mstats.heap_inuse>>20, mstats.heap_idle>>20, mstats.heap_sys>>20,
+ mstats.heap_released>>20, (mstats.heap_sys - mstats.heap_released)>>20);
}
}
P *p;
bool wait;
+ // If we hold a lock, then we won't be able to stop another M
+ // that is blocked trying to acquire the lock.
+ if(g->m->locks > 0)
+ runtime·throw("stoptheworld: holding locks");
+ // There is no evidence that stoptheworld on g0 does not work,
+ // we just don't do it today.
+ if(g == g->m->g0)
+ runtime·throw("stoptheworld: on g0");
runtime·lock(&runtime·sched.lock);
runtime·sched.stopwait = runtime·gomaxprocs;
runtime·atomicstore((uint32*)&runtime·sched.gcwaiting, 1);