-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
process: report ArrayBuffer memory in memoryUsage()
#31550
Conversation
Report memory allocations performed by the `ArrayBuffer::Allocator`.
Co-Authored-By: Richard Lau <[email protected]>
doc/api/process.md
Outdated
* `arrayBuffers` refers to memory allocated for `ArrayBuffer`s and | ||
`SharedArrayBuffer`s, including all Node.js [`Buffer`][]s. | ||
This is also included in the `external` value. When Node.js is used as an | ||
embedded library, this value may be `0`. |
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.
sorry for being raw
here, but I have these questions:
When Node.js is used as an embedded library, this value may be
0
.
- why? is it because Node.js cannot truly account for the allocations of the embedder?
- where? which part of the code takes the decision based on the embedded state?
- may be
0
- why again - why this decision cannot be deterministic as opposed to probabilistic? which factors decide the outcome? how would one use those factors to decide whether the value is trustworthy or not?
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.
sorry for being
raw
here, but I have these questions:When Node.js is used as an embedded library, this value may be
0
.
- why? is it because Node.js cannot truly account for the allocations of the embedder?
Because embedders can specify their own ArrayBuffer::Allocator
, which would not necessarily track allocations (e.g. Electron
does this).
- where? which part of the code takes the decision based on the embedded state?
Inside the C++ MemoryUsage()
binding, there’s a array_buffer_allocator == nullptr
check. If there is no NodeArrayBufferAllocator*
that the embedder informed us about, then the method sets the field for array buffers to 0.
- may be
0
- why again - why this decision cannot be deterministic as opposed to probabilistic?
I don’t really understand this question, sorry – there is nothing probabilistic involved here, I think?
which factors decide the outcome?
I think that’s also answered by the first question, but let me know if I’m misunderstanding.
how would one use those factors to decide whether the value is trustworthy or not?
I think it’s safe to say that the value is trustworthy when it’s not 0
.
I didn’t want to go into a ton of detail in the documentation here – imo there should be an indication that the value may not always be provided, and that tools should not make the expectation that the value is non-zero. But for a tool it’s not really going to matter why exactly the value can’t be reported, I think, other than that it’s related to the fact that the Node.js code is running in a specific environment that behaves differently.
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.
there is nothing probabilistic involved here, I think?
I termed it as probabilistic because of may be 0
phrase. But based on your explanation to the rest of the questions, I understand it as:
if embedders use only non-node.js allocators without a tracker, then this value WILL
be 0 (not truly reflecting actual consumption), and if embedders rely on node.js' allocators, then the value will be accurate - zero or non-zero
Are we on the same 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.
@gireeshpunathil Yes, we are 👍 I feel like the most important thing is that the doc makes clear that this does not affect standard Node.js binaries.
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.
Maybe a simple "because such allocations may not be tracked" would be good?
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.
@jasnell Sure, done 👍
Landed in abe6a2e |
Report memory allocations performed by the `ArrayBuffer::Allocator`. PR-URL: #31550 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
abe6a2e introduced a test that verifies that ArrayBuffer allocations are tracked. However, V8 supports concurrent freeing of such allocations on background threads, meaning that the results may be subject to race conditions sometimes. Disabling concurrent freeing makes the test pass consistently. Refs: nodejs#31550
abe6a2e introduced a test that verifies that ArrayBuffer allocations are tracked. However, V8 supports concurrent freeing of such allocations on background threads, meaning that the results may be subject to race conditions sometimes. Disabling concurrent freeing makes the test pass consistently. Refs: #31550 PR-URL: #31602 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]>
Report memory allocations performed by the `ArrayBuffer::Allocator`. PR-URL: #31550 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
abe6a2e introduced a test that verifies that ArrayBuffer allocations are tracked. However, V8 supports concurrent freeing of such allocations on background threads, meaning that the results may be subject to race conditions sometimes. Disabling concurrent freeing makes the test pass consistently. Refs: #31550 PR-URL: #31602 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]>
Notable changes: * async_hooks * add executionAsyncResource (Matteo Collina) #30959 * crypto * add crypto.diffieHellman (Tobias Nießen) #31178 * add DH support to generateKeyPair (Tobias Nießen) #31178 * simplify DH groups (Tobias Nießen) #31178 * add key type 'dh' (Tobias Nießen) #31178 * test * skip keygen tests on arm systems (Tobias Nießen) #31178 * perf_hooks * add property flags to GCPerformanceEntry (Kirill Fomichev) #29547 * process * report ArrayBuffer memory in `memoryUsage()` (Anna Henningsen) #31550 * readline * make tab size configurable (Ruben Bridgewater) #31318 * report * add support for Workers (Anna Henningsen) #31386 * worker * add ability to take heap snapshot from parent thread (Anna Henningsen) #31569 * added new collaborators * add ronag to collaborators (Robert Nagy) #31498 PR-URL: #31837
Notable changes: * async_hooks * add executionAsyncResource (Matteo Collina) #30959 * crypto * add crypto.diffieHellman (Tobias Nießen) #31178 * add DH support to generateKeyPair (Tobias Nießen) #31178 * simplify DH groups (Tobias Nießen) #31178 * add key type 'dh' (Tobias Nießen) #31178 * test * skip keygen tests on arm systems (Tobias Nießen) #31178 * perf_hooks * add property flags to GCPerformanceEntry (Kirill Fomichev) #29547 * process * report ArrayBuffer memory in `memoryUsage()` (Anna Henningsen) #31550 * readline * make tab size configurable (Ruben Bridgewater) #31318 * report * add support for Workers (Anna Henningsen) #31386 * worker * add ability to take heap snapshot from parent thread (Anna Henningsen) #31569 * added new collaborators * add ronag to collaborators (Robert Nagy) #31498 PR-URL: #31837
Report memory allocations performed by the `ArrayBuffer::Allocator`. PR-URL: nodejs#31550 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
abe6a2e introduced a test that verifies that ArrayBuffer allocations are tracked. However, V8 supports concurrent freeing of such allocations on background threads, meaning that the results may be subject to race conditions sometimes. Disabling concurrent freeing makes the test pass consistently. Refs: nodejs#31550 PR-URL: nodejs#31602 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]>
Report memory allocations performed by the `ArrayBuffer::Allocator`. PR-URL: #31550 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
abe6a2e introduced a test that verifies that ArrayBuffer allocations are tracked. However, V8 supports concurrent freeing of such allocations on background threads, meaning that the results may be subject to race conditions sometimes. Disabling concurrent freeing makes the test pass consistently. Refs: #31550 PR-URL: #31602 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]>
Report memory allocations performed by the
ArrayBuffer::Allocator
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes