]> Cypherpunks repositories - gostls13.git/commit
runtime: use a smaller arena size on Wasm
authorCherry Mui <cherryyz@google.com>
Sun, 22 Jun 2025 19:40:02 +0000 (15:40 -0400)
committerCherry Mui <cherryyz@google.com>
Sat, 27 Sep 2025 00:13:31 +0000 (17:13 -0700)
commit53009b26dd2e8b75fba8b44849e1d323ddb2a31f
tree09416fd14429b1519dbce83fcd79034cd60596c6
parent3a5df9d2b20c0f059c463b5d51e89be17a2c685b
runtime: use a smaller arena size on Wasm

On Wasm, some programs have very small heap. Currently,
we use 4 MB arena size (like all other 32-bit platforms).
For a very small program, it needs to allocate one heap
arena, 4 MB size at a 4 MB aligned address. So we'll
need 8 MB of linear memory, whereas only a smaller
portion is actually used by the program. On Wasm, samll
programs are not uncommon (e.g. WASI plugins), and
users are concerned about the memory usage.

This CL switches to a smaller arena size, as well as a
smaller page allocator chunk size (both are now 512 KB).
So the heap will be grown in 512 KB granularity. For a
helloworld program, it now uses less than 3 MB of
linear memory, instead of 8 MB.

Change-Id: Ibd66c1fa6e794a12c00906cbacc8f2e410f196c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/683296
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/runtime/malloc.go
src/runtime/mgcmark.go
src/runtime/mgcscavenge_test.go
src/runtime/mheap.go
src/runtime/mpagealloc.go
src/runtime/mpagealloc_test.go
src/runtime/mpagecache_test.go
src/runtime/mpallocbits_test.go
test/wasmmemsize.dir/main.go