Commit b344f31c authored by Stephan Herhut's avatar Stephan Herhut Committed by Commit Bot

[wasm] Commit code space eagerly when profiling

Under normal execution, we commit code space in page chunks as we
need it. However, this confuses linux perf, as it generates mmap
events in the trace that seem to override the synthetic ones that
are inserted by perf inject.

Instead, when profiling with perf, we now commit the maximum code
space size upfront, leading to a single mmap event early on. While
this significantly increases memory use, it should not impact
profiling of running wasm code.

Bug: v8:8462
Change-Id: I078e9e486fe4ddecdea0b58543cc6bc5873cdfee
Reviewed-on: https://chromium-review.googlesource.com/c/1340279
Commit-Queue: Stephan Herhut <herhut@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57577}
parent f28a7533
......@@ -1305,6 +1305,9 @@ DEFINE_IMPLICATION(perf_basic_prof_only_functions, perf_basic_prof)
DEFINE_BOOL(perf_prof, false,
"Enable perf linux profiler (experimental annotate support).")
DEFINE_NEG_IMPLICATION(perf_prof, compact_code_space)
// TODO(v8:8462) Remove implication once perf supports remapping.
DEFINE_NEG_IMPLICATION(perf_prof, write_protect_code_memory)
DEFINE_NEG_IMPLICATION(perf_prof, wasm_write_protect_code_memory)
DEFINE_BOOL(perf_prof_unwinding_info, false,
"Enable unwinding info for perf linux profiler (experimental).")
DEFINE_IMPLICATION(perf_prof, perf_prof_unwinding_info)
......
......@@ -835,6 +835,8 @@ WasmCodeManager::WasmCodeManager(WasmMemoryTracker* memory_tracker,
}
bool WasmCodeManager::Commit(Address start, size_t size) {
// TODO(v8:8462) Remove eager commit once perf supports remapping.
if (FLAG_perf_prof) return true;
DCHECK(IsAligned(start, AllocatePageSize()));
DCHECK(IsAligned(size, AllocatePageSize()));
// Reserve the size. Use CAS loop to avoid underflow on
......@@ -898,6 +900,12 @@ VirtualMemory WasmCodeManager::TryAllocate(size_t size, void* hint) {
TRACE_HEAP("VMem alloc: %p:%p (%zu)\n",
reinterpret_cast<void*>(mem.address()),
reinterpret_cast<void*>(mem.end()), mem.size());
// TODO(v8:8462) Remove eager commit once perf supports remapping.
if (FLAG_perf_prof) {
SetPermissions(GetPlatformPageAllocator(), mem.address(), mem.size(),
PageAllocator::kReadWriteExecute);
}
return mem;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment