Commit f3bb4cbf authored by Austin Clements's avatar Austin Clements

runtime: eliminate gosweepone

gosweepone just switches to the system stack and calls sweepone.
sweepone doesn't need to run on the system stack, so this is pretty
pointless.

Historically, this was necessary because the sweeper was written in C
and hence needed to run on the system stack. gosweepone was the
function that Go code (specifically, bgsweep) used to call into the C
sweeper implementation. This probably became unnecessary in 2014 with
CL golang.org/cl/167540043, which ported the sweeper to Go.

This CL changes all callers of gosweepone to call sweepone and
eliminates gosweepone.

Change-Id: I26b8ef0c7d060b4c0c5dedbb25ecfc936acc7269
Reviewed-on: https://go-review.googlesource.com/c/138657
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 416804f3
...@@ -1061,7 +1061,7 @@ func GC() { ...@@ -1061,7 +1061,7 @@ func GC() {
// complete the cycle and because runtime.GC() is often used // complete the cycle and because runtime.GC() is often used
// as part of tests and benchmarks to get the system into a // as part of tests and benchmarks to get the system into a
// relatively stable and isolated state. // relatively stable and isolated state.
for atomic.Load(&work.cycles) == n+1 && gosweepone() != ^uintptr(0) { for atomic.Load(&work.cycles) == n+1 && sweepone() != ^uintptr(0) {
sweep.nbgsweep++ sweep.nbgsweep++
Gosched() Gosched()
} }
...@@ -1219,7 +1219,7 @@ func gcStart(trigger gcTrigger) { ...@@ -1219,7 +1219,7 @@ func gcStart(trigger gcTrigger) {
// //
// We check the transition condition continuously here in case // We check the transition condition continuously here in case
// this G gets delayed in to the next GC cycle. // this G gets delayed in to the next GC cycle.
for trigger.test() && gosweepone() != ^uintptr(0) { for trigger.test() && sweepone() != ^uintptr(0) {
sweep.nbgsweep++ sweep.nbgsweep++
} }
......
...@@ -52,7 +52,7 @@ func bgsweep(c chan int) { ...@@ -52,7 +52,7 @@ func bgsweep(c chan int) {
goparkunlock(&sweep.lock, waitReasonGCSweepWait, traceEvGoBlock, 1) goparkunlock(&sweep.lock, waitReasonGCSweepWait, traceEvGoBlock, 1)
for { for {
for gosweepone() != ^uintptr(0) { for sweepone() != ^uintptr(0) {
sweep.nbgsweep++ sweep.nbgsweep++
Gosched() Gosched()
} }
...@@ -72,9 +72,8 @@ func bgsweep(c chan int) { ...@@ -72,9 +72,8 @@ func bgsweep(c chan int) {
} }
} }
// sweeps one span // sweepone sweeps one span and returns the number of pages returned
// returns number of pages returned to heap, or ^uintptr(0) if there is nothing to sweep // to the heap, or ^uintptr(0) if there was nothing to sweep.
//go:nowritebarrier
func sweepone() uintptr { func sweepone() uintptr {
_g_ := getg() _g_ := getg()
sweepRatio := mheap_.sweepPagesPerByte // For debugging sweepRatio := mheap_.sweepPagesPerByte // For debugging
...@@ -135,15 +134,6 @@ func sweepone() uintptr { ...@@ -135,15 +134,6 @@ func sweepone() uintptr {
return npages return npages
} }
//go:nowritebarrier
func gosweepone() uintptr {
var ret uintptr
systemstack(func() {
ret = sweepone()
})
return ret
}
//go:nowritebarrier //go:nowritebarrier
func gosweepdone() bool { func gosweepdone() bool {
return mheap_.sweepdone != 0 return mheap_.sweepdone != 0
...@@ -414,7 +404,7 @@ retry: ...@@ -414,7 +404,7 @@ retry:
newHeapLive := uintptr(atomic.Load64(&memstats.heap_live)-mheap_.sweepHeapLiveBasis) + spanBytes newHeapLive := uintptr(atomic.Load64(&memstats.heap_live)-mheap_.sweepHeapLiveBasis) + spanBytes
pagesTarget := int64(mheap_.sweepPagesPerByte*float64(newHeapLive)) - int64(callerSweepPages) pagesTarget := int64(mheap_.sweepPagesPerByte*float64(newHeapLive)) - int64(callerSweepPages)
for pagesTarget > int64(atomic.Load64(&mheap_.pagesSwept)-sweptBasis) { for pagesTarget > int64(atomic.Load64(&mheap_.pagesSwept)-sweptBasis) {
if gosweepone() == ^uintptr(0) { if sweepone() == ^uintptr(0) {
mheap_.sweepPagesPerByte = 0 mheap_.sweepPagesPerByte = 0
break break
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment