aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2020-06-03 11:03:22 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2020-11-05 16:43:34 +0000
commit40f0359d52e04ed124a8f81e1ef8ac86957dd983 (patch)
treec54fe0b9d624f5e32660c99d6c3e4b96e966c0ed /src/runtime/malloc.go
parentdb8142fb8631df3ee56983cbc13db997c16f2f6f (diff)
downloadgo-40f0359d52e04ed124a8f81e1ef8ac86957dd983.tar.gz
go-40f0359d52e04ed124a8f81e1ef8ac86957dd983.zip
runtime: avoid a bit of unneeded work when MemProfileRate==1
Change-Id: I1dc355bcaeb0e5fb06a7fddc4cf5db596d22e0b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/236148 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 551acd0796..f20ded5bf7 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -1221,6 +1221,13 @@ func profilealloc(mp *m, x unsafe.Pointer, size uintptr) {
// distribution (exp(MemProfileRate)), so the best return value is a random
// number taken from an exponential distribution whose mean is MemProfileRate.
func nextSample() uintptr {
+ if MemProfileRate == 1 {
+ // Callers assign our return value to
+ // mcache.next_sample, but next_sample is not used
+ // when the rate is 1. So avoid the math below and
+ // just return something.
+ return 0
+ }
if GOOS == "plan9" {
// Plan 9 doesn't support floating point in note handler.
if g := getg(); g == g.m.gsignal {