runtime: preempt goroutines for GC
The last patch for preemptive scheduler,
with this change stoptheworld issues preemption
requests every 100us.
Update issue 543.
Is this intended for go 1.2? I haven't seen its inclusion mentioned anywhere. I'll take ...
11 years, 7 months ago
(2013-06-17 11:54:24 UTC)
#4
Is this intended for go 1.2? I haven't seen its inclusion mentioned anywhere.
I'll take a closer look later, but initial thoughts are that it would be a good
idea to add a compile-time debug flag. Preemption is a big change to our current
execution model and a flag will help once we start debugging after the freeze.
On Mon, Jun 17, 2013 at 3:54 PM, <daniel.morsing@gmail.com> wrote: > Is this intended for ...
11 years, 7 months ago
(2013-06-17 12:01:31 UTC)
#5
On Mon, Jun 17, 2013 at 3:54 PM, <daniel.morsing@gmail.com> wrote:
> Is this intended for go 1.2? I haven't seen its inclusion mentioned
> anywhere.
Yes, it's for Go1.2 and I believe it was mentioned in few places.
There was a discussion about design on golang-dev. And it should be in
Russ' Go1.2. list of big things.
> I'll take a closer look later, but initial thoughts are that it would be
> a good idea to add a compile-time debug flag. Preemption is a big change
> to our current execution model and a flag will help once we start
> debugging after the freeze.
It's easy to turn off in source code. But if we will need to tell
people to turn it off and retest their crashing programs, then a const
in runtime.h will be definitely better. Will do.
On Mon, Jun 17, 2013 at 4:05 PM, Russ Cox <rsc@golang.org> wrote: > Does this ...
11 years, 7 months ago
(2013-06-17 12:07:47 UTC)
#7
On Mon, Jun 17, 2013 at 4:05 PM, Russ Cox <rsc@golang.org> wrote:
> Does this depend on any other pending CLs, or are all its prerequisites
> submitted already?
All prerequisites are submitted. It includes a test that requires
preemption and it passes with this change.
I'm very happy to see this coming to completion, and I will review this CL. ...
11 years, 7 months ago
(2013-06-17 12:31:03 UTC)
#8
I'm very happy to see this coming to completion, and I will review this CL.
However, Rob and I keep running into mysterious runtime behaviors that need
to be fixed before we can make more changes. I am afraid that the runtime
is starting to spiral out of control, and we need to steady it a bit before
making more changes. See golang.org/issue/5723 for details.
Russ
There is one functionality that was there, but I don't know yet how to implement ...
11 years, 7 months ago
(2013-06-27 18:12:10 UTC)
#11
There is one functionality that was there, but I don't know yet how to implement
it now:
If newstack finds gp->stackguard0 == StackPreempt, but it can not be preempted
right now (m->locks != 0), then newstack lefts gp->stackguard0 == StackPreempt.
Then the goroutine will try to preempt itself on the next split stack check.
Currently the goroutine retries from function beginning after morestack, so I
can not leave StackPreempt (will cause infinite loop).
On 2013/06/27 18:12:10, dvyukov wrote: > There is one functionality that was there, but I ...
11 years, 7 months ago
(2013-06-27 19:17:06 UTC)
#12
On 2013/06/27 18:12:10, dvyukov wrote:
> There is one functionality that was there, but I don't know yet how to
implement
> it now:
> If newstack finds gp->stackguard0 == StackPreempt, but it can not be preempted
> right now (m->locks != 0), then newstack lefts gp->stackguard0 ==
StackPreempt.
> Then the goroutine will try to preempt itself on the next split stack check.
> Currently the goroutine retries from function beginning after morestack, so I
> can not leave StackPreempt (will cause infinite loop).
You could put it back when m->locks reaches 0.
Russ
On Thu, Jun 27, 2013 at 11:17 PM, <rsc@golang.org> wrote: > On 2013/06/27 18:12:10, dvyukov ...
11 years, 7 months ago
(2013-06-27 19:47:51 UTC)
#14
On Thu, Jun 27, 2013 at 11:17 PM, <rsc@golang.org> wrote:
> On 2013/06/27 18:12:10, dvyukov wrote:
>>
>> There is one functionality that was there, but I don't know yet how to
>
> implement
>>
>> it now:
>> If newstack finds gp->stackguard0 == StackPreempt, but it can not be
>
> preempted
>>
>> right now (m->locks != 0), then newstack lefts gp->stackguard0 ==
>
> StackPreempt.
>>
>> Then the goroutine will try to preempt itself on the next split stack
>
> check.
>>
>> Currently the goroutine retries from function beginning after
>
> morestack, so I
>>
>> can not leave StackPreempt (will cause infinite loop).
>
>
> You could put it back when m->locks reaches 0.
That's what I've tried to avoid -- additional checks on fast paths
(malloc, lock/unlock, etc)...
I will think a bit more, and then probably will do as you suggest.
This issue it not blocking this CL.
https://codereview.appspot.com/10264044/diff/30001/src/pkg/runtime/stack.c File src/pkg/runtime/stack.c (right): https://codereview.appspot.com/10264044/diff/30001/src/pkg/runtime/stack.c#newcode200 src/pkg/runtime/stack.c:200: How about, right here, // If we are preempted ...
11 years, 7 months ago
(2013-06-27 20:00:41 UTC)
#16
https://codereview.appspot.com/10264044/diff/30001/src/pkg/runtime/stack.c
File src/pkg/runtime/stack.c (right):
https://codereview.appspot.com/10264044/diff/30001/src/pkg/runtime/stack.c#ne...
src/pkg/runtime/stack.c:200:
How about, right here,
// If we are preempted during work on behalf of a system call, ignore.
if(gp->stackguard0 == StackPreempt && gp->status != Grunning) {
gp->stackguard0 = gp->stackguard;
runtime.gogo(&gp->sched);
}
Doing that very early means that we should be able to drop oldstatus, and the
possibility that m->p == nil, and the possibility that m->p->status != Prunning,
right?
I sent you a CL so that this is safe even in the reflectcall case.
https://codereview.appspot.com/10264044/diff/30001/src/pkg/runtime/stack.c File src/pkg/runtime/stack.c (right): https://codereview.appspot.com/10264044/diff/30001/src/pkg/runtime/stack.c#newcode200 src/pkg/runtime/stack.c:200: To be clear, what I meant by "safe" is ...
11 years, 7 months ago
(2013-06-27 20:20:17 UTC)
#17
https://codereview.appspot.com/10264044/diff/30001/src/pkg/runtime/stack.c
File src/pkg/runtime/stack.c (right):
https://codereview.appspot.com/10264044/diff/30001/src/pkg/runtime/stack.c#ne...
src/pkg/runtime/stack.c:200:
To be clear, what I meant by "safe" is that it's always legal to
runtime.gogo(&gp->sched) to back out of a newstack. You would still need to
figure out what conditions need to be backed out of quickly. But I think doing
the check here at the very top, before we touch anything else like gp->status,
will keep the rest of the code clean.
https://codereview.appspot.com/10264044/diff/30001/src/pkg/runtime/stack.c#ne...
src/pkg/runtime/stack.c:238: if(gp->stackguard0 == StackPreempt) {
The actual preemption can still happen here, in the case where we have an
ordinary running goroutine. No magic necessary.
if(gp->stackguard0 == StackPreempt) {
gp->stackguard = gp->stackguard0;
if(gp == m->g0)
runtime.throw("runtime: preempt g0");
gp->status = oldstatus;
if(m->locks == 0 || m->mallocing == 0 || m->gcing == 0) {
// Remember but delay the preemption.
// Let the goroutine keep running for now.
m->preempt = 1;
runtime.gogo(&gp->sched);
}
// Act like goroutine called runtime.Gosched.
// Does not return.
runtime.gosched0(sp);
}
https://codereview.appspot.com/10264044/diff/45002/src/pkg/runtime/proc_test.go File src/pkg/runtime/proc_test.go (right): https://codereview.appspot.com/10264044/diff/45002/src/pkg/runtime/proc_test.go#newcode160 src/pkg/runtime/proc_test.go:160: // The function is used to test preemption at ...
11 years, 7 months ago
(2013-06-27 21:10:45 UTC)
#20
Issue 10264044: code review 10264044: runtime: preempt goroutines for GC
(Closed)
Created 11 years, 7 months ago by dvyukov
Modified 11 years, 7 months ago
Reviewers:
Base URL:
Comments: 13