runtime: reset mark state before stopping the world
runtime: reset mark state before stopping the world

Currently we reset the mark state during STW sweep termination. This
involves looping over all of the goroutines. Each iteration of this
loop takes ~25ns, so at around 400k goroutines, we'll exceed our 10ms
pause goal.

However, it's safe to do this before we stop the world for sweep
termination because nothing is consuming this state yet. Hence, move
the reset to just before STW.

This isn't perfect: a long reset can still delay allocating goroutines
that block on GC starting. But it's certainly better to block some
things eventually than to block everything immediately.

For 1.6.x.

Fixes #14420.

name \ 95%ile-time/sweepTerm           old          new  delta
500kIdleGs-12                 11312µs ± 6%  18.9µs ± 6%  -99.83%  (p=0.000 n=16+20)

Change-Id: I9815c4d8d9b0d3c3e94dfdab78049cefe0dcc93c
Reviewed-on: https://go-review.googlesource.com/20147
Reviewed-by: Rick Hudson <838bd060584c511f21c75c69ea04b7b120d86af0@golang.org>
Run-TryBot: Austin Clements <7ea35d812706d9213868749011af1ed4fa2f6aa0@google.com>
TryBot-Result: Gobot Gobot <66cb808b70d30c07676d5e946fee83fd561249e5@golang.org>

golang/go,ganboing/go-esx,CAFxX/go,linux-on-ibm-z/go,christopher-henderson/Go,codestation/go,4ad/go,CAFxX/go,ImJasonH/go,vsekhar/elastic-go,miolini/go,miolini/go,akutz/go,Samurais/go,theif519/go,ImJasonH/go,theif519/go,CAFxX/go,nawawi/go,akutz/go,cloudflare/go,vsekhar/elastic-go,golang/go,suncycheng/go,josharian/go,theif519/go,miolini/go,josharian/go,nawawi/go,4ad/go,Cofyc/go,suncycheng/go,theif519/go,linux-on-ibm-z/go,CAFxX/go,polyverse-security/go,golang/go,josharian/go,linux-on-ibm-z/go,akutz/go,derekmarcotte/go,theif519/go,goodlang/good,cloudflare/go,momchil-velikov/go,josharian/go,4ad/go,momchil-velikov/go,ganboing/go-esx,suncycheng/go,Cofyc/go,vanloswang/go,4ad/go,vsekhar/elastic-go,goodlang/good,nawawi/go,ImJasonH/go,ganboing/go-esx,momchil-velikov/go,momchil-velikov/go,Cofyc/go,derekmarcotte/go,vanloswang/go,ganboing/go-esx,miolini/go,josharian/go,derekmarcotte/go,Samurais/go,akutz/go,suncycheng/go,ImJasonH/go,nawawi/go,nawawi/go,CAFxX/go,goodlang/good,derekmarcotte/go,vsekhar/elastic-go,Cofyc/go,josharian/go,akutz/go,miolini/go,linux-on-ibm-z/go,cloudflare/go,codestation/go,golang/go,Samurais/go,josharian/go,4ad/go,miolini/go,nawawi/go,goodlang/good,codestation/go,polyverse-security/go,codestation/go,Samurais/go,ganboing/go-esx,linux-on-ibm-z/go,CAFxX/go,Cofyc/go,polyverse-security/go,goodlang/good,vsekhar/elastic-go,ImJasonH/go,4ad/go,ganboing/go-esx,vanloswang/go,miolini/go,Cofyc/go,akutz/go,momchil-velikov/go,Samurais/go,CAFxX/go,polyverse-security/go,vanloswang/go,goodlang/good,codestation/go,nawawi/go,josharian/go,nawawi/go,ImJasonH/go,polyverse-security/go,vanloswang/go,theif519/go,derekmarcotte/go,momchil-velikov/go,suncycheng/go,vanloswang/go,Samurais/go,Cofyc/go,linux-on-ibm-z/go,CAFxX/go,codestation/go,Samurais/go,linux-on-ibm-z/go,golang/go,suncycheng/go,vsekhar/elastic-go,miolini/go,vanloswang/go,polyverse-security/go,codestation/go,akutz/go,akutz/go,polyverse-security/go,cloudflare/go,derekmarcotte/go,goodlang/good,suncycheng/go,momchil-velikov/go,golang/go,ImJasonH/go,vsekhar/elastic-go,4ad/go,cloudflare/go,cloudflare/go,derekmarcotte/go,suncycheng/go,theif519/go,golang/go,cloudflare/go,theif519/go,4ad/go,codestation/go,momchil-velikov/go,linux-on-ibm-z/go,derekmarcotte/go,golang/go,ImJasonH/go,vsekhar/elastic-go,Cofyc/go,vanloswang/go,goodlang/good,ganboing/go-esx,cloudflare/go,Samurais/go,ganboing/go-esx,polyverse-security/go