diff options
| author | Nick Ripley <nick.ripley@datadoghq.com> | 2026-03-27 09:35:51 -0400 |
|---|---|---|
| committer | Nick Ripley <nick.ripley@datadoghq.com> | 2026-03-28 13:07:33 -0700 |
| commit | d247ed00e498e9717fb7c80d126bee5a8afdb4e8 (patch) | |
| tree | 07641e62bb021d5cd34a0ad0a2fc9ea30fbb9c47 /src/runtime/mprof.go | |
| parent | 1fd68799c39bd4a3f7e16a1ee24fcaca3efe5357 (diff) | |
| download | go-d247ed00e498e9717fb7c80d126bee5a8afdb4e8.tar.xz | |
runtime: remove redundant fields from memory profile records
The memProfCycle struct holds allocation counts and bytes allocated, and
frees and bytes freed. But the memory profile records are already
aggregated by allocation size, which is stored in the "size" field of
the bucket struct. We can derive the bytes allocated/freed using the
counts and the size we already store. Thus we can delete the bytes
fields from memProfCycle, saving 64 bytes per memRecord.
We can do something similar for the profilerecord.MemProfileRecord type.
We just need to know the object size and we can derive the allocated and
freed bytes accordingly.
Change-Id: I103885c2f29471b25283e330674fc16d6a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/760140
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/mprof.go')
| -rw-r--r-- | src/runtime/mprof.go | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/runtime/mprof.go b/src/runtime/mprof.go index a4cfef72fa..9ab02fbb30 100644 --- a/src/runtime/mprof.go +++ b/src/runtime/mprof.go @@ -146,16 +146,13 @@ type memRecord struct { // memRecordCycle type memRecordCycle struct { - allocs, frees uintptr - alloc_bytes, free_bytes uintptr + allocs, frees uintptr } // add accumulates b into a. It does not zero b. func (a *memRecordCycle) add(b *memRecordCycle) { a.allocs += b.allocs a.frees += b.frees - a.alloc_bytes += b.alloc_bytes - a.free_bytes += b.free_bytes } // A blockRecord is the bucket data for a bucket of type blockProfile, @@ -453,7 +450,6 @@ func mProf_Malloc(mp *m, p unsafe.Pointer, size uintptr) { lock(&profMemFutureLock[index]) mpc.allocs++ - mpc.alloc_bytes += size unlock(&profMemFutureLock[index]) // Setprofilebucket locks a bunch of other mutexes, so we call it outside of @@ -466,7 +462,7 @@ func mProf_Malloc(mp *m, p unsafe.Pointer, size uintptr) { } // Called when freeing a profiled block. -func mProf_Free(b *bucket, size uintptr) { +func mProf_Free(b *bucket) { index := (mProfCycle.read() + 1) % uint32(len(memRecord{}.future)) mp := b.mp() @@ -474,7 +470,6 @@ func mProf_Free(b *bucket, size uintptr) { lock(&profMemFutureLock[index]) mpc.frees++ - mpc.free_bytes += size unlock(&profMemFutureLock[index]) } @@ -960,7 +955,7 @@ func memProfileInternal(size int, inuseZero bool, copyFn func(profilerecord.MemP head := (*bucket)(mbuckets.Load()) for b := head; b != nil; b = b.allnext { mp := b.mp() - if inuseZero || mp.active.alloc_bytes != mp.active.free_bytes { + if inuseZero || mp.active.allocs != mp.active.frees { n++ } if mp.active.allocs != 0 || mp.active.frees != 0 { @@ -981,7 +976,7 @@ func memProfileInternal(size int, inuseZero bool, copyFn func(profilerecord.MemP mp.future[c] = memRecordCycle{} unlock(&profMemFutureLock[c]) } - if inuseZero || mp.active.alloc_bytes != mp.active.free_bytes { + if inuseZero || mp.active.allocs != mp.active.frees { n++ } } @@ -990,10 +985,9 @@ func memProfileInternal(size int, inuseZero bool, copyFn func(profilerecord.MemP ok = true for b := head; b != nil; b = b.allnext { mp := b.mp() - if inuseZero || mp.active.alloc_bytes != mp.active.free_bytes { + if inuseZero || mp.active.allocs != mp.active.frees { r := profilerecord.MemProfileRecord{ - AllocBytes: int64(mp.active.alloc_bytes), - FreeBytes: int64(mp.active.free_bytes), + ObjectSize: int64(b.size), AllocObjects: int64(mp.active.allocs), FreeObjects: int64(mp.active.frees), Stack: b.stk(), @@ -1007,8 +1001,8 @@ func memProfileInternal(size int, inuseZero bool, copyFn func(profilerecord.MemP } func copyMemProfileRecord(dst *MemProfileRecord, src profilerecord.MemProfileRecord) { - dst.AllocBytes = src.AllocBytes - dst.FreeBytes = src.FreeBytes + dst.AllocBytes = src.AllocObjects * src.ObjectSize + dst.FreeBytes = src.FreeObjects * src.ObjectSize dst.AllocObjects = src.AllocObjects dst.FreeObjects = src.FreeObjects if raceenabled { |
