diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2022-03-19 21:46:12 +0000 |
|---|---|---|
| committer | Michael Knyszek <mknyszek@google.com> | 2022-05-03 15:12:12 +0000 |
| commit | 85d466493dc5b46228440fcb3dafacf4556101e6 (patch) | |
| tree | 8d9e7d56cc0048186a172609c3a70086f222cb32 /src/runtime/mgcsweep.go | |
| parent | 986a31053d1cdb866153b44b6defa9f0400c4d4b (diff) | |
| download | go-85d466493dc5b46228440fcb3dafacf4556101e6.tar.xz | |
runtime: maintain a direct count of total allocs and frees
This will be used by the memory limit computation to determine
overheads.
For #48409.
Change-Id: Iaa4e26e1e6e46f88d10ba8ebb6b001be876dc5cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/394220
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/mgcsweep.go')
| -rw-r--r-- | src/runtime/mgcsweep.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go index a5e04d6ce6..365e21e35e 100644 --- a/src/runtime/mgcsweep.go +++ b/src/runtime/mgcsweep.go @@ -666,6 +666,9 @@ func (sl *sweepLocked) sweep(preserve bool) bool { stats := memstats.heapStats.acquire() atomic.Xadduintptr(&stats.smallFreeCount[spc.sizeclass()], uintptr(nfreed)) memstats.heapStats.release() + + // Count the frees in the inconsistent, internal stats. + memstats.totalFree.Add(int64(nfreed) * int64(s.elemsize)) } if !preserve { // The caller may not have removed this span from whatever @@ -710,10 +713,16 @@ func (sl *sweepLocked) sweep(preserve bool) bool { } else { mheap_.freeSpan(s) } + + // Count the free in the consistent, external stats. stats := memstats.heapStats.acquire() atomic.Xadduintptr(&stats.largeFreeCount, 1) atomic.Xadduintptr(&stats.largeFree, size) memstats.heapStats.release() + + // Count the free in the inconsistent, internal stats. + memstats.totalFree.Add(int64(size)) + return true } |
