Skip to content

[48.0.x] Use one alias region per runtime-data array - #15050

Merged
fitzgen merged 2 commits into
bytecodealliance:release-48.0.0from
vuldin:release-48-runtime-data-alias-region
Oct 28, 2026
Merged

fitzgen merged 2 commits into
bytecodealliance:release-48.0.0from
vuldin:release-48-runtime-data-alias-region

Conversation

@vuldin

@vuldin vuldin commented Oct 28, 2026

Copy link
Copy Markdown

Hi! We're moving Redpanda's data transforms onto the 48 LTS line, and on 48.0.7 compiling a typical Go guest panics:

called `Result::unwrap()` on an `Err` value: MemFlagsSetOverflow

from inst_builder.rs (load), inside Module::new. We embed Wasmtime through the C API, so that panic can't unwind and aborts the host process.

With copy-on-write memory init off (we have to run with memory_init_cow(false) because guest memory comes from our own allocator), the module startup function initializes every data segment, and for each one it loads the segment's base and length out of the VMContext. vmctx_load/vmctx_store key the alias region on the VMContext offset, so every segment adds two distinct regions, and so two distinct MemFlags, to that one function. Past ~32k data segments that's more than the u16 MemFlags index allows. Go guests routinely have that many (the two that hit it for us have ~43K and ~46K data segments).

This PR keys the region for the runtime_data_bases and runtime_data_lengths arrays on the start of each array instead of on each element. It's only ever coarser than before, and those three helpers are the only accessors of the two arrays, so nothing else touches the same memory under a different region.

On main this is already covered by #14253 (bounding alias regions to 256), which went into 49. That one depends on #14230 and is a much bigger change, so this is a narrower fix for the 48 branch. Another option is to backport #14253 + #14230 instead if you'd rather keep 48 closer to main.

The test compiles and instantiates a module with 40K data segments and memory_init_cow(false). I haven't run Wasmtime's own test suite locally. In Redpanda the same change, applied to 48.0.7, takes our two Go-guest tests from aborting on every run to passing.

With copy-on-write memory initialization disabled (or when a module's
data segments can't be made into a static image), the module startup
function initializes every data segment, loading each segment's base and
length out of the `VMContext`. Each of those loads got an alias region
keyed by its own `VMContext` offset, so a module with more than ~32k data
segments needs more distinct `MemFlags` than a Cranelift function can
hold and compilation panics with `MemFlagsSetOverflow`. Modules compiled
by Go routinely have tens of thousands of data segments.

Key the region on the start of the `runtime_data_bases` and
`runtime_data_lengths` arrays instead, giving each array a single region.
This is only ever coarser than before. On `main` this is covered by
bytecodealliance#14253, which bounds the number of alias regions in general.

Claude-Session: https://claude.ai/code/session_01EHmbaDcapmSnyJtjfAGMtR
@vuldin
vuldin requested review from a team as code owners October 28, 2026 19:31
@vuldin
vuldin requested review from fitzgen and removed request for a team October 28, 2026 19:31
Its only caller was `store_vmctx_runtime_data_length`, which now picks
its alias region from the start of the runtime-data lengths array.

Claude-Session: https://claude.ai/code/session_01EHmbaDcapmSnyJtjfAGMtR

@fitzgen fitzgen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks!

@fitzgen
fitzgen merged commit 8be1a51 into bytecodealliance:release-48.0.0 Oct 28, 2026
191 checks passed
@fitzgen

fitzgen commented Oct 28, 2026

Copy link
Copy Markdown
Member

@vuldin could you also send a PR adding release notes to the release-48.0.0 branch's RELEASES.md for this change? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants