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>
Showing
Please register or sign in to comment