summaryrefslogtreecommitdiff
path: root/src/node_http2.h
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-06-15 00:52:35 +0200
committerAnatoli Papirovski <apapirovski@mac.com>2018-06-24 22:54:49 -0700
commit15c627f185608951775f48a2e2d9b2cb2fe0ce3c (patch)
tree0f6b3dbc152f5f5bc673c669de40c4af5ff4796c /src/node_http2.h
parentbfcf5b01bb4112b833a936a8266879b58ed391db (diff)
downloadandroid-node-v8-15c627f185608951775f48a2e2d9b2cb2fe0ce3c.tar.gz
android-node-v8-15c627f185608951775f48a2e2d9b2cb2fe0ce3c.tar.bz2
android-node-v8-15c627f185608951775f48a2e2d9b2cb2fe0ce3c.zip
http2: track memory allocated by nghttp2
Provide a custom memory allocator for nghttp2, and track memory allocated by the library with it. This makes the used-memory-per-session estimate more accurate, and allows us to track memory leaks either in nghttp2 itself or, more likely, through faulty usage on our end. It also allows us to make the per-session memory limit more accurate in the future; currently, we are not handling this in an ideal way, and instead let nghttp2 allocate what it wants, even if that goes over our limit. PR-URL: https://github.com/nodejs/node/pull/21374 Refs: https://github.com/nodejs/node/pull/21373 Refs: https://github.com/nodejs/node/pull/21336 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'src/node_http2.h')
-rw-r--r--src/node_http2.h19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/node_http2.h b/src/node_http2.h
index db453c1087..d90c3aed66 100644
--- a/src/node_http2.h
+++ b/src/node_http2.h
@@ -721,6 +721,7 @@ class Http2Session : public AsyncWrap, public StreamListener {
class Http2Ping;
class Http2Settings;
+ class MemoryAllocatorInfo;
void EmitStatistics();
@@ -849,13 +850,15 @@ class Http2Session : public AsyncWrap, public StreamListener {
current_session_memory_ -= amount;
}
- // Returns the current session memory including the current size of both
- // the inflate and deflate hpack headers, the current outbound storage
- // queue, and pending writes.
+ // Tell our custom memory allocator that this rcbuf is independent of
+ // this session now, and may outlive it.
+ void StopTrackingRcbuf(nghttp2_rcbuf* buf);
+
+ // Returns the current session memory including memory allocated by nghttp2,
+ // the current outbound storage queue, and pending writes.
uint64_t GetCurrentSessionMemory() {
uint64_t total = current_session_memory_ + sizeof(Http2Session);
- total += nghttp2_session_get_hd_deflate_dynamic_table_size(session_);
- total += nghttp2_session_get_hd_inflate_dynamic_table_size(session_);
+ total += current_nghttp2_memory_;
total += outgoing_storage_.size();
return total;
}
@@ -987,6 +990,8 @@ class Http2Session : public AsyncWrap, public StreamListener {
// The maximum amount of memory allocated for this session
uint64_t max_session_memory_ = DEFAULT_MAX_SESSION_MEMORY;
uint64_t current_session_memory_ = 0;
+ // The amount of memory allocated by nghttp2 internals
+ uint64_t current_nghttp2_memory_ = 0;
// The collection of active Http2Streams associated with this session
std::unordered_map<int32_t, Http2Stream*> streams_;
@@ -1178,7 +1183,8 @@ class ExternalHeader :
}
template <bool may_internalize>
- static MaybeLocal<String> New(Environment* env, nghttp2_rcbuf* buf) {
+ static MaybeLocal<String> New(Http2Session* session, nghttp2_rcbuf* buf) {
+ Environment* env = session->env();
if (nghttp2_rcbuf_is_static(buf)) {
auto& static_str_map = env->isolate_data()->http2_static_strs;
v8::Eternal<v8::String>& eternal = static_str_map[buf];
@@ -1205,6 +1211,7 @@ class ExternalHeader :
return GetInternalizedString(env, vec);
}
+ session->StopTrackingRcbuf(buf);
ExternalHeader* h_str = new ExternalHeader(buf);
MaybeLocal<String> str = String::NewExternalOneByte(env->isolate(), h_str);
if (str.IsEmpty())