]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid a bit of unneeded work when MemProfileRate==1
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 3 Jun 2020 18:03:22 +0000 (11:03 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 5 Nov 2020 16:43:34 +0000 (16:43 +0000)
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>
src/runtime/malloc.go

index 551acd0796902e60a2387a4a28680eb10b018074..f20ded5bf71ebb9f99f478ce4e8a3018524029a7 100644 (file)
@@ -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 {