Skip to content

Commit d5b40b6

Browse files
committed
runtime: add GODEBUG gcshrinkstackoff, gcstackbarrieroff, and gcstoptheworld variables
While we're here, update the documentation and delete variables with no effect. Change-Id: I4df0d266dff880df61b488ed547c2870205862f0 Reviewed-on: https://go-review.googlesource.com/10790 Reviewed-by: Austin Clements <[email protected]>
1 parent 80ec711 commit d5b40b6

File tree

5 files changed

+64
-31
lines changed

5 files changed

+64
-31
lines changed

src/runtime/extern.go

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ is GOGC=100. Setting GOGC=off disables the garbage collector entirely.
2121
The runtime/debug package's SetGCPercent function allows changing this
2222
percentage at run time. See http://golang.org/pkg/runtime/debug/#SetGCPercent.
2323
24-
The GODEBUG variable controls debug output from the runtime. GODEBUG value is
25-
a comma-separated list of name=val pairs. Supported names are:
24+
The GODEBUG variable controls debugging variables within the runtime.
25+
It is a comma-separated list of name=val pairs setting these named variables:
2626
2727
allocfreetrace: setting allocfreetrace=1 causes every allocation to be
2828
profiled and a stack trace printed on each object's allocation and free.
@@ -31,23 +31,46 @@ a comma-separated list of name=val pairs. Supported names are:
3131
where each object is allocated on a unique page and addresses are
3232
never recycled.
3333
34+
gccheckmark: setting gccheckmark=1 enables verification of the
35+
garbage collector's concurrent mark phase by performing a
36+
second mark pass while the world is stopped. If the second
37+
pass finds a reachable object that was not found by concurrent
38+
mark, the garbage collector will panic.
39+
40+
gcpacertrace: setting gcpacertrace=1 causes the garbage collector to
41+
print information about the internal state of the concurrent pacer.
42+
43+
gcshrinkstackoff: setting gcshrinkstackoff=1 disables moving goroutines
44+
onto smaller stacks. In this mode, a goroutine's stack can only grow.
45+
46+
gcstackbarrieroff: setting gcstackbarrieroff=1 disables the use of stack barriers
47+
that allow the garbage collector to avoid repeating a stack scan during the
48+
mark termination phase.
49+
50+
gcstoptheworld: setting gcstoptheworld=1 disables concurrent garbage collection,
51+
making every garbage collection a stop-the-world event. Setting gcstoptheworld=2
52+
also disables concurrent sweeping after the garbage collection finishes.
53+
3454
gctrace: setting gctrace=1 causes the garbage collector to emit a single line to standard
3555
error at each collection, summarizing the amount of memory collected and the
3656
length of the pause. Setting gctrace=2 emits the same summary but also
3757
repeats each collection.
3858
39-
gcdead: setting gcdead=1 causes the garbage collector to clobber all stack slots
40-
that it thinks are dead.
59+
memprofilerate: setting memprofilerate=X will update the value of runtime.MemProfileRate.
60+
When set to 0 memory profiling is disabled. Refer to the description of
61+
MemProfileRate for the default value.
4162
4263
invalidptr: defaults to invalidptr=1, causing the garbage collector and stack
4364
copier to crash the program if an invalid pointer value (for example, 1)
4465
is found in a pointer-typed location. Setting invalidptr=0 disables this check.
4566
This should only be used as a temporary workaround to diagnose buggy code.
4667
The real fix is to not store integers in pointer-typed locations.
4768
48-
memprofilerate: setting memprofilerate=X will update the value of runtime.MemProfileRate.
49-
When set to 0 memory profiling is disabled. Refer to the description of
50-
MemProfileRate for the default value.
69+
sbrk: setting sbrk=1 replaces the memory allocator and garbage collector
70+
with a trivial allocator that obtains memory from the operating system and
71+
never reclaims any memory.
72+
73+
scavenge: scavenge=1 enables debugging mode of heap scavenger.
5174
5275
scheddetail: setting schedtrace=X and scheddetail=1 causes the scheduler to emit
5376
detailed multiline info every X milliseconds, describing state of the scheduler,
@@ -56,14 +79,6 @@ a comma-separated list of name=val pairs. Supported names are:
5679
schedtrace: setting schedtrace=X causes the scheduler to emit a single line to standard
5780
error every X milliseconds, summarizing the scheduler state.
5881
59-
scavenge: scavenge=1 enables debugging mode of heap scavenger.
60-
61-
gccheckmark: setting gccheckmark=1 enables verification of the
62-
garbage collector's concurrent mark phase by performing a
63-
second mark pass while the world is stopped. If the second
64-
pass finds a reachable object that was not found by concurrent
65-
mark, the garbage collector will panic.
66-
6782
The GOMAXPROCS variable limits the number of operating system threads that
6883
can execute user-level Go code simultaneously. There is no limit to the number of threads
6984
that can be blocked in system calls on behalf of Go code; those do not count against

src/runtime/mgc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,12 @@ func startGC(mode int) {
740740
releasem(mp)
741741
mp = nil
742742

743+
if debug.gcstoptheworld == 1 {
744+
mode = gcForceMode
745+
} else if debug.gcstoptheworld == 2 {
746+
mode = gcForceBlockMode
747+
}
748+
743749
if mode != gcBackgroundMode {
744750
// special synchronous cases
745751
gc(mode)

src/runtime/mgcmark.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ func scanstack(gp *g) {
327327
barrierOffset = firstStackBarrierOffset
328328
nextBarrier = sp + barrierOffset
329329

330+
if debug.gcstackbarrieroff > 0 {
331+
nextBarrier = ^uintptr(0)
332+
}
333+
330334
if gp.stkbarPos != 0 || len(gp.stkbar) != 0 {
331335
// If this happens, it's probably because we
332336
// scanned a stack twice in the same phase.

src/runtime/runtime1.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -306,33 +306,37 @@ type dbgVar struct {
306306
// existing int var for that value, which may
307307
// already have an initial value.
308308
var debug struct {
309-
allocfreetrace int32
310-
efence int32
311-
gcdead int32
312-
gctrace int32
313-
invalidptr int32
314-
scavenge int32
315-
scheddetail int32
316-
schedtrace int32
317-
wbshadow int32
318-
gccheckmark int32
319-
sbrk int32
320-
gcpacertrace int32
309+
allocfreetrace int32
310+
efence int32
311+
gccheckmark int32
312+
gcpacertrace int32
313+
gcshrinkstackoff int32
314+
gcstackbarrieroff int32
315+
gcstoptheworld int32
316+
gctrace int32
317+
invalidptr int32
318+
sbrk int32
319+
scavenge int32
320+
scheddetail int32
321+
schedtrace int32
322+
wbshadow int32
321323
}
322324

323325
var dbgvars = []dbgVar{
324326
{"allocfreetrace", &debug.allocfreetrace},
325327
{"efence", &debug.efence},
326-
{"gcdead", &debug.gcdead},
328+
{"gccheckmark", &debug.gccheckmark},
329+
{"gcpacertrace", &debug.gcpacertrace},
330+
{"gcshrinkstackoff", &debug.gcshrinkstackoff},
331+
{"gcstackbarrieroff", &debug.gcstackbarrieroff},
332+
{"gcstoptheworld", &debug.gcstoptheworld},
327333
{"gctrace", &debug.gctrace},
328334
{"invalidptr", &debug.invalidptr},
335+
{"sbrk", &debug.sbrk},
329336
{"scavenge", &debug.scavenge},
330337
{"scheddetail", &debug.scheddetail},
331338
{"schedtrace", &debug.schedtrace},
332339
{"wbshadow", &debug.wbshadow},
333-
{"gccheckmark", &debug.gccheckmark},
334-
{"sbrk", &debug.sbrk},
335-
{"gcpacertrace", &debug.gcpacertrace},
336340
}
337341

338342
func parsedebugvars() {

src/runtime/stack1.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@ func shrinkstack(gp *g) {
826826
throw("missing stack in shrinkstack")
827827
}
828828

829+
if debug.gcshrinkstackoff > 0 {
830+
return
831+
}
832+
829833
oldsize := gp.stackAlloc
830834
newsize := oldsize / 2
831835
if newsize < _FixedStack {

0 commit comments

Comments
 (0)