Commit 618e290d authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Add counter for number of code spaces

Some architectures allow more than one code space to be reserved per
module. The strategy to allocate additional spaces seems suboptimal: We
allocate just enough for the one code allocation request which does not
fit in the existing space. This can lead to big numbers of reservations
being made.
Also, for lifting the 128MB code space limit on arm64, we will allocate
several code spaces also on x64 and arm64.
This CL introduces a new counter to measure the number of code spaces
per module, to see whether we have problems there already, and to track
that metric when implementing the mentioned change.

In order to update the respective counter, the {WasmCodeAllocator} now
also holds a shared pointer to the counters of the original isolate.
Those counters might live much longer than the isolate itself, which is
no problem and can already happen before this change.

R=mstarzinger@chromium.org
CC=jwd@chromium.org

Bug: v8:9477
Change-Id: I95e29b2d27f0414586246e2fa99d6761960a636b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1704100
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62767}
parent f5a93574
......@@ -90,6 +90,8 @@ namespace internal {
/* number of code GCs triggered per native module, collected on code GC */ \
HR(wasm_module_num_triggered_code_gcs, \
V8.WasmModuleNumberOfCodeGCsTriggered, 1, 128, 20) \
/* number of code spaces reserved per wasm module */ \
HR(wasm_module_num_code_spaces, V8.WasmModuleNumberOfCodeSpaces, 1, 128, 20) \
/* bailout reason if Liftoff failed, or {kSuccess} (per function) */ \
HR(liftoff_bailout_reasons, V8.LiftoffBailoutReasons, 0, 20, 21) \
/* Ticks observed in a single Turbofan compilation, in 1K */ \
......
......@@ -405,12 +405,15 @@ void WasmCode::DecrementRefCount(Vector<WasmCode* const> code_vec) {
WasmCodeAllocator::WasmCodeAllocator(WasmCodeManager* code_manager,
VirtualMemory code_space,
bool can_request_more)
bool can_request_more,
std::shared_ptr<Counters> async_counters)
: code_manager_(code_manager),
free_code_space_(code_space.region()),
can_request_more_memory_(can_request_more) {
can_request_more_memory_(can_request_more),
async_counters_(std::move(async_counters)) {
owned_code_space_.reserve(can_request_more ? 4 : 1);
owned_code_space_.emplace_back(std::move(code_space));
async_counters_->wasm_module_num_code_spaces()->AddSample(1);
}
WasmCodeAllocator::~WasmCodeAllocator() {
......@@ -489,6 +492,8 @@ Vector<byte> WasmCodeAllocator::AllocateForCode(NativeModule* native_module,
owned_code_space_.emplace_back(std::move(new_mem));
code_space = free_code_space_.Allocate(size);
DCHECK(!code_space.is_empty());
async_counters_->wasm_module_num_code_spaces()->AddSample(
static_cast<int>(owned_code_space_.size()));
}
const Address commit_page_size = page_allocator->CommitPageSize();
Address commit_start = RoundUp(code_space.begin(), commit_page_size);
......@@ -615,7 +620,7 @@ NativeModule::NativeModule(WasmEngine* engine, const WasmFeatures& enabled,
std::shared_ptr<Counters> async_counters,
std::shared_ptr<NativeModule>* shared_this)
: code_allocator_(engine->code_manager(), std::move(code_space),
can_request_more),
can_request_more, async_counters),
enabled_features_(enabled),
module_(std::move(module)),
import_wrapper_cache_(std::unique_ptr<WasmImportWrapperCache>(
......
......@@ -278,7 +278,8 @@ const char* GetWasmCodeKindAsString(WasmCode::Kind);
class WasmCodeAllocator {
public:
WasmCodeAllocator(WasmCodeManager*, VirtualMemory code_space,
bool can_request_more);
bool can_request_more,
std::shared_ptr<Counters> async_counters);
~WasmCodeAllocator();
size_t committed_code_space() const {
......@@ -316,7 +317,7 @@ class WasmCodeAllocator {
// Code space that was allocated for code (subset of {owned_code_space_}).
DisjointAllocationPool allocated_code_space_;
// Code space that was allocated before but is dead now. Full pages within
// this region are discarded. It's still a subset of {owned_code_space_}).
// this region are discarded. It's still a subset of {owned_code_space_}.
DisjointAllocationPool freed_code_space_;
std::vector<VirtualMemory> owned_code_space_;
......@@ -330,6 +331,8 @@ class WasmCodeAllocator {
bool is_executable_ = false;
const bool can_request_more_memory_;
std::shared_ptr<Counters> async_counters_;
};
class V8_EXPORT_PRIVATE NativeModule final {
......
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