@@ -661,7 +661,9 @@ func gcStart(trigger gcTrigger) {
661
661
662
662
work .cycles ++
663
663
664
- gcController .startCycle ()
664
+ // Assists and workers can start the moment we start
665
+ // the world.
666
+ gcController .startCycle (now )
665
667
work .heapGoal = gcController .heapGoal
666
668
667
669
// In STW mode, disable scheduling of user Gs. This may also
@@ -704,10 +706,6 @@ func gcStart(trigger gcTrigger) {
704
706
// mutators.
705
707
atomic .Store (& gcBlackenEnabled , 1 )
706
708
707
- // Assists and workers can start the moment we start
708
- // the world.
709
- gcController .markStartTime = now
710
-
711
709
// In STW mode, we could block the instant systemstack
712
710
// returns, so make sure we're not preemptible.
713
711
mp = acquirem ()
@@ -965,8 +963,7 @@ func gcMarkTermination(nextTriggerRatio float64) {
965
963
throw ("gc done but gcphase != _GCoff" )
966
964
}
967
965
968
- // Record heapGoal and heap_inuse for scavenger.
969
- gcController .lastHeapGoal = gcController .heapGoal
966
+ // Record heap_inuse for scavenger.
970
967
memstats .last_heap_inuse = memstats .heap_inuse
971
968
972
969
// Update GC trigger and pacing for the next cycle.
@@ -1291,15 +1288,9 @@ func gcBgMarkWorker() {
1291
1288
1292
1289
// Account for time.
1293
1290
duration := nanotime () - startTime
1294
- switch pp .gcMarkWorkerMode {
1295
- case gcMarkWorkerDedicatedMode :
1296
- atomic .Xaddint64 (& gcController .dedicatedMarkTime , duration )
1297
- atomic .Xaddint64 (& gcController .dedicatedMarkWorkersNeeded , 1 )
1298
- case gcMarkWorkerFractionalMode :
1299
- atomic .Xaddint64 (& gcController .fractionalMarkTime , duration )
1291
+ gcController .logWorkTime (pp .gcMarkWorkerMode , duration )
1292
+ if pp .gcMarkWorkerMode == gcMarkWorkerFractionalMode {
1300
1293
atomic .Xaddint64 (& pp .gcFractionalMarkTime , duration )
1301
- case gcMarkWorkerIdleMode :
1302
- atomic .Xaddint64 (& gcController .idleMarkTime , duration )
1303
1294
}
1304
1295
1305
1296
// Was this the last worker and did we run out
@@ -1419,30 +1410,22 @@ func gcMark(startTime int64) {
1419
1410
gcw .dispose ()
1420
1411
}
1421
1412
1422
- // Update the marked heap stat.
1423
- gcController .heapMarked = work .bytesMarked
1424
-
1425
1413
// Flush scanAlloc from each mcache since we're about to modify
1426
1414
// heapScan directly. If we were to flush this later, then scanAlloc
1427
1415
// might have incorrect information.
1416
+ //
1417
+ // Note that it's not important to retain this information; we know
1418
+ // exactly what heapScan is at this point via scanWork.
1428
1419
for _ , p := range allp {
1429
1420
c := p .mcache
1430
1421
if c == nil {
1431
1422
continue
1432
1423
}
1433
- gcController .heapScan += uint64 (c .scanAlloc )
1434
1424
c .scanAlloc = 0
1435
1425
}
1436
1426
1437
- // Update other GC heap size stats. This must happen after
1438
- // cachestats (which flushes local statistics to these) and
1439
- // flushallmcaches (which modifies gcController.heapLive).
1440
- gcController .heapLive = work .bytesMarked
1441
- gcController .heapScan = uint64 (gcController .scanWork )
1442
-
1443
- if trace .enabled {
1444
- traceHeapAlloc ()
1445
- }
1427
+ // Reset controller state.
1428
+ gcController .resetLive (work .bytesMarked )
1446
1429
}
1447
1430
1448
1431
// gcSweep must be called on the system stack because it acquires the heap
0 commit comments