diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-07-11 23:46:37 +0200 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2019-07-20 11:10:27 +0200 |
commit | 62f36828be70d0ac8975ec5fe68b90e3dcf526eb (patch) | |
tree | a4a61a48d7311ca5faea14307eb83f07a44a0753 /src | |
parent | c7cb70ce5ec109814544c9cb1862b273a3e5c86f (diff) | |
download | android-node-v8-62f36828be70d0ac8975ec5fe68b90e3dcf526eb.tar.gz android-node-v8-62f36828be70d0ac8975ec5fe68b90e3dcf526eb.tar.bz2 android-node-v8-62f36828be70d0ac8975ec5fe68b90e3dcf526eb.zip |
http2: report memory allocated by nghttp2 to V8
This helps the JS engine have a better understanding of the memory
situation in HTTP/2-heavy applications, and avoids situations that
behave like memory leaks due to previous underestimation of memory
usage which is tied to JS objects.
Refs: https://github.com/nodejs/node/issues/28088#issuecomment-509965105
PR-URL: https://github.com/nodejs/node/pull/28645
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_http2.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/node_http2.cc b/src/node_http2.cc index 9047171e11..ab1c737779 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -557,11 +557,20 @@ class Http2Session::MemoryAllocatorInfo { if (mem != nullptr) { // Adjust the memory info counter. - session->current_nghttp2_memory_ += size - previous_size; + // TODO(addaleax): Avoid the double bookkeeping we do with + // current_nghttp2_memory_ + AdjustAmountOfExternalAllocatedMemory + // and provide versions of our memory allocation utilities that take an + // Environment*/Isolate* parameter and call the V8 method transparently. + const int64_t new_size = size - previous_size; + session->current_nghttp2_memory_ += new_size; + session->env()->isolate()->AdjustAmountOfExternalAllocatedMemory( + new_size); *reinterpret_cast<size_t*>(mem) = size; mem += sizeof(size_t); } else if (size == 0) { session->current_nghttp2_memory_ -= previous_size; + session->env()->isolate()->AdjustAmountOfExternalAllocatedMemory( + -static_cast<int64_t>(previous_size)); } return mem; @@ -571,6 +580,8 @@ class Http2Session::MemoryAllocatorInfo { size_t* original_ptr = reinterpret_cast<size_t*>( static_cast<char*>(ptr) - sizeof(size_t)); session->current_nghttp2_memory_ -= *original_ptr; + session->env()->isolate()->AdjustAmountOfExternalAllocatedMemory( + -static_cast<int64_t>(*original_ptr)); *original_ptr = 0; } |