diff --git a/common.gypi b/common.gypi index 12421a556f1b71..22c9c48c972bd6 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.4', + 'v8_embedder_string': '-node.5', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/BUILD.gn b/deps/v8/BUILD.gn index c13cf053a80d21..00c6e42573d372 100644 --- a/deps/v8/BUILD.gn +++ b/deps/v8/BUILD.gn @@ -83,6 +83,17 @@ declare_args() { # Sets -dENABLE_HUGEPAGE v8_enable_hugepage = false + # Sets -dV8_ENABLE_PRIVATE_MAPPING_FORK_OPTIMIZATION. + # + # This flag speeds up the performance of fork/execve on Linux systems for + # embedders which use it (like Node.js). It works by marking the pages that + # V8 allocates as MADV_DONTFORK. Without MADV_DONTFORK, the Linux kernel + # spends a long time manipulating page mappings on fork and exec which the + # child process doesn't generally need to access. + # + # See v8:7381 for more details. + v8_enable_private_mapping_fork_optimization = false + # Sets -dENABLE_HANDLE_ZAPPING. v8_enable_handle_zapping = is_asan || is_debug @@ -1002,6 +1013,9 @@ config("features") { if (v8_enable_hugepage) { defines += [ "ENABLE_HUGEPAGE" ] } + if (v8_enable_private_mapping_fork_optimization) { + defines += [ "V8_ENABLE_PRIVATE_MAPPING_FORK_OPTIMIZATION" ] + } if (v8_enable_object_print) { defines += [ "OBJECT_PRINT" ] } diff --git a/deps/v8/src/base/platform/platform-posix.cc b/deps/v8/src/base/platform/platform-posix.cc index 2dd97bee02c01f..5408413e11efdd 100644 --- a/deps/v8/src/base/platform/platform-posix.cc +++ b/deps/v8/src/base/platform/platform-posix.cc @@ -160,6 +160,12 @@ void* Allocate(void* hint, size_t size, OS::MemoryPermission access, int flags = GetFlagsForMemoryPermission(access, page_type); void* result = mmap(hint, size, prot, flags, kMmapFd, kMmapFdOffset); if (result == MAP_FAILED) return nullptr; + +#if V8_ENABLE_PRIVATE_MAPPING_FORK_OPTIMIZATION + // This is advisory, so we ignore errors. + madvise(result, size, MADV_DONTFORK); +#endif + #if ENABLE_HUGEPAGE if (result != nullptr && size >= kHugePageSize) { const uintptr_t huge_start =