mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: fix memory leak in parallel garbage collector
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
This commit is contained in:
parent
af1232fe38
commit
8219cc9af8
3 changed files with 29 additions and 1 deletions
24
src/pkg/runtime/gc_test.go
Normal file
24
src/pkg/runtime/gc_test.go
Normal file
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
@ -501,7 +501,7 @@ putempty(Workbuf *b)
|
||||||
|
|
||||||
runtime·lock(&work.emu);
|
runtime·lock(&work.emu);
|
||||||
b->next = work.empty;
|
b->next = work.empty;
|
||||||
work.empty = b->next;
|
work.empty = b;
|
||||||
runtime·unlock(&work.emu);
|
runtime·unlock(&work.emu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,10 @@ fi
|
||||||
gomake testshort
|
gomake testshort
|
||||||
) || exit $?
|
) || exit $?
|
||||||
|
|
||||||
|
(xcd pkg/runtime;
|
||||||
|
gotest -short -cpu=1,2,4
|
||||||
|
) || exit $?
|
||||||
|
|
||||||
(xcd pkg/sync;
|
(xcd pkg/sync;
|
||||||
GOMAXPROCS=10 gomake testshort
|
GOMAXPROCS=10 gomake testshort
|
||||||
) || exit $?
|
) || exit $?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue