aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
authorRichard Musiol <mail@richard-musiol.de>2019-04-08 00:36:55 +0200
committerRichard Musiol <neelance@gmail.com>2019-04-16 15:03:34 +0000
commit460f9c60689c38bdd938d09903f3b414f6082a7d (patch)
tree13b35308f3e97d6696bf4bd1a0dd78263b724b0e /src/runtime/malloc.go
parente47090ab40967c2e5e6058838319259b4cc0d508 (diff)
downloadgo-460f9c60689c38bdd938d09903f3b414f6082a7d.tar.xz
runtime, cmd/link: optimize memory allocation on wasm
WebAssembly's memory is contiguous. Allocating memory at a high address also allocates all memory up to that address. This change reduces the initial memory allocated on wasm from 1GB to 16MB by using multiple heap arenas and reducing the size of a heap arena. Fixes #27462. Change-Id: Ic941e6edcadd411e65a14cb2f9fd6c8eae02fc7a Reviewed-on: https://go-review.googlesource.com/c/go/+/170950 Run-TryBot: Richard Musiol <neelance@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 9feec1b007..c22c7aa7dc 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -248,7 +248,7 @@ const (
// logHeapArenaBytes is log_2 of heapArenaBytes. For clarity,
// prefer using heapArenaBytes where possible (we need the
// constant to compute some other constants).
- logHeapArenaBytes = (6+20)*(_64bit*(1-sys.GoosWindows)*(1-sys.GoosAix)) + (2+20)*(_64bit*sys.GoosWindows) + (2+20)*(1-_64bit) + (8+20)*sys.GoosAix
+ logHeapArenaBytes = (6+20)*(_64bit*(1-sys.GoosWindows)*(1-sys.GoosAix)*(1-sys.GoarchWasm)) + (2+20)*(_64bit*sys.GoosWindows) + (2+20)*(1-_64bit) + (8+20)*sys.GoosAix + (2+20)*sys.GoarchWasm
// heapArenaBitmapBytes is the size of each heap arena's bitmap.
heapArenaBitmapBytes = heapArenaBytes / (sys.PtrSize * 8 / 2)
@@ -394,7 +394,7 @@ func mallocinit() {
_g_.m.mcache = allocmcache()
// Create initial arena growth hints.
- if sys.PtrSize == 8 && GOARCH != "wasm" {
+ if sys.PtrSize == 8 {
// On a 64-bit machine, we pick the following hints
// because:
//