-
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: limit the number of protection keys #7364
Conversation
If Wasmtime is ever embedded in an application that also uses memory protection keys, it could be useful to limit how many Wasmtime allocates and uses. This came up while examining `*.wast` tests: if there was no way limiting the number of keys used, then those tests configured a pool that reserved too much memory. This change takes that further to attempt to limit the initial number of keys allocated. The unfortunate side effect of using a `OnceLock` is that the `max` setting is only applicable on the first invocation, the one that sets the `OnceLock`.
This change stems from how slicing memory slots into MPK-protected regions limits the number of memories each store can access: e.g., with fifteen keys in use, a store only has access to a fifteenth of the available slots. If we simply multiple the number of memory slots needed to run the `*.wast` spec tests by fifteen, we run out of available memory. This limits the number of protection keys used to two, which still allows us to test the functionality without reserving too much memory.
@@ -180,7 +182,7 @@ fn feature_found_src(bytes: &[u8], name: &str) -> bool { | |||
// specified maximum we can put a cap on the virtual address space reservations | |||
// made. | |||
fn lock_pooling() -> impl Drop { | |||
const MAX_CONCURRENT_POOLING: u32 = 8; | |||
const MAX_CONCURRENT_POOLING: u32 = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes some sense to me in that you doubled the number of memories which would halve the limit of concurrent tests because right now each test creates its own engine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me! I think this is fine to start out with at least and we can iterate on it over time. I do agree with what you mentioned though of pushing the handling of max
directly into the keys
function.
@@ -180,7 +182,7 @@ fn feature_found_src(bytes: &[u8], name: &str) -> bool { | |||
// specified maximum we can put a cap on the virtual address space reservations | |||
// made. | |||
fn lock_pooling() -> impl Drop { | |||
const MAX_CONCURRENT_POOLING: u32 = 8; | |||
const MAX_CONCURRENT_POOLING: u32 = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes some sense to me in that you doubled the number of memories which would halve the limit of concurrent tests because right now each test creates its own engine.
This addresses a review comment to slice the list of keys down to the `max` hint regardless of how many are allocated in the first invocation.
This change stems from how slicing memory slots into MPK-protected regions limits the number of memories each store can access: e.g., with fifteen keys in use, a store only has access to a fifteenth of the available slots. If we simply multiple the number of memory slots needed to run the
*.wast
spec tests by fifteen, we run out of available memory. This limits the number of protection keys used to two, which still allows us to test the functionality without reserving too much memory.Also, if Wasmtime is ever embedded in an application that also uses memory protection keys, it could be useful to limit how many Wasmtime allocates and uses.. This change not only limits the number of protection keys used at runtime, but takes that
further to attempt to limit the initial number of keys allocated. The unfortunate side effect of using a
OnceLock
is that themax
setting is only applicable on the first invocation, the one that sets theOnceLock
.