]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix memory leak in parallel garbage collector
authorRuss Cox <rsc@golang.org>
Wed, 12 Oct 2011 17:23:34 +0000 (13:23 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 12 Oct 2011 17:23:34 +0000 (13:23 -0400)
The work buffer management used by the garbage
collector during parallel collections leaks buffers.
This CL tests for and fixes the leak.

R=golang-dev, dvyukov, r
CC=golang-dev
https://golang.org/cl/5254059

src/pkg/runtime/gc_test.go [new file with mode: 0644]
src/pkg/runtime/mgc0.c
src/run.bash

diff --git a/src/pkg/runtime/gc_test.go b/src/pkg/runtime/gc_test.go
new file mode 100644 (file)
index 0000000..fad60a3
--- /dev/null
@@ -0,0 +1,24 @@
+package runtime_test
+
+import (
+       "runtime"
+       "testing"
+)
+
+func TestGcSys(t *testing.T) {
+       for i := 0; i < 1000000; i++ {
+               workthegc()
+       }
+
+       // Should only be using a few MB.
+       runtime.UpdateMemStats()
+       sys := runtime.MemStats.Sys
+       t.Logf("using %d MB", sys>>20)
+       if sys > 10e6 {
+               t.Fatalf("using too much memory: %d MB", sys>>20)
+       }
+}
+
+func workthegc() []byte {
+       return make([]byte, 1029)
+}
index 6f7e2459d9d6c791fca64a91daf4a0898aa128bd..89bad668fec33c8af5b5f3dade4b657aea52612b 100644 (file)
@@ -501,7 +501,7 @@ putempty(Workbuf *b)
 
        runtimeĀ·lock(&work.emu);
        b->next = work.empty;
-       work.empty = b->next;
+       work.empty = b;
        runtimeĀ·unlock(&work.emu);
 }
 
index d3d2c69bf5afab1607ab8a99740ea643c4adb93e..927e193e0ab10a5f63a3ca7909dfe1319e2048b1 100755 (executable)
@@ -41,6 +41,10 @@ fi
 gomake testshort
 ) || exit $?
 
+(xcd pkg/runtime;
+gotest -short -cpu=1,2,4
+) || exit $?
+
 (xcd pkg/sync;
 GOMAXPROCS=10 gomake testshort
 ) || exit $?