[go] runtime: call mallocgc directly from makeslice and growslice

127 views
Skip to first unread message

Josh Bleecher Snyder (Gerrit)

unread,
Apr 19, 2016, 6:47:46 PM4/19/16
to Keith Randall, Ian Lance Taylor, Josh Bleecher Snyder, golang-co...@googlegroups.com
Reviewers: Keith Randall

Josh Bleecher Snyder uploaded a change:
https://go-review.googlesource.com/22276

runtime: call mallocgc directly from makeslice and growslice

The extra checks provided by newarray are
redundant in these cases.

This shrinks by one frame the call stack expected
by the pprof test.

name old time/op new time/op delta
MakeSlice-8 34.3ns ± 2% 30.5ns ± 3% -11.03% (p=0.000
n=24+22)
GrowSlicePtr-8 134ns ± 2% 129ns ± 3% -3.25% (p=0.000
n=25+24)

Change-Id: Icd828655906b921c732701fd9d61da3fa217b0af
---
M src/runtime/pprof/mprof_test.go
M src/runtime/slice.go
2 files changed, 8 insertions(+), 3 deletions(-)



diff --git a/src/runtime/pprof/mprof_test.go
b/src/runtime/pprof/mprof_test.go
index d15102c..0fff9d4 100644
--- a/src/runtime/pprof/mprof_test.go
+++ b/src/runtime/pprof/mprof_test.go
@@ -82,7 +82,7 @@
# 0x[0-9,a-f]+
runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:61
`, (1<<10)*memoryProfilerRun, (1<<20)*memoryProfilerRun),

- fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
0x[0-9,a-f]+ 0x[0-9,a-f]+
+ fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
0x[0-9,a-f]+
# 0x[0-9,a-f]+
runtime/pprof_test\.allocateTransient2M\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:27
# 0x[0-9,a-f]+
runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:62
`, memoryProfilerRun, (2<<20)*memoryProfilerRun),
diff --git a/src/runtime/slice.go b/src/runtime/slice.go
index f9414d7..873e97e 100644
--- a/src/runtime/slice.go
+++ b/src/runtime/slice.go
@@ -55,7 +55,12 @@
panic(errorString("makeslice: cap out of range"))
}

- p := newarray(t.elem, uintptr(cap))
+ et := t.elem
+ var flags uint32
+ if et.kind&kindNoPointers != 0 {
+ flags = flagNoScan
+ }
+ p := mallocgc(et.size*uintptr(cap), et, flags)
return slice{p, len, cap}
}

@@ -130,7 +135,7 @@
memclr(add(p, lenmem), capmem-lenmem)
} else {
// Note: can't use rawmem (which avoids zeroing of memory), because then
GC can scan uninitialized memory.
- p = newarray(et, uintptr(newcap))
+ p = mallocgc(capmem, et, 0)
if !writeBarrier.enabled {
memmove(p, old.array, lenmem)
} else {

--
https://go-review.googlesource.com/22276
Gerrit-Reviewer: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>

Gobot Gobot (Gerrit)

unread,
Apr 19, 2016, 6:48:38 PM4/19/16
to Josh Bleecher Snyder, Keith Randall, golang-co...@googlegroups.com
Gobot Gobot has posted comments on this change.

runtime: call mallocgc directly from makeslice and growslice

Patch Set 1:

TryBots beginning. Status page: http://farmer.golang.org/try?commit=26f7931d

--
https://go-review.googlesource.com/22276
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-HasComments: No

Gobot Gobot (Gerrit)

unread,
Apr 19, 2016, 7:10:24 PM4/19/16
to Josh Bleecher Snyder, Keith Randall, golang-co...@googlegroups.com
Gobot Gobot has posted comments on this change.

runtime: call mallocgc directly from makeslice and growslice

Patch Set 1: TryBot-Result+1

TryBots are happy.
Gerrit-Reviewer: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-HasComments: No

Brad Fitzpatrick (Gerrit)

unread,
Apr 19, 2016, 7:23:58 PM4/19/16
to Josh Bleecher Snyder, Brad Fitzpatrick, Keith Randall, Gobot Gobot, golang-co...@googlegroups.com
Brad Fitzpatrick has posted comments on this change.

runtime: call mallocgc directly from makeslice and growslice

Patch Set 1:

(1 comment)

https://go-review.googlesource.com/#/c/22276/1/src/runtime/slice.go
File src/runtime/slice.go:

Line 63: p := mallocgc(et.size*uintptr(cap), et, flags)
why can't mallocgc figure out flagNoScan from et itself? You're both
calculating it from et.kind, and passing it et too.


--
https://go-review.googlesource.com/22276
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-HasComments: Yes

Josh Bleecher Snyder (Gerrit)

unread,
Apr 19, 2016, 7:34:52 PM4/19/16
to Josh Bleecher Snyder, Brad Fitzpatrick, Keith Randall, Gobot Gobot, golang-co...@googlegroups.com
Josh Bleecher Snyder has posted comments on this change.

runtime: call mallocgc directly from makeslice and growslice

Patch Set 1:

(1 comment)

https://go-review.googlesource.com/#/c/22276/1/src/runtime/slice.go
File src/runtime/slice.go:

Line 63: p := mallocgc(et.size*uintptr(cap), et, flags)
> why can't mallocgc figure out flagNoScan from et itself? You're both
> calcul
It probably can, but mallocgc gets called from many places, and I don't
really want to go do an audit of all them for this CL, which is pretty much
just a manual inlining of newarray.

I do think it's worth doing a mallocgc/flags cleanup, but (a) I'm slightly
afraid of doing it myself and (b) it can and should be done separately from
this CL.


--
https://go-review.googlesource.com/22276
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-HasComments: Yes

Keith Randall (Gerrit)

unread,
Apr 19, 2016, 8:05:04 PM4/19/16
to Josh Bleecher Snyder, Brad Fitzpatrick, Keith Randall, Gobot Gobot, golang-co...@googlegroups.com
Keith Randall has posted comments on this change.

runtime: call mallocgc directly from makeslice and growslice

Patch Set 1: Code-Review+2

--
https://go-review.googlesource.com/22276
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-HasComments: No

Josh Bleecher Snyder (Gerrit)

unread,
Apr 19, 2016, 8:05:46 PM4/19/16
to Josh Bleecher Snyder, golang-...@googlegroups.com, Brad Fitzpatrick, Keith Randall, Gobot Gobot, golang-co...@googlegroups.com
Josh Bleecher Snyder has submitted this change and it was merged.

runtime: call mallocgc directly from makeslice and growslice

The extra checks provided by newarray are
redundant in these cases.

This shrinks by one frame the call stack expected
by the pprof test.

name old time/op new time/op delta
MakeSlice-8 34.3ns ± 2% 30.5ns ± 3% -11.03% (p=0.000
n=24+22)
GrowSlicePtr-8 134ns ± 2% 129ns ± 3% -3.25% (p=0.000
n=25+24)

Change-Id: Icd828655906b921c732701fd9d61da3fa217b0af
Reviewed-on: https://go-review.googlesource.com/22276
Run-TryBot: Josh Bleecher Snyder <josh...@gmail.com>
TryBot-Result: Gobot Gobot <go...@golang.org>
Reviewed-by: Keith Randall <k...@golang.org>
---
M src/runtime/pprof/mprof_test.go
M src/runtime/slice.go
2 files changed, 8 insertions(+), 3 deletions(-)

Approvals:
Keith Randall: Looks good to me, approved
Josh Bleecher Snyder: Run TryBots
Gobot Gobot: TryBots succeeded


--
https://go-review.googlesource.com/22276
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Reply all
Reply to author
Forward
0 new messages