]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: free stacks of Gdead goroutines at GC time
authorKeith Randall <khr@golang.org>
Wed, 17 Sep 2014 20:25:46 +0000 (13:25 -0700)
committerKeith Randall <khr@golang.org>
Wed, 17 Sep 2014 20:25:46 +0000 (13:25 -0700)
We could probably free the G structures as well, but
for the allg list.  Leaving that for another day.

Fixes #8287

LGTM=rsc
R=golang-codereviews, dvyukov, khr, rsc
CC=golang-codereviews
https://golang.org/cl/145010043

src/runtime/stack.c

index b38ee31d48eb8f51ac555a3956df906d4f660cce..95a5a123d917b378920f16ddb2bf97bdea6d829d 100644 (file)
@@ -806,8 +806,16 @@ runtime·shrinkstack(G *gp)
 {
        uintptr used, oldsize, newsize;
 
-       if(runtime·readgstatus(gp) == Gdead)
+       if(runtime·readgstatus(gp) == Gdead) {
+               if(gp->stack.lo != 0) {
+                       // Free whole stack - it will get reallocated
+                       // if G is used again.
+                       runtime·stackfree(gp->stack);
+                       gp->stack.lo = 0;
+                       gp->stack.hi = 0;
+               }
                return;
+       }
        if(gp->stack.lo == 0)
                runtime·throw("missing stack in shrinkstack");