Skip to content

Commit d398dbd

Browse files
committed
runtime: eliminate gcBlackenPromptly mode
Now that there is no mark 2 phase, gcBlackenPromptly is no longer used. Updates #26903. This is a follow-up to eliminating mark 2. Change-Id: Ib9c534f21b36b8416fcf3cab667f186167b827f8 Reviewed-on: https://go-review.googlesource.com/c/134319 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rick Hudson <[email protected]>
1 parent 9108ae7 commit d398dbd

File tree

6 files changed

+5
-54
lines changed

6 files changed

+5
-54
lines changed

src/runtime/mgc.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,6 @@ var writeBarrier struct {
253253
// gcphase == _GCmark.
254254
var gcBlackenEnabled uint32
255255

256-
// gcBlackenPromptly indicates that optimizations that may
257-
// hide work from the global work queue should be disabled.
258-
//
259-
// If gcBlackenPromptly is true, per-P gcWork caches should
260-
// be flushed immediately and new objects should be allocated black.
261-
//
262-
// There is a tension between allocating objects white and
263-
// allocating them black. If white and the objects die before being
264-
// marked they can be collected during this GC cycle. On the other
265-
// hand allocating them black will reduce _GCmarktermination latency
266-
// since more work is done in the mark phase. This tension is resolved
267-
// by allocating white until the mark phase is approaching its end and
268-
// then allocating black for the remainder of the mark phase.
269-
var gcBlackenPromptly bool
270-
271256
const (
272257
_GCoff = iota // GC not running; sweeping in background, write barrier disabled
273258
_GCmark // GC marking roots and workbufs: allocate black, write barrier ENABLED
@@ -1497,7 +1482,6 @@ func gcMarkTermination(nextTriggerRatio float64) {
14971482
// World is stopped.
14981483
// Start marktermination which includes enabling the write barrier.
14991484
atomic.Store(&gcBlackenEnabled, 0)
1500-
gcBlackenPromptly = false
15011485
setGCPhase(_GCmarktermination)
15021486

15031487
work.heap1 = memstats.heap_live
@@ -1828,16 +1812,6 @@ func gcBgMarkWorker(_p_ *p) {
18281812
casgstatus(gp, _Gwaiting, _Grunning)
18291813
})
18301814

1831-
// If we are nearing the end of mark, dispose
1832-
// of the cache promptly. We must do this
1833-
// before signaling that we're no longer
1834-
// working so that other workers can't observe
1835-
// no workers and no work while we have this
1836-
// cached, and before we compute done.
1837-
if gcBlackenPromptly {
1838-
_p_.gcw.dispose()
1839-
}
1840-
18411815
// Account for time.
18421816
duration := nanotime() - startTime
18431817
switch _p_.gcMarkWorkerMode {

src/runtime/mgcmark.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,6 @@ func gcAssistAlloc1(gp *g, scanWork int64) {
556556
// will be more cache friendly.
557557
gcw := &getg().m.p.ptr().gcw
558558
workDone := gcDrainN(gcw, scanWork)
559-
// If we are near the end of the mark phase
560-
// dispose of the gcw.
561-
if gcBlackenPromptly {
562-
gcw.dispose()
563-
}
564559

565560
casgstatus(gp, _Gwaiting, _Grunning)
566561

@@ -577,8 +572,7 @@ func gcAssistAlloc1(gp *g, scanWork int64) {
577572
incnwait := atomic.Xadd(&work.nwait, +1)
578573
if incnwait > work.nproc {
579574
println("runtime: work.nwait=", incnwait,
580-
"work.nproc=", work.nproc,
581-
"gcBlackenPromptly=", gcBlackenPromptly)
575+
"work.nproc=", work.nproc)
582576
throw("work.nwait > work.nproc")
583577
}
584578

@@ -1155,7 +1149,7 @@ func shade(b uintptr) {
11551149
if obj, span, objIndex := findObject(b, 0, 0); obj != 0 {
11561150
gcw := &getg().m.p.ptr().gcw
11571151
greyobject(obj, 0, 0, span, gcw, objIndex)
1158-
if gcphase == _GCmarktermination || gcBlackenPromptly {
1152+
if gcphase == _GCmarktermination {
11591153
// Ps aren't allowed to cache work during mark
11601154
// termination.
11611155
gcw.dispose()
@@ -1289,18 +1283,13 @@ func gcDumpObject(label string, obj, off uintptr) {
12891283
//go:nowritebarrier
12901284
//go:nosplit
12911285
func gcmarknewobject(obj, size, scanSize uintptr) {
1292-
if useCheckmark && !gcBlackenPromptly { // The world should be stopped so this should not happen.
1286+
if useCheckmark { // The world should be stopped so this should not happen.
12931287
throw("gcmarknewobject called while doing checkmark")
12941288
}
12951289
markBitsForAddr(obj).setMarked()
12961290
gcw := &getg().m.p.ptr().gcw
12971291
gcw.bytesMarked += uint64(size)
12981292
gcw.scanWork += int64(scanSize)
1299-
if gcBlackenPromptly {
1300-
// There shouldn't be anything in the work queue, but
1301-
// we still need to flush stats.
1302-
gcw.dispose()
1303-
}
13041293
}
13051294

13061295
// gcMarkTinyAllocs greys all active tiny alloc blocks.
@@ -1315,9 +1304,6 @@ func gcMarkTinyAllocs() {
13151304
_, span, objIndex := findObject(c.tiny, 0, 0)
13161305
gcw := &p.gcw
13171306
greyobject(c.tiny, 0, 0, span, gcw, objIndex)
1318-
if gcBlackenPromptly {
1319-
gcw.dispose()
1320-
}
13211307
}
13221308
}
13231309

src/runtime/mgcwork.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ func init() {
4747
// (preemption must be disabled)
4848
// gcw := &getg().m.p.ptr().gcw
4949
// .. call gcw.put() to produce and gcw.get() to consume ..
50-
// if gcBlackenPromptly {
51-
// gcw.dispose()
52-
// }
5350
//
5451
// It's important that any use of gcWork during the mark phase prevent
5552
// the garbage collector from transitioning to mark termination since

src/runtime/mheap.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,9 +1438,6 @@ func addfinalizer(p unsafe.Pointer, f *funcval, nret uintptr, fint *_type, ot *p
14381438
// Mark the finalizer itself, since the
14391439
// special isn't part of the GC'd heap.
14401440
scanblock(uintptr(unsafe.Pointer(&s.fn)), sys.PtrSize, &oneptrmask[0], gcw)
1441-
if gcBlackenPromptly {
1442-
gcw.dispose()
1443-
}
14441441
releasem(mp)
14451442
}
14461443
return true

src/runtime/mwbbuf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const (
7979
func (b *wbBuf) reset() {
8080
start := uintptr(unsafe.Pointer(&b.buf[0]))
8181
b.next = start
82-
if gcBlackenPromptly || writeBarrier.cgo {
82+
if writeBarrier.cgo {
8383
// Effectively disable the buffer by forcing a flush
8484
// on every barrier.
8585
b.end = uintptr(unsafe.Pointer(&b.buf[wbBufEntryPointers]))
@@ -275,7 +275,7 @@ func wbBufFlush1(_p_ *p) {
275275

276276
// Enqueue the greyed objects.
277277
gcw.putBatch(ptrs[:pos])
278-
if gcphase == _GCmarktermination || gcBlackenPromptly {
278+
if gcphase == _GCmarktermination {
279279
// Ps aren't allowed to cache work during mark
280280
// termination.
281281
gcw.dispose()

src/runtime/stack.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -981,9 +981,6 @@ func newstack() {
981981
// system stack.
982982
gcw := &gp.m.p.ptr().gcw
983983
scanstack(gp, gcw)
984-
if gcBlackenPromptly {
985-
gcw.dispose()
986-
}
987984
gp.gcscandone = true
988985
}
989986
gp.preemptscan = false

0 commit comments

Comments
 (0)