cli: allow running wasm in limited vmemory with --disable-wasm-trap-handler#52766
Closed
joyeecheung wants to merge 5 commits intonodejs:mainfrom
Closed
cli: allow running wasm in limited vmemory with --disable-wasm-trap-handler#52766joyeecheung wants to merge 5 commits intonodejs:mainfrom
joyeecheung wants to merge 5 commits intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
Member
Author
|
A more real world example of what this PR fixes: (This happens because Webpack uses a wasm implementation of md4) |
Collaborator
VoltrexKeyva
reviewed
May 1, 2024
Collaborator
1906f18 to
61b7375
Compare
Collaborator
The output of `node -p process.config.variables.asan` includes a newline character so it's never exactly "1", which means asan is always "off" for the status files. This fixes the detection by stripping whitespaces from the output.
…andler
By default, Node.js enables trap-handler-based WebAssembly bound
checks. As a result, V8 does not need to insert inline bound checks
int the code compiled from WebAssembly which may speedup WebAssembly
execution significantly, but this optimization requires allocating
a big virtual memory cage (currently 10GB). If the Node.js process
does not have access to a large enough virtual memory address space
due to system configurations or hardware limitations, users won't
be able to run any WebAssembly that involves allocation in this
virtual memory cage and will see an out-of-memory error.
```console
$ ulimit -v 5000000
$ node -p "new WebAssembly.Memory({ initial: 10, maximum: 100 });"
[eval]:1
new WebAssembly.Memory({ initial: 10, maximum: 100 });
^
RangeError: WebAssembly.Memory(): could not allocate memory
at [eval]:1:1
at runScriptInThisContext (node:internal/vm:209:10)
at node:internal/process/execution:118:14
at [eval]-wrapper:6:24
at runScript (node:internal/process/execution:101:62)
at evalScript (node:internal/process/execution:136:3)
at node:internal/main/eval_string:49:3
```
`--disable-wasm-trap-handler` disables this optimization so that
users can at least run WebAssembly (with a less optimial performance)
when the virtual memory address space available to their Node.js
process is lower than what the V8 WebAssembly memory cage needs.
61b7375 to
a087263
Compare
Collaborator
Collaborator
Collaborator
Collaborator
Collaborator
Member
Author
|
cc @nodejs/cpp-reviewers @nodejs/build |
RafaelGSS
reviewed
May 7, 2024
Member
Author
|
Added YAML and manpage entries, thanks for the reminder. As for stability index, it seems unnecessary for a flag that serves as an escape hatch in a special environment - we don't usually add stability index to this kind of flags, either, and there is no clear criteria when this should be considered stable or how it could change over time - I expect the flag to just keep working as it is. If we must assign an index, I think it's fine to just mark it stable. But I'd prefer to just leave it out like most other optional CLI flags. |
Collaborator
Collaborator
joyeecheung
added a commit
that referenced
this pull request
May 10, 2024
PR-URL: #52766 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
marco-ippolito
added a commit
that referenced
this pull request
Jun 20, 2024
Notable changes: doc: * add pimterry to collaborators (Tim Perry) #52874 inspector: * (SEMVER-MINOR) introduce the `--inspect-wait` flag (Kohei Ueno) #52734 test_runner: * (SEMVER-MINOR) support test plans (Colin Ihrig) #52860 tools: * (SEMVER-MINOR) fix get_asan_state() in tools/test.py (Joyee Cheung) #52766 * (SEMVER-MINOR) support max_virtual_memory test configuration (Joyee Cheung) #52766 * (SEMVER-MINOR) support != in test status files (Joyee Cheung) #52766 zlib: * (SEMVER-MINOR) expose zlib.crc32() (Joyee Cheung) #52692 PR-URL: #53486
marco-ippolito
added a commit
that referenced
this pull request
Jun 20, 2024
Notable changes: doc: * add pimterry to collaborators (Tim Perry) #52874 inspector: * (SEMVER-MINOR) introduce the `--inspect-wait` flag (Kohei Ueno) #52734 test_runner: * (SEMVER-MINOR) support test plans (Colin Ihrig) #52860 tools: * (SEMVER-MINOR) fix get_asan_state() in tools/test.py (Joyee Cheung) #52766 * (SEMVER-MINOR) support max_virtual_memory test configuration (Joyee Cheung) #52766 * (SEMVER-MINOR) support != in test status files (Joyee Cheung) #52766 zlib: * (SEMVER-MINOR) expose zlib.crc32() (Joyee Cheung) #52692 PR-URL: #53486
sophoniie
pushed a commit
to sophoniie/node
that referenced
this pull request
Jun 20, 2024
PR-URL: nodejs#52766 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
sophoniie
pushed a commit
to sophoniie/node
that referenced
this pull request
Jun 20, 2024
PR-URL: nodejs#52766 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
sophoniie
pushed a commit
to sophoniie/node
that referenced
this pull request
Jun 20, 2024
The output of `node -p process.config.variables.asan` includes a newline character so it's never exactly "1", which means asan is always "off" for the status files. This fixes the detection by stripping whitespaces from the output. PR-URL: nodejs#52766 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
sophoniie
pushed a commit
to sophoniie/node
that referenced
this pull request
Jun 20, 2024
By default, Node.js enables trap-handler-based WebAssembly bound
checks. As a result, V8 does not need to insert inline bound checks
int the code compiled from WebAssembly which may speedup WebAssembly
execution significantly, but this optimization requires allocating
a big virtual memory cage (currently 10GB). If the Node.js process
does not have access to a large enough virtual memory address space
due to system configurations or hardware limitations, users won't
be able to run any WebAssembly that involves allocation in this
virtual memory cage and will see an out-of-memory error.
```console
$ ulimit -v 5000000
$ node -p "new WebAssembly.Memory({ initial: 10, maximum: 100 });"
[eval]:1
new WebAssembly.Memory({ initial: 10, maximum: 100 });
^
RangeError: WebAssembly.Memory(): could not allocate memory
at [eval]:1:1
at runScriptInThisContext (node:internal/vm:209:10)
at node:internal/process/execution:118:14
at [eval]-wrapper:6:24
at runScript (node:internal/process/execution:101:62)
at evalScript (node:internal/process/execution:136:3)
at node:internal/main/eval_string:49:3
```
`--disable-wasm-trap-handler` disables this optimization so that
users can at least run WebAssembly (with a less optimial performance)
when the virtual memory address space available to their Node.js
process is lower than what the V8 WebAssembly memory cage needs.
PR-URL: nodejs#52766
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
sophoniie
pushed a commit
to sophoniie/node
that referenced
this pull request
Jun 20, 2024
Notable changes:
cli:
* (SEMVER-MINOR) allow running wasm in limited vmem with
--disable-wasm-trap-handler (Joyee Cheung)
nodejs#52766
doc:
* add pimterry to collaborators (Tim Perry)
nodejs#52874
fs:
* (SEMVER-MINOR) allow 'withFileTypes' to be used with globs
(Aviv Keller) nodejs#52837
inspector:
* (SEMVER-MINOR) introduce the `--inspect-wait` flag (Kohei Ueno)
nodejs#52734
lib,src:
* remove --experimental-policy (Rafael Gonzaga)
nodejs#52583
perf_hooks:
* (SEMVER-MINOR) add `deliveryType` and `responseStatus` fields
(Matthew Aitken) nodejs#51589
test_runner:
* (SEMVER-MINOR) support test plans (Colin Ihrig)
nodejs#52860
zlib:
* (SEMVER-MINOR) expose zlib.crc32() (Joyee Cheung)
nodejs#52692
PR-URL: nodejs#52971
sophoniie
pushed a commit
to sophoniie/node
that referenced
this pull request
Jun 20, 2024
Notable changes: doc: * add pimterry to collaborators (Tim Perry) nodejs#52874 inspector: * (SEMVER-MINOR) introduce the `--inspect-wait` flag (Kohei Ueno) nodejs#52734 test_runner: * (SEMVER-MINOR) support test plans (Colin Ihrig) nodejs#52860 tools: * (SEMVER-MINOR) fix get_asan_state() in tools/test.py (Joyee Cheung) nodejs#52766 * (SEMVER-MINOR) support max_virtual_memory test configuration (Joyee Cheung) nodejs#52766 * (SEMVER-MINOR) support != in test status files (Joyee Cheung) nodejs#52766 zlib: * (SEMVER-MINOR) expose zlib.crc32() (Joyee Cheung) nodejs#52692 PR-URL: nodejs#53486
bmeck
pushed a commit
to bmeck/node
that referenced
this pull request
Jun 22, 2024
PR-URL: nodejs#52766 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
bmeck
pushed a commit
to bmeck/node
that referenced
this pull request
Jun 22, 2024
PR-URL: nodejs#52766 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
bmeck
pushed a commit
to bmeck/node
that referenced
this pull request
Jun 22, 2024
The output of `node -p process.config.variables.asan` includes a newline character so it's never exactly "1", which means asan is always "off" for the status files. This fixes the detection by stripping whitespaces from the output. PR-URL: nodejs#52766 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
bmeck
pushed a commit
to bmeck/node
that referenced
this pull request
Jun 22, 2024
By default, Node.js enables trap-handler-based WebAssembly bound
checks. As a result, V8 does not need to insert inline bound checks
int the code compiled from WebAssembly which may speedup WebAssembly
execution significantly, but this optimization requires allocating
a big virtual memory cage (currently 10GB). If the Node.js process
does not have access to a large enough virtual memory address space
due to system configurations or hardware limitations, users won't
be able to run any WebAssembly that involves allocation in this
virtual memory cage and will see an out-of-memory error.
```console
$ ulimit -v 5000000
$ node -p "new WebAssembly.Memory({ initial: 10, maximum: 100 });"
[eval]:1
new WebAssembly.Memory({ initial: 10, maximum: 100 });
^
RangeError: WebAssembly.Memory(): could not allocate memory
at [eval]:1:1
at runScriptInThisContext (node:internal/vm:209:10)
at node:internal/process/execution:118:14
at [eval]-wrapper:6:24
at runScript (node:internal/process/execution:101:62)
at evalScript (node:internal/process/execution:136:3)
at node:internal/main/eval_string:49:3
```
`--disable-wasm-trap-handler` disables this optimization so that
users can at least run WebAssembly (with a less optimial performance)
when the virtual memory address space available to their Node.js
process is lower than what the V8 WebAssembly memory cage needs.
PR-URL: nodejs#52766
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
bmeck
pushed a commit
to bmeck/node
that referenced
this pull request
Jun 22, 2024
Notable changes:
cli:
* (SEMVER-MINOR) allow running wasm in limited vmem with
--disable-wasm-trap-handler (Joyee Cheung)
nodejs#52766
doc:
* add pimterry to collaborators (Tim Perry)
nodejs#52874
fs:
* (SEMVER-MINOR) allow 'withFileTypes' to be used with globs
(Aviv Keller) nodejs#52837
inspector:
* (SEMVER-MINOR) introduce the `--inspect-wait` flag (Kohei Ueno)
nodejs#52734
lib,src:
* remove --experimental-policy (Rafael Gonzaga)
nodejs#52583
perf_hooks:
* (SEMVER-MINOR) add `deliveryType` and `responseStatus` fields
(Matthew Aitken) nodejs#51589
test_runner:
* (SEMVER-MINOR) support test plans (Colin Ihrig)
nodejs#52860
zlib:
* (SEMVER-MINOR) expose zlib.crc32() (Joyee Cheung)
nodejs#52692
PR-URL: nodejs#52971
bmeck
pushed a commit
to bmeck/node
that referenced
this pull request
Jun 22, 2024
Notable changes: doc: * add pimterry to collaborators (Tim Perry) nodejs#52874 inspector: * (SEMVER-MINOR) introduce the `--inspect-wait` flag (Kohei Ueno) nodejs#52734 test_runner: * (SEMVER-MINOR) support test plans (Colin Ihrig) nodejs#52860 tools: * (SEMVER-MINOR) fix get_asan_state() in tools/test.py (Joyee Cheung) nodejs#52766 * (SEMVER-MINOR) support max_virtual_memory test configuration (Joyee Cheung) nodejs#52766 * (SEMVER-MINOR) support != in test status files (Joyee Cheung) nodejs#52766 zlib: * (SEMVER-MINOR) expose zlib.crc32() (Joyee Cheung) nodejs#52692 PR-URL: nodejs#53486
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 24, 2024
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 24, 2024
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 24, 2024
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 24, 2024
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 24, 2024
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 27, 2024
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 27, 2024
* chore: bump node in DEPS to v20.15.0 * doc: Add OpenSSL errors to API docs nodejs/node#34213 * test: crypto-rsa-dsa testing for dynamic openssl nodejs/node#52781 * src: allow preventing debug signal handler start nodejs/node#46681 * cli: allow running wasm in limited vmemory with --disable-wasm-trap-handler nodejs/node#52766 * chore: fixup indices --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 27, 2024
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 27, 2024
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 27, 2024
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 27, 2024
* chore: bump node in DEPS to v20.15.0 * doc: Add OpenSSL errors to API docs nodejs/node#34213 * test: crypto-rsa-dsa testing for dynamic openssl nodejs/node#52781 * src: allow preventing debug signal handler start nodejs/node#46681 * cli: allow running wasm in limited vmemory with --disable-wasm-trap-handler nodejs/node#52766 * chore: fixup indices --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 27, 2024
* chore: bump node in DEPS to v20.15.0 * doc: Add OpenSSL errors to API docs nodejs/node#34213 * test: crypto-rsa-dsa testing for dynamic openssl nodejs/node#52781 * src: allow preventing debug signal handler start nodejs/node#46681 * cli: allow running wasm in limited vmemory with --disable-wasm-trap-handler nodejs/node#52766 * chore: fixup patch indices * chore: update patches --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
codebytere
added a commit
to electron/electron
that referenced
this pull request
Jun 27, 2024
* chore: bump node in DEPS to v20.15.0 * doc: Add OpenSSL errors to API docs nodejs/node#34213 * test: crypto-rsa-dsa testing for dynamic openssl nodejs/node#52781 * src: allow preventing debug signal handler start nodejs/node#46681 * cli: allow running wasm in limited vmemory with --disable-wasm-trap-handler nodejs/node#52766 * chore: fixup patch indices * chore: update patches --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
SkyBird233
pushed a commit
to AOSC-Tracking/vscodium
that referenced
this pull request
Nov 24, 2025
…ion error on riscv Compilation error: RangeError: WebAssembly.Instance(): Out of memory: Cannot allocate Wasm memory for new instance Related PR from Node: nodejs/node#52766
joyeecheung
added a commit
to joyeecheung/node
that referenced
this pull request
Dec 10, 2025
Original commit message:
[api] add V8::CanEnableWebAssemblyTrapHandler()
When the system does not have enough virtual memory for the wasm
cage, installing the trap handler would cause any code allocating
wasm memory to throw. Therefore it's useful for the emebdder to
know when the system require is not met and in that case, skip the
trap handler installation so that wasm code can at least work
(even not at the maximal performance).
Node.js previously has a command line option
--disable-wasm-trap-handler for this, this patch would allow
it to adapt automatically without requiring the use of
a command line flag, which is not always under end-user's control.
Refs: nodejs#52766
Refs: nodejs#60788
Refs: microsoft/vscode#251777
Bug: 40644005
Change-Id: Ie0608970daabe370db4616b875a8f098711c80e2
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
tools: support != in test status files
tools: support max_virtual_memory test configuration
tools: fix get_asan_state() in tools/test.py
The output of
node -p process.config.variables.asanincludesa newline character so it's never exactly "1", which means
asan is always "off" for the status files. This fixes the
detection by stripping whitespaces from the output.
cli: allow running wasm in limited vmemory with --disable-wasm-trap-handler
By default, Node.js enables trap-handler-based WebAssembly bound
checks. As a result, V8 does not need to insert inline bound checks
int the code compiled from WebAssembly which may speedup WebAssembly
execution significantly, but this optimization requires allocating
a big virtual memory cage (currently 10GB). If the Node.js process
does not have access to a large enough virtual memory address space
due to system configurations or hardware limitations, users won't
be able to run any WebAssembly that involves allocation in this
virtual memory cage and will see an out-of-memory error.
--disable-wasm-trap-handlerdisables this optimization so thatusers can at least run WebAssembly (with a less optimial performance)
when the virtual memory address space available to their Node.js
process is lower than what the V8 WebAssembly memory cage needs.
Background: https://docs.google.com/document/u/3/d/1PM4Zqmlt8ac5O8UNQfY7fOsem-6MhbsB-vjFI-9XK6w/edit#heading=h.diogznvalour