]> Cypherpunks repositories - gostls13.git/commit
runtime: make sysReserve return page-aligned memory on js-wasm
authorMichael Anthony Knyszek <mknyszek@google.com>
Mon, 4 Nov 2019 20:01:18 +0000 (20:01 +0000)
committerMichael Knyszek <mknyszek@google.com>
Thu, 7 Nov 2019 17:45:27 +0000 (17:45 +0000)
commit763d3ac75cd19f3484f4bb371175aac34ce1f271
treec6dd21395eff28a0a6c0e72be68e001c1a7ec854
parentcec01395c5df103f8e359027fd80c8070ce41506
runtime: make sysReserve return page-aligned memory on js-wasm

This change ensures js-wasm returns page-aligned memory. While today
its lack of alignment doesn't cause problems, this is an invariant of
sysAlloc which is documented in HACKING.md but isn't upheld by js-wasm.

Any code that calls sysAlloc directly for small structures expects a
certain alignment (e.g. debuglog, tracebufs) but this is not maintained
by js-wasm's sysAlloc.

Where sysReserve comes into play is that sysAlloc is implemented in
terms of sysReserve on js-wasm. Also, the documentation of sysReserve
says that the returned memory is "OS-aligned" which on most platforms
means page-aligned, but the "OS-alignment" on js-wasm is effectively 1,
which doesn't seem right either.

The expected impact of this change is increased memory use on wasm,
since there's no way to decommit memory, and any small structures
allocated with sysAlloc won't be packed quite as tightly. However, any
memory increase should be minimal. Most calls to sysReserve and sysAlloc
already aligned their request to physPageSize before calling it; there
are only a few circumstances where this is not true, and they involve
allocating an amount of memory returned by unsafe.Sizeof where it's
actually quite important that we get the alignment right.

Updates #35112.

Change-Id: I9ca171e507ff3bd186326ccf611b35b9ebea1bfe
Reviewed-on: https://go-review.googlesource.com/c/go/+/205277
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Richard Musiol <neelance@gmail.com>
src/runtime/mem_js.go