]> Cypherpunks repositories - gostls13.git/commit
runtime: redefine scavenge goal in terms of heap_inuse
authorMichael Anthony Knyszek <mknyszek@google.com>
Tue, 3 Sep 2019 19:54:32 +0000 (19:54 +0000)
committerMichael Knyszek <mknyszek@google.com>
Wed, 25 Sep 2019 22:15:39 +0000 (22:15 +0000)
commit9b30811280427a6d50d2558f316d62210e948656
treeecffe597a49cb2dfc77f54f812e8f17ed1fe2e02
parent78baea836d9f4312972e50e17dcff15ff63d155b
runtime: redefine scavenge goal in terms of heap_inuse

This change makes it so that the scavenge goal is defined primarily in
terms of heap_inuse at the end of the last GC rather than next_gc. The
reason behind this change is that next_gc doesn't take into account
fragmentation, and we can fall into situation where the scavenger thinks
it should have work to do but there's no free and unscavenged memory
available.

In order to ensure the scavenge goal still tracks next_gc, we multiply
heap_inuse by the ratio between the current heap goal and the last heap
goal, which describes whether the heap is growing or shrinking, and by
how much.

Finally, this change updates the documentation for scavenging and
elaborates on why the scavenge goal is defined the way it is.

Fixes #34048.
Updates #32828.

Change-Id: I8deaf87620b5dc12a40ab8a90bf27932868610da
Reviewed-on: https://go-review.googlesource.com/c/go/+/193040
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/mgc.go
src/runtime/mgcscavenge.go
src/runtime/mstats.go