-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mpk: optimize layout of protected stripes, again #7622
Conversation
This is another attempt at bytecodealliance#7603, attempting reduce the slab layout sizes of MPK-protected stripes. While experimenting with the limits of MPK-protected memory pools, @alexcrichton and I discovered that the current slab layout calculations were too conservative. This meant that the memory pool could not pack in as many memories as it should have been able: we were expecting, but not seeing, ~15x more memory slots over non-MPK memory pools. This change brings together several fixes: - it more aggressively divides up the stripes (as in b212152) - it eliminates an extra stripe (as in 8813a30) - it replaces some uses of `checked_*` with `saturating_*` (as in fb22a20) - it improves some documentation - and, crucially, it reports back a larger value for `memory_and_guard_size` The failures observed with bytecodealliance#7603 when run with MPK (`WASMTIME_TEST_FORCE_MPK=1 cargo test`) were due to `Store::wasm_fault` not being able to identify which memory an OOB address belonged to. This is because the `MemoryPool` was underreporting the size of the region in which OOB accesses would fault. The correct value is provided by the new `SlabLayout::bytes_to_next_stripe_slot`: any OOB access within that larger region must fault because (1) the other stripes have different protection keys and (2) a `Store` can only use one protection key. We also use (2) to guarantee that `Store::wasm_fault` will be able to calculate the Wasm address from the raw address. This change also provides a new `traps` test that will reproduce the failures from bytecodealliance#7603; if we observe `SIGABRT` from that test, it will be a regression.
I manually checked that the following pass:
Running the example program from #7609, I see expected improvements in the number of slots: $ cargo run --example mpk
without MPK: 14713 memory slots 86.2 TiB reserved
with MPK: 220685 memory slots 86.2 TiB reserved
14.999x more slots per reserved memory |
This is kind of interesting: arm64 is miscomputing the
It should be |
Ah that's expected that some platforms report a different faulting address rounded to some boundary. s390x will round it to a page boundary I think. There's a similar test to what you're doing here which should be ok to copy |
This is another attempt at #7603, attempting reduce the slab layout sizes of MPK-protected stripes. While experimenting with the limits of MPK-protected memory pools, @alexcrichton and I discovered that the current slab layout calculations were too conservative. This meant that the memory pool could not pack in as many memories as it should have been able: we were expecting, but not seeing, ~15x more memory slots over non-MPK memory pools.
This change brings together several fixes:
checked_*
withsaturating_*
(as in fb22a20)memory_and_guard_size
The failures observed with #7603 when run with MPK (
WASMTIME_TEST_FORCE_MPK=1 cargo test
) were due toStore::wasm_fault
not being able to identify which memory an OOB address belonged to. This is because theMemoryPool
was underreporting the size of the region in which OOB accesses would fault. The correct value is provided by the newSlabLayout::bytes_to_next_stripe_slot
: any OOB access within that larger region must fault because (1) the other stripes have different protection keys and (2) aStore
can only use one protection key. We also use (2) to guarantee thatStore::wasm_fault
will be able to calculate the Wasm address from the raw address.This change also provides a new
traps
test that will reproduce the failures from #7603; if we observeSIGABRT
from that test, it will be a regression.