Skip to content

Commit 618e290

Browse files
backesCommit Bot
authored andcommitted
[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: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#62767}
1 parent f5a9357 commit 618e290

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/logging/counters-definitions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ namespace internal {
9090
/* number of code GCs triggered per native module, collected on code GC */ \
9191
HR(wasm_module_num_triggered_code_gcs, \
9292
V8.WasmModuleNumberOfCodeGCsTriggered, 1, 128, 20) \
93+
/* number of code spaces reserved per wasm module */ \
94+
HR(wasm_module_num_code_spaces, V8.WasmModuleNumberOfCodeSpaces, 1, 128, 20) \
9395
/* bailout reason if Liftoff failed, or {kSuccess} (per function) */ \
9496
HR(liftoff_bailout_reasons, V8.LiftoffBailoutReasons, 0, 20, 21) \
9597
/* Ticks observed in a single Turbofan compilation, in 1K */ \

src/wasm/wasm-code-manager.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,15 @@ void WasmCode::DecrementRefCount(Vector<WasmCode* const> code_vec) {
405405

406406
WasmCodeAllocator::WasmCodeAllocator(WasmCodeManager* code_manager,
407407
VirtualMemory code_space,
408-
bool can_request_more)
408+
bool can_request_more,
409+
std::shared_ptr<Counters> async_counters)
409410
: code_manager_(code_manager),
410411
free_code_space_(code_space.region()),
411-
can_request_more_memory_(can_request_more) {
412+
can_request_more_memory_(can_request_more),
413+
async_counters_(std::move(async_counters)) {
412414
owned_code_space_.reserve(can_request_more ? 4 : 1);
413415
owned_code_space_.emplace_back(std::move(code_space));
416+
async_counters_->wasm_module_num_code_spaces()->AddSample(1);
414417
}
415418

416419
WasmCodeAllocator::~WasmCodeAllocator() {
@@ -489,6 +492,8 @@ Vector<byte> WasmCodeAllocator::AllocateForCode(NativeModule* native_module,
489492
owned_code_space_.emplace_back(std::move(new_mem));
490493
code_space = free_code_space_.Allocate(size);
491494
DCHECK(!code_space.is_empty());
495+
async_counters_->wasm_module_num_code_spaces()->AddSample(
496+
static_cast<int>(owned_code_space_.size()));
492497
}
493498
const Address commit_page_size = page_allocator->CommitPageSize();
494499
Address commit_start = RoundUp(code_space.begin(), commit_page_size);
@@ -615,7 +620,7 @@ NativeModule::NativeModule(WasmEngine* engine, const WasmFeatures& enabled,
615620
std::shared_ptr<Counters> async_counters,
616621
std::shared_ptr<NativeModule>* shared_this)
617622
: code_allocator_(engine->code_manager(), std::move(code_space),
618-
can_request_more),
623+
can_request_more, async_counters),
619624
enabled_features_(enabled),
620625
module_(std::move(module)),
621626
import_wrapper_cache_(std::unique_ptr<WasmImportWrapperCache>(

src/wasm/wasm-code-manager.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ const char* GetWasmCodeKindAsString(WasmCode::Kind);
278278
class WasmCodeAllocator {
279279
public:
280280
WasmCodeAllocator(WasmCodeManager*, VirtualMemory code_space,
281-
bool can_request_more);
281+
bool can_request_more,
282+
std::shared_ptr<Counters> async_counters);
282283
~WasmCodeAllocator();
283284

284285
size_t committed_code_space() const {
@@ -316,7 +317,7 @@ class WasmCodeAllocator {
316317
// Code space that was allocated for code (subset of {owned_code_space_}).
317318
DisjointAllocationPool allocated_code_space_;
318319
// Code space that was allocated before but is dead now. Full pages within
319-
// this region are discarded. It's still a subset of {owned_code_space_}).
320+
// this region are discarded. It's still a subset of {owned_code_space_}.
320321
DisjointAllocationPool freed_code_space_;
321322
std::vector<VirtualMemory> owned_code_space_;
322323

@@ -330,6 +331,8 @@ class WasmCodeAllocator {
330331
bool is_executable_ = false;
331332

332333
const bool can_request_more_memory_;
334+
335+
std::shared_ptr<Counters> async_counters_;
333336
};
334337

335338
class V8_EXPORT_PRIVATE NativeModule final {

0 commit comments

Comments
 (0)