alexcrichton opened PR #5208 from pooling-dynamic
to main
:
This is a continuation of the thrust in #5207 for reducing page faults and lock contention when using the pooling allocator. To that end this commit implements support for efficient memory management in the pooling allocator when using wasm that is instrumented with bounds checks.
The
MemoryImageSlot
type now avoids unconditionally shrinking memory back to its initial size during theclear_and_remain_ready
operation, instead deferring optional resizing of memory to the subsequent call toinstantiate
when the slot is reused. The instantiation portion then takes the "memory style" as an argument which dictates whether the accessible memory must be precisely fit or whether it's allowed to exceed the maximum. This in effect enables skipping a call tomprotect
to shrink the heap when dynamic memory checks are enabled.In terms of page fault and contention this should improve the situation by:
Fewer calls to
mprotect
since once a heap grows it stays grown and it never shrinks. This means that a write lock is taken within the kernel much more rarely from before (only asymptotically now, not N-times-per-instance).Accessed memory after a heap growth operation will not fault if it was previously paged in by a prior instance and set to zero with
memset
. Unlike #5207 which requires a 6.0 kernel to see this optimization this commit enables the optimization for any kernel.The major cost of choosing this strategy is naturally the performance hit of the wasm itself. This is being looked at in PRs such as #5190 to improve Wasmtime's story here.
This commit does not implement any new configuration options for Wasmtime but instead reinterprets existing configuration options. The pooling allocator no longer unconditionally sets
static_memory_bound_is_maximum
and then implements support necessary for this memory type. This other change to this commit is that theTunables::static_memory_bound
configuration option is no longer gating on the creation of aMemoryPool
and it will now appropriately size toinstance_limits.memory_pages
if thestatic_memory_bound
is to small. This is done to accomodate fuzzing more easily where thestatic_memory_bound
will become small during fuzzing and otherwise the configuration would be rejected and require manual handling. The spirit of theMemoryPool
is one of large virtual address space reservations anyway so it seemed reasonable to interpret the configuration this way.<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
alexcrichton updated PR #5208 from pooling-dynamic
to main
.
alexcrichton requested peterhuene for a review on PR #5208.
peterhuene submitted PR review.
alexcrichton merged PR #5208.
Last updated: Nov 22 2024 at 16:03 UTC