Commit 0b6ad251 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Add histogram for code space per module

In the context of launching Liftoff, this will help us estimate the code
size increase and find a good value for the maximum allowed code space.

R=titzer@chromium.org

Bug: v8:6600
Change-Id: Ie76172edbf136629636911fe97c7ecdc940be86d
Reviewed-on: https://chromium-review.googlesource.com/1061497
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53220}
parent 337c1e52
...@@ -1146,7 +1146,9 @@ class RuntimeCallTimerScope { ...@@ -1146,7 +1146,9 @@ class RuntimeCallTimerScope {
HR(compile_script_cache_behaviour, V8.CompileScript.CacheBehaviour, 0, 19, \ HR(compile_script_cache_behaviour, V8.CompileScript.CacheBehaviour, 0, 19, \
20) \ 20) \
HR(wasm_memory_allocation_result, V8.WasmMemoryAllocationResult, 0, 3, 4) \ HR(wasm_memory_allocation_result, V8.WasmMemoryAllocationResult, 0, 3, 4) \
HR(wasm_address_space_usage_mb, V8.WasmAddressSpaceUsageMiB, 0, 1 << 20, 128) HR(wasm_address_space_usage_mb, V8.WasmAddressSpaceUsageMiB, 0, 1 << 20, \
128) \
HR(wasm_module_code_size_mb, V8.WasmModuleCodeSizeMiB, 0, 256, 64)
#define HISTOGRAM_TIMER_LIST(HT) \ #define HISTOGRAM_TIMER_LIST(HT) \
/* Garbage collection timers. */ \ /* Garbage collection timers. */ \
......
...@@ -3012,6 +3012,8 @@ bool Isolate::Init(StartupDeserializer* des) { ...@@ -3012,6 +3012,8 @@ bool Isolate::Init(StartupDeserializer* des) {
counters()->wasm_memory_allocation_result()); counters()->wasm_memory_allocation_result());
wasm_engine_->memory_tracker()->SetAddressSpaceUsageHistogram( wasm_engine_->memory_tracker()->SetAddressSpaceUsageHistogram(
counters()->wasm_address_space_usage_mb()); counters()->wasm_address_space_usage_mb());
wasm_engine_->code_manager()->SetModuleCodeSizeHistogram(
counters()->wasm_module_code_size_mb());
// Initialize the interface descriptors ahead of time. // Initialize the interface descriptors ahead of time.
#define INTERFACE_DESCRIPTOR(Name, ...) \ #define INTERFACE_DESCRIPTOR(Name, ...) \
......
...@@ -985,14 +985,19 @@ void WasmCodeManager::FreeNativeModule(NativeModule* native_module) { ...@@ -985,14 +985,19 @@ void WasmCodeManager::FreeNativeModule(NativeModule* native_module) {
} }
native_module->owned_code_space_.clear(); native_module->owned_code_space_.clear();
size_t code_size = native_module->committed_code_space_;
DCHECK(IsAligned(code_size, AllocatePageSize()));
if (module_code_size_mb_) {
module_code_size_mb_->AddSample(static_cast<int>(code_size / MB));
}
// No need to tell the GC anything if we're destroying the heap, // No need to tell the GC anything if we're destroying the heap,
// which we currently indicate by having the isolate_ as null // which we currently indicate by having the isolate_ as null
if (isolate_ == nullptr) return; if (isolate_ == nullptr) return;
size_t freed_code_space = native_module->committed_code_space_; remaining_uncommitted_code_space_.fetch_add(code_size);
DCHECK(IsAligned(freed_code_space, AllocatePageSize()));
remaining_uncommitted_code_space_.fetch_add(freed_code_space);
isolate_->AdjustAmountOfExternalAllocatedMemory( isolate_->AdjustAmountOfExternalAllocatedMemory(
-static_cast<int64_t>(freed_code_space)); -static_cast<int64_t>(code_size));
} }
// TODO(wasm): We can make this more efficient if needed. For // TODO(wasm): We can make this more efficient if needed. For
......
...@@ -22,6 +22,7 @@ namespace internal { ...@@ -22,6 +22,7 @@ namespace internal {
struct CodeDesc; struct CodeDesc;
class Code; class Code;
class Histogram;
class WasmCompiledModule; class WasmCompiledModule;
namespace wasm { namespace wasm {
...@@ -388,6 +389,10 @@ class V8_EXPORT_PRIVATE WasmCodeManager final { ...@@ -388,6 +389,10 @@ class V8_EXPORT_PRIVATE WasmCodeManager final {
WasmCode* GetCodeFromStartAddress(Address pc) const; WasmCode* GetCodeFromStartAddress(Address pc) const;
size_t remaining_uncommitted_code_space() const; size_t remaining_uncommitted_code_space() const;
void SetModuleCodeSizeHistogram(Histogram* histogram) {
module_code_size_mb_ = histogram;
}
private: private:
friend class NativeModule; friend class NativeModule;
...@@ -412,6 +417,9 @@ class V8_EXPORT_PRIVATE WasmCodeManager final { ...@@ -412,6 +417,9 @@ class V8_EXPORT_PRIVATE WasmCodeManager final {
// TODO(mtrofin): remove the dependency on isolate. // TODO(mtrofin): remove the dependency on isolate.
v8::Isolate* isolate_; v8::Isolate* isolate_;
// Histogram to update with the maximum used code space for each NativeModule.
Histogram* module_code_size_mb_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(WasmCodeManager); DISALLOW_COPY_AND_ASSIGN(WasmCodeManager);
}; };
......
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