]> Cypherpunks repositories - gostls13.git/commit
runtime: delay freeing of shrunk stacks until gc is done.
authorKeith Randall <khr@golang.org>
Wed, 8 Oct 2014 22:57:20 +0000 (15:57 -0700)
committerKeith Randall <khr@golang.org>
Wed, 8 Oct 2014 22:57:20 +0000 (15:57 -0700)
commit91e8554b8b9edfb4b05b2c04a50daf4df8ffed7b
tree77e0025cd3fc6f5796a5776603c50e2452407101
parent6920b2a1f93a2ff6876eafc7f8747e82aa59d015
runtime: delay freeing of shrunk stacks until gc is done.

This change prevents confusion in the garbage collector.
The collector wants to make sure that every pointer it finds
isn't junk.  Its criteria for junk is (among others) points
to a "free" span.

Because the stack shrinker modifies pointers in the heap,
there is a race condition between the GC scanner and the
shrinker.  The GC scanner can see old pointers (pointers to
freed stacks).  In particular this happens with SudoG.elem
pointers.

Normally this is not a problem, as pointers into stack spans
are ok.  But if the freed stack is the last one in its span,
the span is marked as "free" instead of "contains stacks".

This change makes sure that even if the GC scanner sees
an old pointer, the span into which it points is still
marked as "contains stacks", and thus the GC doesn't
complain about it.

This change will make the GC pause a tiny bit slower, as
the stack freeing now happens in serial with the mark pause.
We could delay the freeing until the mutators start back up,
but this is the simplest change for now.

TBR=dvyukov
CC=golang-codereviews
https://golang.org/cl/158750043
src/runtime/mgc0.c
src/runtime/runtime.h
src/runtime/stack.c