Skip to content
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

[v18.x backport] child_process: improve spawn performance on Linux #50098

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
@@ -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.26',
'v8_embedder_string': '-node.27',

##### V8 defaults for Node.js #####

14 changes: 14 additions & 0 deletions deps/v8/BUILD.gn
Original file line number Diff line number Diff line change
@@ -82,6 +82,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_on_release_branch || is_debug

@@ -862,6 +873,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" ]
}
6 changes: 6 additions & 0 deletions deps/v8/src/base/platform/platform-posix.cc
Original file line number Diff line number Diff line change
@@ -174,6 +174,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 =
17 changes: 17 additions & 0 deletions tools/v8_gypfiles/features.gypi
Original file line number Diff line number Diff line change
@@ -68,6 +68,20 @@
}, {
'v8_enable_system_instrumentation': 0,
}],
['OS=="linux"', {
# 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': 1,
}, {
'v8_enable_private_mapping_fork_optimization': 0,
}],
],
'is_debug%': 0,

@@ -310,6 +324,9 @@
['v8_enable_hugepage==1', {
'defines': ['ENABLE_HUGEPAGE',],
}],
['v8_enable_private_mapping_fork_optimization==1', {
'defines': ['V8_ENABLE_PRIVATE_MAPPING_FORK_OPTIMIZATION'],
}],
['v8_enable_vtunejit==1', {
'defines': ['ENABLE_VTUNE_JIT_INTERFACE',],
}],