2015-02-12 07:58:25 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
2015-11-02 12:09:24 -07:00
|
|
|
import (
|
|
|
|
"runtime/internal/atomic"
|
2015-11-11 10:39:30 -07:00
|
|
|
"runtime/internal/sys"
|
2015-11-02 12:09:24 -07:00
|
|
|
"unsafe"
|
|
|
|
)
|
2015-02-12 07:58:25 -07:00
|
|
|
|
|
|
|
const (
|
2016-02-25 19:01:16 -07:00
|
|
|
_WorkbufSize = 2048 // in bytes; larger values result in less contention
|
2015-02-12 07:58:25 -07:00
|
|
|
)
|
|
|
|
|
2015-02-12 10:53:48 -07:00
|
|
|
// Garbage collector work pool abstraction.
|
|
|
|
//
|
|
|
|
// This implements a producer/consumer model for pointers to grey
|
2016-03-01 16:21:55 -07:00
|
|
|
// objects. A grey object is one that is marked and on a work
|
|
|
|
// queue. A black object is marked and not on a work queue.
|
2015-02-12 10:53:48 -07:00
|
|
|
//
|
|
|
|
// Write barriers, root discovery, stack scanning, and object scanning
|
2016-03-01 16:21:55 -07:00
|
|
|
// produce pointers to grey objects. Scanning consumes pointers to
|
2015-02-12 10:53:48 -07:00
|
|
|
// grey objects, thus blackening them, and then scans them,
|
|
|
|
// potentially producing new pointers to grey objects.
|
|
|
|
|
|
|
|
// A wbufptr holds a workbuf*, but protects it from write barriers.
|
|
|
|
// workbufs never live on the heap, so write barriers are unnecessary.
|
|
|
|
// Write barriers on workbuf pointers may also be dangerous in the GC.
|
|
|
|
type wbufptr uintptr
|
|
|
|
|
|
|
|
func wbufptrOf(w *workbuf) wbufptr {
|
|
|
|
return wbufptr(unsafe.Pointer(w))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wp wbufptr) ptr() *workbuf {
|
|
|
|
return (*workbuf)(unsafe.Pointer(wp))
|
|
|
|
}
|
|
|
|
|
2015-03-12 11:09:30 -06:00
|
|
|
// A gcWork provides the interface to produce and consume work for the
|
2015-02-12 10:53:48 -07:00
|
|
|
// garbage collector.
|
|
|
|
//
|
runtime: replace per-M workbuf cache with per-P gcWork cache
Currently, each M has a cache of the most recently used *workbuf. This
is used primarily by the write barrier so it doesn't have to access
the global workbuf lists on every write barrier. It's also used by
stack scanning because it's convenient.
This cache is important for write barrier performance, but this
particular approach has several downsides. It's faster than no cache,
but far from optimal (as the benchmarks below show). It's complex:
access to the cache is sprinkled through most of the workbuf list
operations and it requires special care to transform into and back out
of the gcWork cache that's actually used for scanning and marking. It
requires atomic exchanges to take ownership of the cached workbuf and
to return it to the M's cache even though it's almost always used by
only the current M. Since it's per-M, flushing these caches is O(# of
Ms), which may be high. And it has some significant subtleties: for
example, in general the cache shouldn't be used after the
harvestwbufs() in mark termination because it could hide work from
mark termination, but stack scanning can happen after this and *will*
use the cache (but it turns out this is okay because it will always be
followed by a getfull(), which drains the cache).
This change replaces this cache with a per-P gcWork object. This
gcWork cache can be used directly by scanning and marking (as long as
preemption is disabled, which is a general requirement of gcWork).
Since it's per-P, it doesn't require synchronization, which simplifies
things and means the only atomic operations in the write barrier are
occasionally fetching new work buffers and setting a mark bit if the
object isn't already marked. This cache can be flushed in O(# of Ps),
which is generally small. It follows a simple flushing rule: the cache
can be used during any phase, but during mark termination it must be
flushed before allowing preemption. This also makes the dispose during
mutator assist no longer necessary, which eliminates the vast majority
of gcWork dispose calls and reduces contention on the global workbuf
lists. And it's a lot faster on some benchmarks:
benchmark old ns/op new ns/op delta
BenchmarkBinaryTree17 11963668673 11206112763 -6.33%
BenchmarkFannkuch11 2643217136 2649182499 +0.23%
BenchmarkFmtFprintfEmpty 70.4 70.2 -0.28%
BenchmarkFmtFprintfString 364 307 -15.66%
BenchmarkFmtFprintfInt 317 282 -11.04%
BenchmarkFmtFprintfIntInt 512 483 -5.66%
BenchmarkFmtFprintfPrefixedInt 404 380 -5.94%
BenchmarkFmtFprintfFloat 521 479 -8.06%
BenchmarkFmtManyArgs 2164 1894 -12.48%
BenchmarkGobDecode 30366146 22429593 -26.14%
BenchmarkGobEncode 29867472 26663152 -10.73%
BenchmarkGzip 391236616 396779490 +1.42%
BenchmarkGunzip 96639491 96297024 -0.35%
BenchmarkHTTPClientServer 100110 70763 -29.31%
BenchmarkJSONEncode 51866051 52511382 +1.24%
BenchmarkJSONDecode 103813138 86094963 -17.07%
BenchmarkMandelbrot200 4121834 4120886 -0.02%
BenchmarkGoParse 16472789 5879949 -64.31%
BenchmarkRegexpMatchEasy0_32 140 140 +0.00%
BenchmarkRegexpMatchEasy0_1K 394 394 +0.00%
BenchmarkRegexpMatchEasy1_32 120 120 +0.00%
BenchmarkRegexpMatchEasy1_1K 621 614 -1.13%
BenchmarkRegexpMatchMedium_32 209 202 -3.35%
BenchmarkRegexpMatchMedium_1K 54889 55175 +0.52%
BenchmarkRegexpMatchHard_32 2682 2675 -0.26%
BenchmarkRegexpMatchHard_1K 79383 79524 +0.18%
BenchmarkRevcomp 584116718 584595320 +0.08%
BenchmarkTemplate 125400565 109620196 -12.58%
BenchmarkTimeParse 386 387 +0.26%
BenchmarkTimeFormat 580 447 -22.93%
(Best out of 10 runs. The delta of averages is similar.)
This also puts us in a good position to flush these caches when
nearing the end of concurrent marking, which will let us increase the
size of the work buffers while still controlling mark termination
pause time.
Change-Id: I2dd94c8517a19297a98ec280203cccaa58792522
Reviewed-on: https://go-review.googlesource.com/9178
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-19 13:22:20 -06:00
|
|
|
// A gcWork can be used on the stack as follows:
|
2015-02-12 10:53:48 -07:00
|
|
|
//
|
runtime: replace per-M workbuf cache with per-P gcWork cache
Currently, each M has a cache of the most recently used *workbuf. This
is used primarily by the write barrier so it doesn't have to access
the global workbuf lists on every write barrier. It's also used by
stack scanning because it's convenient.
This cache is important for write barrier performance, but this
particular approach has several downsides. It's faster than no cache,
but far from optimal (as the benchmarks below show). It's complex:
access to the cache is sprinkled through most of the workbuf list
operations and it requires special care to transform into and back out
of the gcWork cache that's actually used for scanning and marking. It
requires atomic exchanges to take ownership of the cached workbuf and
to return it to the M's cache even though it's almost always used by
only the current M. Since it's per-M, flushing these caches is O(# of
Ms), which may be high. And it has some significant subtleties: for
example, in general the cache shouldn't be used after the
harvestwbufs() in mark termination because it could hide work from
mark termination, but stack scanning can happen after this and *will*
use the cache (but it turns out this is okay because it will always be
followed by a getfull(), which drains the cache).
This change replaces this cache with a per-P gcWork object. This
gcWork cache can be used directly by scanning and marking (as long as
preemption is disabled, which is a general requirement of gcWork).
Since it's per-P, it doesn't require synchronization, which simplifies
things and means the only atomic operations in the write barrier are
occasionally fetching new work buffers and setting a mark bit if the
object isn't already marked. This cache can be flushed in O(# of Ps),
which is generally small. It follows a simple flushing rule: the cache
can be used during any phase, but during mark termination it must be
flushed before allowing preemption. This also makes the dispose during
mutator assist no longer necessary, which eliminates the vast majority
of gcWork dispose calls and reduces contention on the global workbuf
lists. And it's a lot faster on some benchmarks:
benchmark old ns/op new ns/op delta
BenchmarkBinaryTree17 11963668673 11206112763 -6.33%
BenchmarkFannkuch11 2643217136 2649182499 +0.23%
BenchmarkFmtFprintfEmpty 70.4 70.2 -0.28%
BenchmarkFmtFprintfString 364 307 -15.66%
BenchmarkFmtFprintfInt 317 282 -11.04%
BenchmarkFmtFprintfIntInt 512 483 -5.66%
BenchmarkFmtFprintfPrefixedInt 404 380 -5.94%
BenchmarkFmtFprintfFloat 521 479 -8.06%
BenchmarkFmtManyArgs 2164 1894 -12.48%
BenchmarkGobDecode 30366146 22429593 -26.14%
BenchmarkGobEncode 29867472 26663152 -10.73%
BenchmarkGzip 391236616 396779490 +1.42%
BenchmarkGunzip 96639491 96297024 -0.35%
BenchmarkHTTPClientServer 100110 70763 -29.31%
BenchmarkJSONEncode 51866051 52511382 +1.24%
BenchmarkJSONDecode 103813138 86094963 -17.07%
BenchmarkMandelbrot200 4121834 4120886 -0.02%
BenchmarkGoParse 16472789 5879949 -64.31%
BenchmarkRegexpMatchEasy0_32 140 140 +0.00%
BenchmarkRegexpMatchEasy0_1K 394 394 +0.00%
BenchmarkRegexpMatchEasy1_32 120 120 +0.00%
BenchmarkRegexpMatchEasy1_1K 621 614 -1.13%
BenchmarkRegexpMatchMedium_32 209 202 -3.35%
BenchmarkRegexpMatchMedium_1K 54889 55175 +0.52%
BenchmarkRegexpMatchHard_32 2682 2675 -0.26%
BenchmarkRegexpMatchHard_1K 79383 79524 +0.18%
BenchmarkRevcomp 584116718 584595320 +0.08%
BenchmarkTemplate 125400565 109620196 -12.58%
BenchmarkTimeParse 386 387 +0.26%
BenchmarkTimeFormat 580 447 -22.93%
(Best out of 10 runs. The delta of averages is similar.)
This also puts us in a good position to flush these caches when
nearing the end of concurrent marking, which will let us increase the
size of the work buffers while still controlling mark termination
pause time.
Change-Id: I2dd94c8517a19297a98ec280203cccaa58792522
Reviewed-on: https://go-review.googlesource.com/9178
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-19 13:22:20 -06:00
|
|
|
// (preemption must be disabled)
|
|
|
|
// gcw := &getg().m.p.ptr().gcw
|
|
|
|
// .. call gcw.put() to produce and gcw.get() to consume ..
|
2015-09-24 12:24:32 -06:00
|
|
|
// if gcBlackenPromptly {
|
runtime: replace per-M workbuf cache with per-P gcWork cache
Currently, each M has a cache of the most recently used *workbuf. This
is used primarily by the write barrier so it doesn't have to access
the global workbuf lists on every write barrier. It's also used by
stack scanning because it's convenient.
This cache is important for write barrier performance, but this
particular approach has several downsides. It's faster than no cache,
but far from optimal (as the benchmarks below show). It's complex:
access to the cache is sprinkled through most of the workbuf list
operations and it requires special care to transform into and back out
of the gcWork cache that's actually used for scanning and marking. It
requires atomic exchanges to take ownership of the cached workbuf and
to return it to the M's cache even though it's almost always used by
only the current M. Since it's per-M, flushing these caches is O(# of
Ms), which may be high. And it has some significant subtleties: for
example, in general the cache shouldn't be used after the
harvestwbufs() in mark termination because it could hide work from
mark termination, but stack scanning can happen after this and *will*
use the cache (but it turns out this is okay because it will always be
followed by a getfull(), which drains the cache).
This change replaces this cache with a per-P gcWork object. This
gcWork cache can be used directly by scanning and marking (as long as
preemption is disabled, which is a general requirement of gcWork).
Since it's per-P, it doesn't require synchronization, which simplifies
things and means the only atomic operations in the write barrier are
occasionally fetching new work buffers and setting a mark bit if the
object isn't already marked. This cache can be flushed in O(# of Ps),
which is generally small. It follows a simple flushing rule: the cache
can be used during any phase, but during mark termination it must be
flushed before allowing preemption. This also makes the dispose during
mutator assist no longer necessary, which eliminates the vast majority
of gcWork dispose calls and reduces contention on the global workbuf
lists. And it's a lot faster on some benchmarks:
benchmark old ns/op new ns/op delta
BenchmarkBinaryTree17 11963668673 11206112763 -6.33%
BenchmarkFannkuch11 2643217136 2649182499 +0.23%
BenchmarkFmtFprintfEmpty 70.4 70.2 -0.28%
BenchmarkFmtFprintfString 364 307 -15.66%
BenchmarkFmtFprintfInt 317 282 -11.04%
BenchmarkFmtFprintfIntInt 512 483 -5.66%
BenchmarkFmtFprintfPrefixedInt 404 380 -5.94%
BenchmarkFmtFprintfFloat 521 479 -8.06%
BenchmarkFmtManyArgs 2164 1894 -12.48%
BenchmarkGobDecode 30366146 22429593 -26.14%
BenchmarkGobEncode 29867472 26663152 -10.73%
BenchmarkGzip 391236616 396779490 +1.42%
BenchmarkGunzip 96639491 96297024 -0.35%
BenchmarkHTTPClientServer 100110 70763 -29.31%
BenchmarkJSONEncode 51866051 52511382 +1.24%
BenchmarkJSONDecode 103813138 86094963 -17.07%
BenchmarkMandelbrot200 4121834 4120886 -0.02%
BenchmarkGoParse 16472789 5879949 -64.31%
BenchmarkRegexpMatchEasy0_32 140 140 +0.00%
BenchmarkRegexpMatchEasy0_1K 394 394 +0.00%
BenchmarkRegexpMatchEasy1_32 120 120 +0.00%
BenchmarkRegexpMatchEasy1_1K 621 614 -1.13%
BenchmarkRegexpMatchMedium_32 209 202 -3.35%
BenchmarkRegexpMatchMedium_1K 54889 55175 +0.52%
BenchmarkRegexpMatchHard_32 2682 2675 -0.26%
BenchmarkRegexpMatchHard_1K 79383 79524 +0.18%
BenchmarkRevcomp 584116718 584595320 +0.08%
BenchmarkTemplate 125400565 109620196 -12.58%
BenchmarkTimeParse 386 387 +0.26%
BenchmarkTimeFormat 580 447 -22.93%
(Best out of 10 runs. The delta of averages is similar.)
This also puts us in a good position to flush these caches when
nearing the end of concurrent marking, which will let us increase the
size of the work buffers while still controlling mark termination
pause time.
Change-Id: I2dd94c8517a19297a98ec280203cccaa58792522
Reviewed-on: https://go-review.googlesource.com/9178
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-19 13:22:20 -06:00
|
|
|
// gcw.dispose()
|
|
|
|
// }
|
|
|
|
//
|
2015-03-20 11:34:03 -06:00
|
|
|
// It's important that any use of gcWork during the mark phase prevent
|
|
|
|
// the garbage collector from transitioning to mark termination since
|
|
|
|
// gcWork may locally hold GC work buffers. This can be done by
|
|
|
|
// disabling preemption (systemstack or acquirem).
|
2015-03-12 11:09:30 -06:00
|
|
|
type gcWork struct {
|
2015-10-16 07:53:11 -06:00
|
|
|
// wbuf1 and wbuf2 are the primary and secondary work buffers.
|
|
|
|
//
|
|
|
|
// This can be thought of as a stack of both work buffers'
|
|
|
|
// pointers concatenated. When we pop the last pointer, we
|
|
|
|
// shift the stack up by one work buffer by bringing in a new
|
|
|
|
// full buffer and discarding an empty one. When we fill both
|
|
|
|
// buffers, we shift the stack down by one work buffer by
|
|
|
|
// bringing in a new empty buffer and discarding a full one.
|
|
|
|
// This way we have one buffer's worth of hysteresis, which
|
|
|
|
// amortizes the cost of getting or putting a work buffer over
|
|
|
|
// at least one buffer of work and reduces contention on the
|
|
|
|
// global work lists.
|
|
|
|
//
|
|
|
|
// wbuf1 is always the buffer we're currently pushing to and
|
|
|
|
// popping from and wbuf2 is the buffer that will be discarded
|
|
|
|
// next.
|
|
|
|
//
|
|
|
|
// Invariant: Both wbuf1 and wbuf2 are nil or neither are.
|
|
|
|
wbuf1, wbuf2 wbufptr
|
2015-03-12 14:53:57 -06:00
|
|
|
|
|
|
|
// Bytes marked (blackened) on this gcWork. This is aggregated
|
|
|
|
// into work.bytesMarked by dispose.
|
|
|
|
bytesMarked uint64
|
2015-03-12 10:08:47 -06:00
|
|
|
|
|
|
|
// Scan work performed on this gcWork. This is aggregated into
|
2015-10-04 21:00:01 -06:00
|
|
|
// gcController by dispose and may also be flushed by callers.
|
2015-03-12 10:08:47 -06:00
|
|
|
scanWork int64
|
2015-02-12 10:53:48 -07:00
|
|
|
}
|
|
|
|
|
2015-10-16 07:53:11 -06:00
|
|
|
func (w *gcWork) init() {
|
2016-02-25 19:01:16 -07:00
|
|
|
w.wbuf1 = wbufptrOf(getempty())
|
|
|
|
wbuf2 := trygetfull()
|
2015-10-16 07:53:11 -06:00
|
|
|
if wbuf2 == nil {
|
2016-02-25 19:01:16 -07:00
|
|
|
wbuf2 = getempty()
|
2015-10-16 07:53:11 -06:00
|
|
|
}
|
|
|
|
w.wbuf2 = wbufptrOf(wbuf2)
|
|
|
|
}
|
|
|
|
|
2015-02-12 10:53:48 -07:00
|
|
|
// put enqueues a pointer for the garbage collector to trace.
|
runtime: eliminate one heapBitsForObject from scanobject
scanobject with ptrmask!=nil is only ever called with the base
pointer of a heap object. Currently, scanobject calls
heapBitsForObject, which goes to a great deal of trouble to check
that the pointer points into the heap and to find the base of the
object it points to, both of which are completely unnecessary in
this case.
Replace this call to heapBitsForObject with much simpler logic to
fetch the span and compute the heap bits.
Benchmark results with five runs:
name old mean new mean delta
BenchmarkBinaryTree17 9.21s × (0.95,1.02) 8.55s × (0.91,1.03) -7.16% (p=0.022)
BenchmarkFannkuch11 2.65s × (1.00,1.00) 2.62s × (1.00,1.00) -1.10% (p=0.000)
BenchmarkFmtFprintfEmpty 73.2ns × (0.99,1.01) 71.7ns × (1.00,1.01) -1.99% (p=0.004)
BenchmarkFmtFprintfString 302ns × (0.99,1.00) 292ns × (0.98,1.02) -3.31% (p=0.020)
BenchmarkFmtFprintfInt 281ns × (0.98,1.01) 279ns × (0.96,1.02) ~ (p=0.596)
BenchmarkFmtFprintfIntInt 482ns × (0.98,1.01) 488ns × (0.95,1.02) ~ (p=0.419)
BenchmarkFmtFprintfPrefixedInt 382ns × (0.99,1.01) 365ns × (0.96,1.02) -4.35% (p=0.015)
BenchmarkFmtFprintfFloat 475ns × (0.99,1.01) 472ns × (1.00,1.00) ~ (p=0.108)
BenchmarkFmtManyArgs 1.89µs × (1.00,1.01) 1.90µs × (0.94,1.02) ~ (p=0.883)
BenchmarkGobDecode 22.4ms × (0.99,1.01) 21.9ms × (0.92,1.04) ~ (p=0.332)
BenchmarkGobEncode 24.7ms × (0.98,1.02) 23.9ms × (0.87,1.07) ~ (p=0.407)
BenchmarkGzip 397ms × (0.99,1.01) 398ms × (0.99,1.01) ~ (p=0.718)
BenchmarkGunzip 96.7ms × (1.00,1.00) 96.9ms × (1.00,1.00) ~ (p=0.230)
BenchmarkHTTPClientServer 71.5µs × (0.98,1.01) 68.5µs × (0.92,1.06) ~ (p=0.243)
BenchmarkJSONEncode 46.1ms × (0.98,1.01) 44.9ms × (0.98,1.03) -2.51% (p=0.040)
BenchmarkJSONDecode 86.1ms × (0.99,1.01) 86.5ms × (0.99,1.01) ~ (p=0.343)
BenchmarkMandelbrot200 4.12ms × (1.00,1.00) 4.13ms × (1.00,1.00) +0.23% (p=0.000)
BenchmarkGoParse 5.89ms × (0.96,1.03) 5.82ms × (0.96,1.04) ~ (p=0.522)
BenchmarkRegexpMatchEasy0_32 141ns × (0.99,1.01) 142ns × (1.00,1.00) ~ (p=0.178)
BenchmarkRegexpMatchEasy0_1K 408ns × (1.00,1.00) 392ns × (0.99,1.00) -3.83% (p=0.000)
BenchmarkRegexpMatchEasy1_32 122ns × (1.00,1.00) 122ns × (1.00,1.00) ~ (p=0.178)
BenchmarkRegexpMatchEasy1_1K 626ns × (1.00,1.01) 624ns × (0.99,1.00) ~ (p=0.122)
BenchmarkRegexpMatchMedium_32 202ns × (0.99,1.00) 205ns × (0.99,1.01) +1.58% (p=0.001)
BenchmarkRegexpMatchMedium_1K 54.4µs × (1.00,1.00) 55.5µs × (1.00,1.00) +1.86% (p=0.000)
BenchmarkRegexpMatchHard_32 2.68µs × (1.00,1.00) 2.71µs × (1.00,1.00) +0.97% (p=0.002)
BenchmarkRegexpMatchHard_1K 79.8µs × (1.00,1.01) 80.5µs × (1.00,1.01) +0.94% (p=0.003)
BenchmarkRevcomp 590ms × (0.99,1.01) 585ms × (1.00,1.00) ~ (p=0.066)
BenchmarkTemplate 111ms × (0.97,1.02) 112ms × (0.99,1.01) ~ (p=0.201)
BenchmarkTimeParse 392ns × (1.00,1.00) 385ns × (1.00,1.00) -1.69% (p=0.000)
BenchmarkTimeFormat 449ns × (0.98,1.01) 448ns × (0.99,1.01) ~ (p=0.550)
Change-Id: Ie7c3830c481d96c9043e7bf26853c6c1d05dc9f4
Reviewed-on: https://go-review.googlesource.com/9364
Reviewed-by: Rick Hudson <rlh@golang.org>
2015-04-26 16:27:17 -06:00
|
|
|
// obj must point to the beginning of a heap object.
|
2015-02-12 10:53:48 -07:00
|
|
|
//go:nowritebarrier
|
2016-02-09 16:37:41 -07:00
|
|
|
func (w *gcWork) put(obj uintptr) {
|
2015-10-16 07:53:11 -06:00
|
|
|
wbuf := w.wbuf1.ptr()
|
2015-02-12 10:53:48 -07:00
|
|
|
if wbuf == nil {
|
2015-10-16 07:53:11 -06:00
|
|
|
w.init()
|
|
|
|
wbuf = w.wbuf1.ptr()
|
|
|
|
// wbuf is empty at this point.
|
|
|
|
} else if wbuf.nobj == len(wbuf.obj) {
|
|
|
|
w.wbuf1, w.wbuf2 = w.wbuf2, w.wbuf1
|
|
|
|
wbuf = w.wbuf1.ptr()
|
|
|
|
if wbuf.nobj == len(wbuf.obj) {
|
2016-02-25 19:01:16 -07:00
|
|
|
putfull(wbuf)
|
|
|
|
wbuf = getempty()
|
2015-10-16 07:53:11 -06:00
|
|
|
w.wbuf1 = wbufptrOf(wbuf)
|
|
|
|
}
|
2015-02-12 10:53:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
wbuf.obj[wbuf.nobj] = obj
|
|
|
|
wbuf.nobj++
|
|
|
|
}
|
|
|
|
|
2016-03-14 10:17:48 -06:00
|
|
|
// putFast does a put and returns true if it can be done quickly
|
|
|
|
// otherwise it returns false and the caller needs to call put.
|
|
|
|
//go:nowritebarrier
|
|
|
|
func (w *gcWork) putFast(obj uintptr) bool {
|
|
|
|
wbuf := w.wbuf1.ptr()
|
|
|
|
if wbuf == nil {
|
|
|
|
return false
|
|
|
|
} else if wbuf.nobj == len(wbuf.obj) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
wbuf.obj[wbuf.nobj] = obj
|
|
|
|
wbuf.nobj++
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-02-12 10:53:48 -07:00
|
|
|
// tryGet dequeues a pointer for the garbage collector to trace.
|
|
|
|
//
|
|
|
|
// If there are no pointers remaining in this gcWork or in the global
|
|
|
|
// queue, tryGet returns 0. Note that there may still be pointers in
|
|
|
|
// other gcWork instances or other caches.
|
|
|
|
//go:nowritebarrier
|
2016-02-09 16:37:41 -07:00
|
|
|
func (w *gcWork) tryGet() uintptr {
|
2015-10-16 07:53:11 -06:00
|
|
|
wbuf := w.wbuf1.ptr()
|
2015-02-12 10:53:48 -07:00
|
|
|
if wbuf == nil {
|
2015-10-16 07:53:11 -06:00
|
|
|
w.init()
|
|
|
|
wbuf = w.wbuf1.ptr()
|
|
|
|
// wbuf is empty at this point.
|
2015-02-12 10:53:48 -07:00
|
|
|
}
|
|
|
|
if wbuf.nobj == 0 {
|
2015-10-16 07:53:11 -06:00
|
|
|
w.wbuf1, w.wbuf2 = w.wbuf2, w.wbuf1
|
|
|
|
wbuf = w.wbuf1.ptr()
|
|
|
|
if wbuf.nobj == 0 {
|
|
|
|
owbuf := wbuf
|
2016-02-25 19:01:16 -07:00
|
|
|
wbuf = trygetfull()
|
2015-10-16 07:53:11 -06:00
|
|
|
if wbuf == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2016-02-25 19:01:16 -07:00
|
|
|
putempty(owbuf)
|
2015-10-16 07:53:11 -06:00
|
|
|
w.wbuf1 = wbufptrOf(wbuf)
|
|
|
|
}
|
2015-02-12 10:53:48 -07:00
|
|
|
}
|
|
|
|
|
2015-10-16 07:53:11 -06:00
|
|
|
wbuf.nobj--
|
|
|
|
return wbuf.obj[wbuf.nobj]
|
2015-02-12 10:53:48 -07:00
|
|
|
}
|
|
|
|
|
2016-03-14 10:17:48 -06:00
|
|
|
// tryGetFast dequeues a pointer for the garbage collector to trace
|
|
|
|
// if one is readily available. Otherwise it returns 0 and
|
|
|
|
// the caller is expected to call tryGet().
|
|
|
|
//go:nowritebarrier
|
|
|
|
func (w *gcWork) tryGetFast() uintptr {
|
|
|
|
wbuf := w.wbuf1.ptr()
|
|
|
|
if wbuf == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if wbuf.nobj == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
wbuf.nobj--
|
|
|
|
return wbuf.obj[wbuf.nobj]
|
|
|
|
}
|
|
|
|
|
2015-02-12 10:53:48 -07:00
|
|
|
// get dequeues a pointer for the garbage collector to trace, blocking
|
|
|
|
// if necessary to ensure all pointers from all queues and caches have
|
|
|
|
// been retrieved. get returns 0 if there are no pointers remaining.
|
|
|
|
//go:nowritebarrier
|
2016-02-09 16:37:41 -07:00
|
|
|
func (w *gcWork) get() uintptr {
|
2015-10-16 07:53:11 -06:00
|
|
|
wbuf := w.wbuf1.ptr()
|
2015-02-12 10:53:48 -07:00
|
|
|
if wbuf == nil {
|
2015-10-16 07:53:11 -06:00
|
|
|
w.init()
|
|
|
|
wbuf = w.wbuf1.ptr()
|
|
|
|
// wbuf is empty at this point.
|
|
|
|
}
|
|
|
|
if wbuf.nobj == 0 {
|
|
|
|
w.wbuf1, w.wbuf2 = w.wbuf2, w.wbuf1
|
|
|
|
wbuf = w.wbuf1.ptr()
|
|
|
|
if wbuf.nobj == 0 {
|
|
|
|
owbuf := wbuf
|
2016-02-25 19:01:16 -07:00
|
|
|
wbuf = getfull()
|
2015-10-16 07:53:11 -06:00
|
|
|
if wbuf == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2016-02-25 19:01:16 -07:00
|
|
|
putempty(owbuf)
|
2015-10-16 07:53:11 -06:00
|
|
|
w.wbuf1 = wbufptrOf(wbuf)
|
2015-02-12 10:53:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: This might be a good place to add prefetch code
|
|
|
|
|
|
|
|
wbuf.nobj--
|
2015-10-16 07:53:11 -06:00
|
|
|
return wbuf.obj[wbuf.nobj]
|
2015-02-12 10:53:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// dispose returns any cached pointers to the global queue.
|
2015-07-29 10:03:54 -06:00
|
|
|
// The buffers are being put on the full queue so that the
|
|
|
|
// write barriers will not simply reacquire them before the
|
|
|
|
// GC can inspect them. This helps reduce the mutator's
|
|
|
|
// ability to hide pointers during the concurrent mark phase.
|
|
|
|
//
|
2015-02-12 10:53:48 -07:00
|
|
|
//go:nowritebarrier
|
|
|
|
func (w *gcWork) dispose() {
|
2015-10-16 07:53:11 -06:00
|
|
|
if wbuf := w.wbuf1.ptr(); wbuf != nil {
|
|
|
|
if wbuf.nobj == 0 {
|
2016-02-25 19:01:16 -07:00
|
|
|
putempty(wbuf)
|
2015-10-16 07:53:11 -06:00
|
|
|
} else {
|
2016-02-25 19:01:16 -07:00
|
|
|
putfull(wbuf)
|
2015-07-29 10:03:54 -06:00
|
|
|
}
|
2015-10-16 07:53:11 -06:00
|
|
|
w.wbuf1 = 0
|
|
|
|
|
|
|
|
wbuf = w.wbuf2.ptr()
|
|
|
|
if wbuf.nobj == 0 {
|
2016-02-25 19:01:16 -07:00
|
|
|
putempty(wbuf)
|
2015-10-16 07:53:11 -06:00
|
|
|
} else {
|
2016-02-25 19:01:16 -07:00
|
|
|
putfull(wbuf)
|
2015-10-16 07:53:11 -06:00
|
|
|
}
|
|
|
|
w.wbuf2 = 0
|
2015-03-12 11:09:30 -06:00
|
|
|
}
|
2015-03-12 14:53:57 -06:00
|
|
|
if w.bytesMarked != 0 {
|
|
|
|
// dispose happens relatively infrequently. If this
|
|
|
|
// atomic becomes a problem, we should first try to
|
|
|
|
// dispose less and if necessary aggregate in a per-P
|
|
|
|
// counter.
|
2015-11-02 12:09:24 -07:00
|
|
|
atomic.Xadd64(&work.bytesMarked, int64(w.bytesMarked))
|
2015-03-12 14:53:57 -06:00
|
|
|
w.bytesMarked = 0
|
|
|
|
}
|
2015-03-12 10:08:47 -06:00
|
|
|
if w.scanWork != 0 {
|
2015-11-02 12:09:24 -07:00
|
|
|
atomic.Xaddint64(&gcController.scanWork, w.scanWork)
|
2015-03-12 10:08:47 -06:00
|
|
|
w.scanWork = 0
|
|
|
|
}
|
2015-03-12 11:09:30 -06:00
|
|
|
}
|
|
|
|
|
2015-02-12 10:53:48 -07:00
|
|
|
// balance moves some work that's cached in this gcWork back on the
|
|
|
|
// global queue.
|
|
|
|
//go:nowritebarrier
|
|
|
|
func (w *gcWork) balance() {
|
2015-10-16 07:53:11 -06:00
|
|
|
if w.wbuf1 == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if wbuf := w.wbuf2.ptr(); wbuf.nobj != 0 {
|
2016-02-25 19:01:16 -07:00
|
|
|
putfull(wbuf)
|
|
|
|
w.wbuf2 = wbufptrOf(getempty())
|
2015-10-16 07:53:11 -06:00
|
|
|
} else if wbuf := w.wbuf1.ptr(); wbuf.nobj > 4 {
|
|
|
|
w.wbuf1 = wbufptrOf(handoff(wbuf))
|
2015-02-12 10:53:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 14:02:37 -06:00
|
|
|
// empty returns true if w has no mark work available.
|
|
|
|
//go:nowritebarrier
|
|
|
|
func (w *gcWork) empty() bool {
|
2015-10-16 07:53:11 -06:00
|
|
|
return w.wbuf1 == 0 || (w.wbuf1.ptr().nobj == 0 && w.wbuf2.ptr().nobj == 0)
|
2015-05-18 14:02:37 -06:00
|
|
|
}
|
|
|
|
|
2015-02-12 10:53:48 -07:00
|
|
|
// Internally, the GC work pool is kept in arrays in work buffers.
|
|
|
|
// The gcWork interface caches a work buffer until full (or empty) to
|
|
|
|
// avoid contending on the global work buffer lists.
|
|
|
|
|
2015-02-12 07:58:25 -07:00
|
|
|
type workbufhdr struct {
|
2016-02-25 19:01:16 -07:00
|
|
|
node lfnode // must be first
|
|
|
|
nobj int
|
2015-02-12 07:58:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type workbuf struct {
|
|
|
|
workbufhdr
|
|
|
|
// account for the above fields
|
2015-11-11 10:39:30 -07:00
|
|
|
obj [(_WorkbufSize - unsafe.Sizeof(workbufhdr{})) / sys.PtrSize]uintptr
|
2015-02-12 07:58:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// workbuf factory routines. These funcs are used to manage the
|
runtime: replace per-M workbuf cache with per-P gcWork cache
Currently, each M has a cache of the most recently used *workbuf. This
is used primarily by the write barrier so it doesn't have to access
the global workbuf lists on every write barrier. It's also used by
stack scanning because it's convenient.
This cache is important for write barrier performance, but this
particular approach has several downsides. It's faster than no cache,
but far from optimal (as the benchmarks below show). It's complex:
access to the cache is sprinkled through most of the workbuf list
operations and it requires special care to transform into and back out
of the gcWork cache that's actually used for scanning and marking. It
requires atomic exchanges to take ownership of the cached workbuf and
to return it to the M's cache even though it's almost always used by
only the current M. Since it's per-M, flushing these caches is O(# of
Ms), which may be high. And it has some significant subtleties: for
example, in general the cache shouldn't be used after the
harvestwbufs() in mark termination because it could hide work from
mark termination, but stack scanning can happen after this and *will*
use the cache (but it turns out this is okay because it will always be
followed by a getfull(), which drains the cache).
This change replaces this cache with a per-P gcWork object. This
gcWork cache can be used directly by scanning and marking (as long as
preemption is disabled, which is a general requirement of gcWork).
Since it's per-P, it doesn't require synchronization, which simplifies
things and means the only atomic operations in the write barrier are
occasionally fetching new work buffers and setting a mark bit if the
object isn't already marked. This cache can be flushed in O(# of Ps),
which is generally small. It follows a simple flushing rule: the cache
can be used during any phase, but during mark termination it must be
flushed before allowing preemption. This also makes the dispose during
mutator assist no longer necessary, which eliminates the vast majority
of gcWork dispose calls and reduces contention on the global workbuf
lists. And it's a lot faster on some benchmarks:
benchmark old ns/op new ns/op delta
BenchmarkBinaryTree17 11963668673 11206112763 -6.33%
BenchmarkFannkuch11 2643217136 2649182499 +0.23%
BenchmarkFmtFprintfEmpty 70.4 70.2 -0.28%
BenchmarkFmtFprintfString 364 307 -15.66%
BenchmarkFmtFprintfInt 317 282 -11.04%
BenchmarkFmtFprintfIntInt 512 483 -5.66%
BenchmarkFmtFprintfPrefixedInt 404 380 -5.94%
BenchmarkFmtFprintfFloat 521 479 -8.06%
BenchmarkFmtManyArgs 2164 1894 -12.48%
BenchmarkGobDecode 30366146 22429593 -26.14%
BenchmarkGobEncode 29867472 26663152 -10.73%
BenchmarkGzip 391236616 396779490 +1.42%
BenchmarkGunzip 96639491 96297024 -0.35%
BenchmarkHTTPClientServer 100110 70763 -29.31%
BenchmarkJSONEncode 51866051 52511382 +1.24%
BenchmarkJSONDecode 103813138 86094963 -17.07%
BenchmarkMandelbrot200 4121834 4120886 -0.02%
BenchmarkGoParse 16472789 5879949 -64.31%
BenchmarkRegexpMatchEasy0_32 140 140 +0.00%
BenchmarkRegexpMatchEasy0_1K 394 394 +0.00%
BenchmarkRegexpMatchEasy1_32 120 120 +0.00%
BenchmarkRegexpMatchEasy1_1K 621 614 -1.13%
BenchmarkRegexpMatchMedium_32 209 202 -3.35%
BenchmarkRegexpMatchMedium_1K 54889 55175 +0.52%
BenchmarkRegexpMatchHard_32 2682 2675 -0.26%
BenchmarkRegexpMatchHard_1K 79383 79524 +0.18%
BenchmarkRevcomp 584116718 584595320 +0.08%
BenchmarkTemplate 125400565 109620196 -12.58%
BenchmarkTimeParse 386 387 +0.26%
BenchmarkTimeFormat 580 447 -22.93%
(Best out of 10 runs. The delta of averages is similar.)
This also puts us in a good position to flush these caches when
nearing the end of concurrent marking, which will let us increase the
size of the work buffers while still controlling mark termination
pause time.
Change-Id: I2dd94c8517a19297a98ec280203cccaa58792522
Reviewed-on: https://go-review.googlesource.com/9178
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-19 13:22:20 -06:00
|
|
|
// workbufs.
|
2015-02-12 07:58:25 -07:00
|
|
|
// If the GC asks for some work these are the only routines that
|
2015-10-15 13:44:16 -06:00
|
|
|
// make wbufs available to the GC.
|
2015-02-12 07:58:25 -07:00
|
|
|
|
|
|
|
func (b *workbuf) checknonempty() {
|
|
|
|
if b.nobj == 0 {
|
|
|
|
throw("workbuf is empty")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *workbuf) checkempty() {
|
|
|
|
if b.nobj != 0 {
|
|
|
|
throw("workbuf is not empty")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// getempty pops an empty work buffer off the work.empty list,
|
|
|
|
// allocating new buffers if none are available.
|
|
|
|
//go:nowritebarrier
|
2016-02-25 19:01:16 -07:00
|
|
|
func getempty() *workbuf {
|
2015-02-12 07:58:25 -07:00
|
|
|
var b *workbuf
|
|
|
|
if work.empty != 0 {
|
|
|
|
b = (*workbuf)(lfstackpop(&work.empty))
|
|
|
|
if b != nil {
|
|
|
|
b.checkempty()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if b == nil {
|
2015-11-11 10:39:30 -07:00
|
|
|
b = (*workbuf)(persistentalloc(unsafe.Sizeof(*b), sys.CacheLineSize, &memstats.gc_sys))
|
2015-02-12 07:58:25 -07:00
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// putempty puts a workbuf onto the work.empty list.
|
|
|
|
// Upon entry this go routine owns b. The lfstackpush relinquishes ownership.
|
|
|
|
//go:nowritebarrier
|
2016-02-25 19:01:16 -07:00
|
|
|
func putempty(b *workbuf) {
|
2015-02-12 07:58:25 -07:00
|
|
|
b.checkempty()
|
|
|
|
lfstackpush(&work.empty, &b.node)
|
|
|
|
}
|
|
|
|
|
|
|
|
// putfull puts the workbuf on the work.full list for the GC.
|
|
|
|
// putfull accepts partially full buffers so the GC can avoid competing
|
|
|
|
// with the mutators for ownership of partially full buffers.
|
|
|
|
//go:nowritebarrier
|
2016-02-25 19:01:16 -07:00
|
|
|
func putfull(b *workbuf) {
|
2015-02-12 07:58:25 -07:00
|
|
|
b.checknonempty()
|
|
|
|
lfstackpush(&work.full, &b.node)
|
2015-10-26 15:07:02 -06:00
|
|
|
|
|
|
|
// We just made more work available. Let the GC controller
|
|
|
|
// know so it can encourage more workers to run.
|
|
|
|
if gcphase == _GCmark {
|
|
|
|
gcController.enlistWorker()
|
|
|
|
}
|
2015-02-12 07:58:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// trygetfull tries to get a full or partially empty workbuffer.
|
|
|
|
// If one is not immediately available return nil
|
|
|
|
//go:nowritebarrier
|
2016-02-25 19:01:16 -07:00
|
|
|
func trygetfull() *workbuf {
|
2015-02-12 07:58:25 -07:00
|
|
|
b := (*workbuf)(lfstackpop(&work.full))
|
|
|
|
if b != nil {
|
|
|
|
b.checknonempty()
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2015-10-15 13:44:16 -06:00
|
|
|
// Get a full work buffer off the work.full list.
|
|
|
|
// If nothing is available wait until all the other gc helpers have
|
|
|
|
// finished and then return nil.
|
2015-02-12 07:58:25 -07:00
|
|
|
// getfull acts as a barrier for work.nproc helpers. As long as one
|
|
|
|
// gchelper is actively marking objects it
|
|
|
|
// may create a workbuffer that the other helpers can work on.
|
|
|
|
// The for loop either exits when a work buffer is found
|
|
|
|
// or when _all_ of the work.nproc GC helpers are in the loop
|
|
|
|
// looking for work and thus not capable of creating new work.
|
|
|
|
// This is in fact the termination condition for the STW mark
|
|
|
|
// phase.
|
|
|
|
//go:nowritebarrier
|
2016-02-25 19:01:16 -07:00
|
|
|
func getfull() *workbuf {
|
2015-02-12 07:58:25 -07:00
|
|
|
b := (*workbuf)(lfstackpop(&work.full))
|
|
|
|
if b != nil {
|
|
|
|
b.checknonempty()
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2015-11-02 12:09:24 -07:00
|
|
|
incnwait := atomic.Xadd(&work.nwait, +1)
|
2015-06-01 16:16:03 -06:00
|
|
|
if incnwait > work.nproc {
|
|
|
|
println("runtime: work.nwait=", incnwait, "work.nproc=", work.nproc)
|
|
|
|
throw("work.nwait > work.nproc")
|
|
|
|
}
|
2015-02-12 07:58:25 -07:00
|
|
|
for i := 0; ; i++ {
|
2015-10-15 13:44:16 -06:00
|
|
|
if work.full != 0 {
|
2015-11-02 12:09:24 -07:00
|
|
|
decnwait := atomic.Xadd(&work.nwait, -1)
|
2015-06-01 16:16:03 -06:00
|
|
|
if decnwait == work.nproc {
|
|
|
|
println("runtime: work.nwait=", decnwait, "work.nproc=", work.nproc)
|
|
|
|
throw("work.nwait > work.nproc")
|
|
|
|
}
|
2015-02-12 07:58:25 -07:00
|
|
|
b = (*workbuf)(lfstackpop(&work.full))
|
|
|
|
if b != nil {
|
|
|
|
b.checknonempty()
|
|
|
|
return b
|
|
|
|
}
|
2015-11-02 12:09:24 -07:00
|
|
|
incnwait := atomic.Xadd(&work.nwait, +1)
|
2015-06-01 16:16:03 -06:00
|
|
|
if incnwait > work.nproc {
|
|
|
|
println("runtime: work.nwait=", incnwait, "work.nproc=", work.nproc)
|
|
|
|
throw("work.nwait > work.nproc")
|
|
|
|
}
|
2015-02-12 07:58:25 -07:00
|
|
|
}
|
runtime: perform concurrent scan in GC workers
Currently the concurrent root scan is performed in its entirety by the
GC coordinator before entering concurrent mark (which enables GC
workers). This scan is done sequentially, which can prolong the scan
phase, delay the mark phase, and means that the scan phase does not
obey the 25% CPU goal. Furthermore, there's no need to complete the
root scan before starting marking (in fact, we already allow GC
assists to happen during the scan phase), so this acts as an
unnecessary barrier between root scanning and marking.
This change shifts the root scan work out of the GC coordinator and in
to the GC workers. The coordinator simply sets up the scan state and
enqueues the right number of root scan jobs. The GC workers then drain
the root scan jobs prior to draining heap scan jobs.
This parallelizes the root scan process, makes it obey the 25% CPU
goal, and effectively eliminates root scanning as an isolated phase,
allowing the system to smoothly transition from root scanning to heap
marking. This also eliminates a major non-STW responsibility of the GC
coordinator, which will make it easier to switch to a decentralized
state machine. Finally, it puts us in a good position to perform root
scanning in assists as well, which will help satisfy assists at the
beginning of the GC cycle.
This is mostly straightforward. One tricky aspect is that we have to
deal with preemption deadlock: where two non-preemptible gorountines
are trying to preempt each other to perform a stack scan. Given the
context where this happens, the only instance of this is two
background workers trying to scan each other. We avoid this by simply
not scanning the stacks of background workers during the concurrent
phase; this is safe because we'll scan them during mark termination
(and their stacks are *very* small and should not contain any new
pointers).
This change also switches the root marking during mark termination to
use the same gcDrain-based code path as concurrent mark. This
shouldn't affect performance because STW root marking was already
parallel and tasks switched to heap marking immediately when no more
root marking tasks were available. However, it simplifies the code and
unifies these code paths.
This has negligible effect on the go1 benchmarks. It slightly slows
down the garbage benchmark, possibly by making GC run slightly more
frequently.
name old time/op new time/op delta
XBenchGarbage-12 5.10ms ± 1% 5.24ms ± 1% +2.87% (p=0.000 n=18+18)
name old time/op new time/op delta
BinaryTree17-12 3.25s ± 3% 3.20s ± 5% -1.57% (p=0.013 n=20+20)
Fannkuch11-12 2.45s ± 1% 2.46s ± 1% +0.38% (p=0.019 n=20+18)
FmtFprintfEmpty-12 49.7ns ± 3% 49.9ns ± 4% ~ (p=0.851 n=19+20)
FmtFprintfString-12 170ns ± 2% 170ns ± 1% ~ (p=0.775 n=20+19)
FmtFprintfInt-12 161ns ± 1% 160ns ± 1% -0.78% (p=0.000 n=19+18)
FmtFprintfIntInt-12 267ns ± 1% 270ns ± 1% +1.04% (p=0.000 n=19+19)
FmtFprintfPrefixedInt-12 238ns ± 2% 238ns ± 1% ~ (p=0.133 n=18+19)
FmtFprintfFloat-12 311ns ± 1% 310ns ± 2% -0.35% (p=0.023 n=20+19)
FmtManyArgs-12 1.08µs ± 1% 1.06µs ± 1% -2.31% (p=0.000 n=20+20)
GobDecode-12 8.65ms ± 1% 8.63ms ± 1% ~ (p=0.377 n=18+20)
GobEncode-12 6.49ms ± 1% 6.52ms ± 1% +0.37% (p=0.015 n=20+20)
Gzip-12 319ms ± 3% 318ms ± 1% ~ (p=0.975 n=19+17)
Gunzip-12 41.9ms ± 1% 42.1ms ± 2% +0.65% (p=0.004 n=19+20)
HTTPClientServer-12 61.7µs ± 1% 62.6µs ± 1% +1.40% (p=0.000 n=18+20)
JSONEncode-12 16.8ms ± 1% 16.9ms ± 1% ~ (p=0.239 n=20+18)
JSONDecode-12 58.4ms ± 1% 60.7ms ± 1% +3.85% (p=0.000 n=19+20)
Mandelbrot200-12 3.86ms ± 0% 3.86ms ± 1% ~ (p=0.092 n=18+19)
GoParse-12 3.75ms ± 2% 3.75ms ± 2% ~ (p=0.708 n=19+20)
RegexpMatchEasy0_32-12 100ns ± 1% 100ns ± 2% +0.60% (p=0.010 n=17+20)
RegexpMatchEasy0_1K-12 341ns ± 1% 342ns ± 2% ~ (p=0.203 n=20+19)
RegexpMatchEasy1_32-12 82.5ns ± 2% 83.2ns ± 2% +0.83% (p=0.007 n=19+19)
RegexpMatchEasy1_1K-12 495ns ± 1% 495ns ± 2% ~ (p=0.970 n=19+18)
RegexpMatchMedium_32-12 130ns ± 2% 130ns ± 2% +0.59% (p=0.039 n=19+20)
RegexpMatchMedium_1K-12 39.2µs ± 1% 39.3µs ± 1% ~ (p=0.214 n=18+18)
RegexpMatchHard_32-12 2.03µs ± 2% 2.02µs ± 1% ~ (p=0.166 n=18+19)
RegexpMatchHard_1K-12 61.0µs ± 1% 60.9µs ± 1% ~ (p=0.169 n=20+18)
Revcomp-12 533ms ± 1% 535ms ± 1% ~ (p=0.071 n=19+17)
Template-12 68.1ms ± 2% 73.0ms ± 1% +7.26% (p=0.000 n=19+20)
TimeParse-12 355ns ± 2% 356ns ± 2% ~ (p=0.530 n=19+20)
TimeFormat-12 357ns ± 2% 347ns ± 1% -2.59% (p=0.000 n=20+19)
[Geo mean] 62.1µs 62.3µs +0.31%
name old speed new speed delta
GobDecode-12 88.7MB/s ± 1% 88.9MB/s ± 1% ~ (p=0.377 n=18+20)
GobEncode-12 118MB/s ± 1% 118MB/s ± 1% -0.37% (p=0.015 n=20+20)
Gzip-12 60.9MB/s ± 3% 60.9MB/s ± 1% ~ (p=0.944 n=19+17)
Gunzip-12 464MB/s ± 1% 461MB/s ± 2% -0.64% (p=0.004 n=19+20)
JSONEncode-12 115MB/s ± 1% 115MB/s ± 1% ~ (p=0.236 n=20+18)
JSONDecode-12 33.2MB/s ± 1% 32.0MB/s ± 1% -3.71% (p=0.000 n=19+20)
GoParse-12 15.5MB/s ± 2% 15.5MB/s ± 2% ~ (p=0.702 n=19+20)
RegexpMatchEasy0_32-12 320MB/s ± 1% 318MB/s ± 2% ~ (p=0.094 n=18+20)
RegexpMatchEasy0_1K-12 3.00GB/s ± 1% 2.99GB/s ± 1% ~ (p=0.194 n=20+19)
RegexpMatchEasy1_32-12 388MB/s ± 2% 385MB/s ± 2% -0.83% (p=0.008 n=19+19)
RegexpMatchEasy1_1K-12 2.07GB/s ± 1% 2.07GB/s ± 1% ~ (p=0.964 n=19+18)
RegexpMatchMedium_32-12 7.68MB/s ± 1% 7.64MB/s ± 2% -0.57% (p=0.020 n=19+20)
RegexpMatchMedium_1K-12 26.1MB/s ± 1% 26.1MB/s ± 1% ~ (p=0.211 n=18+18)
RegexpMatchHard_32-12 15.8MB/s ± 1% 15.8MB/s ± 1% ~ (p=0.180 n=18+19)
RegexpMatchHard_1K-12 16.8MB/s ± 1% 16.8MB/s ± 2% ~ (p=0.236 n=20+19)
Revcomp-12 477MB/s ± 1% 475MB/s ± 1% ~ (p=0.071 n=19+17)
Template-12 28.5MB/s ± 2% 26.6MB/s ± 1% -6.77% (p=0.000 n=19+20)
[Geo mean] 100MB/s 99.0MB/s -0.82%
Change-Id: I875bf6ceb306d1ee2f470cabf88aa6ede27c47a0
Reviewed-on: https://go-review.googlesource.com/16059
Reviewed-by: Rick Hudson <rlh@golang.org>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-10-19 11:46:32 -06:00
|
|
|
if work.nwait == work.nproc && work.markrootNext >= work.markrootJobs {
|
2015-02-12 07:58:25 -07:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
_g_ := getg()
|
|
|
|
if i < 10 {
|
|
|
|
_g_.m.gcstats.nprocyield++
|
|
|
|
procyield(20)
|
|
|
|
} else if i < 20 {
|
|
|
|
_g_.m.gcstats.nosyield++
|
|
|
|
osyield()
|
|
|
|
} else {
|
|
|
|
_g_.m.gcstats.nsleep++
|
|
|
|
usleep(100)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nowritebarrier
|
|
|
|
func handoff(b *workbuf) *workbuf {
|
|
|
|
// Make new buffer with half of b's pointers.
|
2016-02-25 19:01:16 -07:00
|
|
|
b1 := getempty()
|
2015-02-12 07:58:25 -07:00
|
|
|
n := b.nobj / 2
|
|
|
|
b.nobj -= n
|
|
|
|
b1.nobj = n
|
2015-02-18 19:56:12 -07:00
|
|
|
memmove(unsafe.Pointer(&b1.obj[0]), unsafe.Pointer(&b.obj[b.nobj]), uintptr(n)*unsafe.Sizeof(b1.obj[0]))
|
2015-02-12 07:58:25 -07:00
|
|
|
_g_ := getg()
|
|
|
|
_g_.m.gcstats.nhandoff++
|
|
|
|
_g_.m.gcstats.nhandoffcnt += uint64(n)
|
|
|
|
|
|
|
|
// Put b on full list - let first half of b get stolen.
|
2016-02-25 19:01:16 -07:00
|
|
|
putfull(b)
|
2015-02-12 07:58:25 -07:00
|
|
|
return b1
|
|
|
|
}
|