-
-
Notifications
You must be signed in to change notification settings - Fork 35.1k
src: do not enable wasm trap handler if there's not enough vmem #62132
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
Open
joyeecheung
wants to merge
3
commits into
nodejs:main
Choose a base branch
from
joyeecheung:wasm-handler-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+251
−73
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // RLIMIT_AS: 3221225472 | ||
| // When the virtual memory limit is 3GB, there is not enough virtual memory for | ||
| // even one wasm cage. In this case Node.js should automatically adapt and | ||
| // skip enabling trap-based bounds checks, so that WASM can at least run with | ||
| // inline bound checks. | ||
| 'use strict'; | ||
|
|
||
| require('../common'); | ||
| new WebAssembly.Memory({ initial: 10, maximum: 100 }); | ||
|
|
||
| // Test memory64 works too. | ||
| new WebAssembly.Memory({ address: 'i64', initial: 10n, maximum: 100n }); |
20 changes: 20 additions & 0 deletions
20
test/wasm-allocation/test-wasm-allocation-disable-trap-handler.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Flags: --disable-wasm-trap-handler | ||
| // RLIMIT_AS: 34359738368 | ||
|
|
||
| // 32GB should be enough for at least 2 cages, but not enough for 30. | ||
|
|
||
| // Test that with limited virtual memory space, --disable-wasm-trap-handler | ||
| // fully disables trap-based bounds checks, and thus allows WASM to run with | ||
| // inline bound checks. | ||
| 'use strict'; | ||
|
|
||
| require('../common'); | ||
| const instances = []; | ||
| for (let i = 0; i < 30; i++) { | ||
| instances.push(new WebAssembly.Memory({ initial: 10, maximum: 100 })); | ||
| } | ||
|
|
||
| // Test memory64 works too. | ||
| for (let i = 0; i < 30; i++) { | ||
| instances.push(new WebAssembly.Memory({ initial: 10n, maximum: 100n, address: 'i64' })); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
(Non blocking)
The virtual memory available to the process is usually much more than the virtual memory available for usage in wasm trap handler.
e.g. In nodejs/doc-kit#691 (comment) , I observed that only a single wasm memory is successfully allocated, while the available virtual address space is 256GiB (riscv64 with sv39). It's very likely that address space fragmentation caused it.
Maybe it would be better to check if the available virtual memory could contain more cages rather than just one cage. But that being said, I am not sure where to draw the line.
Uh oh!
There was an error while loading. Please reload this page.
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.
That would help accommodate more use cases yeah, though I guess for the initial version we can just go with RLIMIT_AS for now for the more common "someone is setting it somewhere to be < 16GB" case - which means even core functionality can be incomplete (since llhttp requires at least 1 cage). I think it'll probably be unlikely for 64-bit architectures to have a natural limit that is smaller than that. For space sizes in-between, this is going to be tricky, you'll only see issues from multiple user-land WASM, and that's harder to accomondate just from the Node.js side - you'll likely need something in V8 instead.