mirror of
https://github.com/golang/go
synced 2024-11-18 08:14:41 -07:00
runtime: minor clean up to heapminimum
Currently setGCPercent sets heapminimum to heapminimum*GOGC/100. The real intent is to set heapminimum to a scaled multiple of a fixed default heap minimum, not to scale heapminimum based on its current value. This turns out to be okay because setGCPercent is only called once and heapminimum is initially set to this default heap minimum. However, the code as written is confusing, especially since setGCPercent is otherwise written so it could be called again to change GOGC. Fix this by introducing a defaultHeapMinimum constant and using this instead of the current value of heapminimum to compute the scaled heap minimum. As part of this, this commit improves the documentation on heapminimum. Change-Id: I4eb82c73dc2eb44a6e5a17c780a747a2e73d7493 Reviewed-on: https://go-review.googlesource.com/10181 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
8903b3db0e
commit
f4d51eb2f5
@ -127,13 +127,22 @@ const (
|
||||
_RootCount = 5
|
||||
)
|
||||
|
||||
// heapminimum is the minimum number of bytes in the heap.
|
||||
// This cleans up the corner case of where we have a very small live set but a lot
|
||||
// of allocations and collecting every GOGC * live set is expensive.
|
||||
// heapminimum is adjust by multiplying it by GOGC/100. In
|
||||
// the special case of GOGC==0 this will set heapminimum to 0 resulting
|
||||
// collecting at every allocation even when the heap size is small.
|
||||
var heapminimum = uint64(4 << 20)
|
||||
// heapminimum is the minimum heap size at which to trigger GC.
|
||||
// For small heaps, this overrides the usual GOGC*live set rule.
|
||||
//
|
||||
// When there is a very small live set but a lot of allocation, simply
|
||||
// collecting when the heap reaches GOGC*live results in many GC
|
||||
// cycles and high total per-GC overhead. This minimum amortizes this
|
||||
// per-GC overhead while keeping the heap reasonably small.
|
||||
//
|
||||
// During initialization this is set to 4MB*GOGC/100. In the case of
|
||||
// GOGC==0, this will set heapminimum to 0, resulting in constant
|
||||
// collection even when the heap size is small, which is useful for
|
||||
// debugging.
|
||||
var heapminimum uint64 = defaultHeapMinimum
|
||||
|
||||
// defaultHeapMinimum is the value of heapminimum for GOGC==100.
|
||||
const defaultHeapMinimum = 4 << 20
|
||||
|
||||
// Initialized from $GOGC. GOGC=off means no GC.
|
||||
var gcpercent int32
|
||||
@ -180,7 +189,7 @@ func setGCPercent(in int32) (out int32) {
|
||||
in = -1
|
||||
}
|
||||
gcpercent = in
|
||||
heapminimum = heapminimum * uint64(gcpercent) / 100
|
||||
heapminimum = defaultHeapMinimum * uint64(gcpercent) / 100
|
||||
unlock(&mheap_.lock)
|
||||
return out
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user