Skip to content

Commit 4f188c2

Browse files
committed
runtime: disallow GC assists in non-preemptible contexts
Currently it's possible to perform GC work on a system stack or when locks are held if there's an allocation that triggers an assist. This is generally a bad idea because of the fragility of these contexts, and it's incompatible with two changes we're about to make: one is to yield after signaling mark completion (which we can't do from a non-preemptible context) and the other is to make assists block if there's no other way for them to pay off the assist debt. This commit simply skips the assist if it's called from a non-preemptible context. The allocation will still count toward the assist debt, so it will be paid off by a later assist. There should be little allocation from non-preemptible contexts, so this shouldn't harm the overall assist mechanism. Change-Id: I7bf0e6c73e659fe6b52f27437abf39d76b245c79 Reviewed-on: https://go-review.googlesource.com/12649 Reviewed-by: Russ Cox <[email protected]>
1 parent dff9108 commit 4f188c2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/runtime/mgcmark.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ func gcAssistAlloc(size uintptr, allowAssist bool) {
160160
return
161161
}
162162

163+
// Don't assist in non-preemptible contexts. These are
164+
// generally fragile and won't allow the assist to block.
165+
if getg() == gp.m.g0 {
166+
return
167+
}
168+
if mp := getg().m; mp.locks > 0 || mp.preemptoff != "" {
169+
return
170+
}
171+
163172
// Compute the amount of assist scan work we need to do.
164173
scanWork := int64(gcController.assistRatio*float64(gp.gcalloc)) - gp.gcscanwork
165174
// scanWork can be negative if the last assist scanned a large

0 commit comments

Comments
 (0)