Commit b101e0bb authored by Samuel Groß's avatar Samuel Groß Committed by V8 LUCI CQ

Record caged memory allocation outcomes into UMA

Attempts to allocate memory pages inside the virtual memory cage are
currently allowed to fall back to allocating them outside of the cage if
necessary. When this will be forbidden in the future, these cases will
turn into allocation failures. To estimate the frequency of such events,
we now record the outcome of allocation attempts for memory inside the
cage into UMA.

Bug: chromium:1218005
Change-Id: I788fdd968eea10c887eaba1585cd7951823246e0
Cq-Include-Trybots: luci.v8.try:v8_linux64_heap_sandbox_dbg_ng
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3178520Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Samuel Groß <saelo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77041}
parent ac663e2e
......@@ -102,7 +102,9 @@ namespace internal {
HR(turbofan_ticks, V8.TurboFan1KTicks, 0, 100000, 200) \
/* Backtracks observed in a single regexp interpreter execution */ \
/* The maximum of 100M backtracks takes roughly 2 seconds on my machine. */ \
HR(regexp_backtracks, V8.RegExpBacktracks, 1, 100000000, 50)
HR(regexp_backtracks, V8.RegExpBacktracks, 1, 100000000, 50) \
/* See the CagedMemoryAllocationOutcome enum in backing-store.cc */ \
HR(caged_memory_allocation_outcome, V8.CagedMemoryAllocationOutcome, 0, 2, 3)
#define NESTED_TIMED_HISTOGRAM_LIST(HT) \
/* Timer histograms, not thread safe: HT(name, caption, max, unit) */ \
......
......@@ -58,7 +58,7 @@ std::atomic<uint32_t> next_backing_store_id_{1};
// Allocation results are reported to UMA
//
// See wasm_memory_allocation_result in counters.h
// See wasm_memory_allocation_result in counters-definitions.h
enum class AllocationStatus {
kSuccess, // Succeeded on the first try
......@@ -70,6 +70,19 @@ enum class AllocationStatus {
kOtherFailure // Failed for an unknown reason
};
// Attempts to allocate memory inside the virtual memory cage currently fall
// back to allocating memory outside of the cage if necessary. Once this
// fallback is no longer allowed/possible, these cases will become allocation
// failures instead. To track the frequency of such events, the outcome of
// memory allocation attempts inside the cage is reported to UMA.
//
// See caged_memory_allocation_outcome in counters-definitions.h
enum class CagedMemoryAllocationOutcome {
kSuccess, // Allocation succeeded inside the cage
kOutsideCage, // Allocation failed inside the cage but succeeded outside
kFailure, // Allocation failed inside and outside of the cage
};
base::AddressRegion GetReservedRegion(bool has_guard_regions,
void* buffer_start,
size_t byte_capacity) {
......@@ -109,6 +122,29 @@ void RecordStatus(Isolate* isolate, AllocationStatus status) {
static_cast<int>(status));
}
// When the virtual memory cage is active, this function records the outcome of
// attempts to allocate memory inside the cage which fall back to allocating
// memory outside of the cage. Passing a value of nullptr for the result
// indicates that the memory could not be allocated at all.
void RecordCagedMemoryAllocationResult(Isolate* isolate, void* result) {
// This metric is only meaningful when the virtual memory cage is active.
#ifdef V8_VIRTUAL_MEMORY_CAGE
if (GetProcessWideVirtualMemoryCage()->is_initialized()) {
CagedMemoryAllocationOutcome outcome;
if (result) {
bool allocation_in_cage =
GetProcessWideVirtualMemoryCage()->Contains(result);
outcome = allocation_in_cage ? CagedMemoryAllocationOutcome::kSuccess
: CagedMemoryAllocationOutcome::kOutsideCage;
} else {
outcome = CagedMemoryAllocationOutcome::kFailure;
}
isolate->counters()->caged_memory_allocation_outcome()->AddSample(
static_cast<int>(outcome));
}
#endif
}
inline void DebugCheckZero(void* start, size_t byte_length) {
#if DEBUG
// Double check memory is zero-initialized. Despite being DEBUG-only,
......@@ -469,6 +505,7 @@ std::unique_ptr<BackingStore> BackingStore::TryAllocateAndPartiallyCommitMemory(
// Page allocator could not reserve enough pages.
BackingStore::ReleaseReservation(reservation_size);
RecordStatus(isolate, AllocationStatus::kOtherFailure);
RecordCagedMemoryAllocationResult(isolate, nullptr);
TRACE_BS("BSw:try failed to allocate pages\n");
return {};
}
......@@ -504,6 +541,7 @@ std::unique_ptr<BackingStore> BackingStore::TryAllocateAndPartiallyCommitMemory(
RecordStatus(isolate, did_retry ? AllocationStatus::kSuccessAfterRetry
: AllocationStatus::kSuccess);
RecordCagedMemoryAllocationResult(isolate, allocation_base);
ResizableFlag resizable =
is_wasm_memory ? ResizableFlag::kNotResizable : ResizableFlag::kResizable;
......
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