From 1d996f58af3067617a67c0af8f86f014ed4d139c Mon Sep 17 00:00:00 2001 From: Ali Ijaz Sheikh Date: Fri, 1 Feb 2019 11:38:52 -0800 Subject: [PATCH] src: properly configure default heap limits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unless configured, V8 defaults to limiting the max heaps size to 700 MB or 1400MB on 32 and 64-bit platforms respectively. This default is based on the browser use-cases and doesn't make a lot of sense generally. This change properly configures the heap size based on actual available memory. PR-URL: https://github.com/nodejs/node/pull/25576 Reviewed-By: Anna Henningsen Reviewed-By: Joyee Cheung Reviewed-By: Michaƫl Zasso Reviewed-By: Yang Guo Reviewed-By: Ujjwal Sharma Reviewed-By: Colin Ihrig --- src/api/environment.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/api/environment.cc b/src/api/environment.cc index 22938df37cc41d..e54252824bdcc9 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -80,6 +80,15 @@ void FreeArrayBufferAllocator(ArrayBufferAllocator* allocator) { Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) { Isolate::CreateParams params; params.array_buffer_allocator = allocator; + + double total_memory = uv_get_total_memory(); + if (total_memory > 0) { + // V8 defaults to 700MB or 1.4GB on 32 and 64 bit platforms respectively. + // This default is based on browser use-cases. Tell V8 to configure the + // heap based on the actual physical memory. + params.constraints.ConfigureDefaults(total_memory, 0); + } + #ifdef NODE_ENABLE_VTUNE_PROFILING params.code_event_handler = vTune::GetVtuneCodeEventHandler(); #endif