]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix trigger for concurrent GC
authorRick Hudson <rlh@golang.org>
Tue, 13 Jan 2015 20:36:42 +0000 (15:36 -0500)
committerRick Hudson <rlh@golang.org>
Wed, 21 Jan 2015 21:30:46 +0000 (21:30 +0000)
Adjust triggergc so that we trigger when we have used 7/8
of the available heap memory. Do first collection when we
exceed 4Mbytes.

Change-Id: I467b4335e16dc9cd1521d687fc1f99a51cc7e54b
Reviewed-on: https://go-review.googlesource.com/3149
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/malloc.go
src/runtime/mgc.go

index 223220a570ee97d5ef307488c5cdfb305de08b6f..69eb090706427842f254bf431f7b96ae389c198a 100644 (file)
@@ -31,10 +31,12 @@ type pageID uintptr
 // base address for all 0-byte allocations
 var zerobase uintptr
 
+// Trigger the concurrent GC when 1/triggerratio memory is available to allocate.
+// Adjust this ratio as part of a scheme to ensure that mutators have enough
+// memory to allocate in durring a concurrent GC cycle.
+var triggerratio = int64(8)
+
 // Determine whether to initiate a GC.
-// Currently the primitive heuristic we use will start a new
-// concurrent GC when approximately half the available space
-// made available by the last GC cycle has been used.
 // If the GC is already working no need to trigger another one.
 // This should establish a feedback loop where if the GC does not
 // have sufficient time to complete then more memory will be
@@ -44,7 +46,7 @@ var zerobase uintptr
 // A false negative simple does not start a GC, a false positive
 // will start a GC needlessly. Neither have correctness issues.
 func shouldtriggergc() bool {
-       return memstats.heap_alloc+memstats.heap_alloc*3/4 >= memstats.next_gc && atomicloaduint(&bggc.working) == 0
+       return triggerratio*(int64(memstats.next_gc)-int64(memstats.heap_alloc)) <= int64(memstats.next_gc) && atomicloaduint(&bggc.working) == 0
 }
 
 // Allocate an object of size bytes.
index 32f13d1d4d61ecdefe967e145d4ad596d494cc82..6436a3f786cd179dac53bbd3bb143c7cd8adb902 100644 (file)
@@ -1344,6 +1344,7 @@ func gcinit() {
        gcpercent = readgogc()
        gcdatamask = unrollglobgcprog((*byte)(unsafe.Pointer(&gcdata)), uintptr(unsafe.Pointer(&edata))-uintptr(unsafe.Pointer(&data)))
        gcbssmask = unrollglobgcprog((*byte)(unsafe.Pointer(&gcbss)), uintptr(unsafe.Pointer(&ebss))-uintptr(unsafe.Pointer(&bss)))
+       memstats.next_gc = 4 << 20 // 4 megs to start with
 }
 
 // Called from malloc.go using onM, stopping and starting the world handled in caller.