Commit 38f97cae authored by Anton Bikineev's avatar Anton Bikineev Committed by V8 LUCI CQ

platform: Provide hooks for disabling allocation quarantining

Some performance sensitive paths in V8 (compilation/json parsing) or
paths with high allocation/freeing throughput can suffer from not being
able to reuse recently freed allocations. These paths can also
significantly increase the working set and cause large number of page
faults. For such paths (at least as an initial measure) we are planning
to disable allocation quarantining.

The CL provides a way for the embedder to hook in *Scan functions that
disable/enable quarantining. It also disables *Scan for json parsing and
compilation jobs.

Bug: chromium:1249550
Change-Id: I0274f66010435f3d4d091fe70fabcd20f46dc0d2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3306389
Auto-Submit: Anton Bikineev <bikineev@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Anton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78178}
parent 95a69c6b
...@@ -1136,6 +1136,7 @@ filegroup( ...@@ -1136,6 +1136,7 @@ filegroup(
"src/common/assert-scope.cc", "src/common/assert-scope.cc",
"src/common/assert-scope.h", "src/common/assert-scope.h",
"src/common/checks.h", "src/common/checks.h",
"src/common/high-allocation-throughput-scope.h",
"src/common/message-template.h", "src/common/message-template.h",
"src/common/ptr-compr-inl.h", "src/common/ptr-compr-inl.h",
"src/common/ptr-compr.h", "src/common/ptr-compr.h",
......
...@@ -2711,6 +2711,7 @@ v8_header_set("v8_internal_headers") { ...@@ -2711,6 +2711,7 @@ v8_header_set("v8_internal_headers") {
"src/codegen/unoptimized-compilation-info.h", "src/codegen/unoptimized-compilation-info.h",
"src/common/assert-scope.h", "src/common/assert-scope.h",
"src/common/checks.h", "src/common/checks.h",
"src/common/high-allocation-throughput-scope.h",
"src/common/message-template.h", "src/common/message-template.h",
"src/common/ptr-compr-inl.h", "src/common/ptr-compr-inl.h",
"src/common/ptr-compr.h", "src/common/ptr-compr.h",
......
...@@ -522,6 +522,16 @@ class ZoneBackingAllocator { ...@@ -522,6 +522,16 @@ class ZoneBackingAllocator {
virtual FreeFn GetFreeFn() const { return ::free; } virtual FreeFn GetFreeFn() const { return ::free; }
}; };
/**
* Observer used by V8 to notify the embedder about entering/leaving sections
* with high throughput of malloc/free operations.
*/
class HighAllocationThroughputObserver {
public:
virtual void EnterSection() {}
virtual void LeaveSection() {}
};
/** /**
* V8 Platform abstraction layer. * V8 Platform abstraction layer.
* *
...@@ -713,6 +723,16 @@ class Platform { ...@@ -713,6 +723,16 @@ class Platform {
*/ */
virtual void DumpWithoutCrashing() {} virtual void DumpWithoutCrashing() {}
/**
* Allows the embedder to observe sections with high throughput allocation
* operations.
*/
virtual HighAllocationThroughputObserver*
GetHighAllocationThroughputObserver() {
static HighAllocationThroughputObserver default_observer;
return &default_observer;
}
protected: protected:
/** /**
* Default implementation of current wall-clock time in milliseconds * Default implementation of current wall-clock time in milliseconds
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_COMMON_HIGH_ALLOCATION_THROUGHPUT_SCOPE_H_
#define V8_COMMON_HIGH_ALLOCATION_THROUGHPUT_SCOPE_H_
#include "include/v8-platform.h"
namespace v8 {
namespace internal {
/**
* Scope that notifies embedder's observer about entering sections with high
* throughput of malloc/free operations.
*/
class HighAllocationThroughputScope final {
public:
explicit HighAllocationThroughputScope(Platform* platform)
: observer_(platform->GetHighAllocationThroughputObserver()) {
observer_->LeaveSection();
}
HighAllocationThroughputScope(const HighAllocationThroughputScope&) = delete;
HighAllocationThroughputScope& operator=(
const HighAllocationThroughputScope&) = delete;
~HighAllocationThroughputScope() { observer_->EnterSection(); }
private:
HighAllocationThroughputObserver* observer_;
};
} // namespace internal
} // namespace v8
#endif // V8_COMMON_HIGH_ALLOCATION_THROUGHPUT_SCOPE_H_
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "src/codegen/compiler.h" #include "src/codegen/compiler.h"
#include "src/codegen/optimized-compilation-info.h" #include "src/codegen/optimized-compilation-info.h"
#include "src/codegen/register-configuration.h" #include "src/codegen/register-configuration.h"
#include "src/common/high-allocation-throughput-scope.h"
#include "src/compiler/add-type-assertions-reducer.h" #include "src/compiler/add-type-assertions-reducer.h"
#include "src/compiler/backend/code-generator.h" #include "src/compiler/backend/code-generator.h"
#include "src/compiler/backend/frame-elider.h" #include "src/compiler/backend/frame-elider.h"
...@@ -1136,6 +1137,8 @@ class V8_NODISCARD PipelineJobScope { ...@@ -1136,6 +1137,8 @@ class V8_NODISCARD PipelineJobScope {
~PipelineJobScope() { data_->set_runtime_call_stats(nullptr); } ~PipelineJobScope() { data_->set_runtime_call_stats(nullptr); }
private: private:
HighAllocationThroughputScope high_throughput_scope_{
V8::GetCurrentPlatform()};
PipelineData* data_; PipelineData* data_;
}; };
} // namespace } // namespace
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "include/v8-callbacks.h" #include "include/v8-callbacks.h"
#include "src/base/small-vector.h" #include "src/base/small-vector.h"
#include "src/base/strings.h" #include "src/base/strings.h"
#include "src/common/high-allocation-throughput-scope.h"
#include "src/execution/isolate.h" #include "src/execution/isolate.h"
#include "src/heap/factory.h" #include "src/heap/factory.h"
#include "src/objects/objects.h" #include "src/objects/objects.h"
...@@ -145,6 +146,8 @@ class JsonParser final { ...@@ -145,6 +146,8 @@ class JsonParser final {
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> Parse( V8_WARN_UNUSED_RESULT static MaybeHandle<Object> Parse(
Isolate* isolate, Handle<String> source, Handle<Object> reviver) { Isolate* isolate, Handle<String> source, Handle<Object> reviver) {
HighAllocationThroughputScope high_throughput_scope(
V8::GetCurrentPlatform());
Handle<Object> result; Handle<Object> result;
ASSIGN_RETURN_ON_EXCEPTION(isolate, result, ASSIGN_RETURN_ON_EXCEPTION(isolate, result,
JsonParser(isolate, source).ParseJson(), Object); JsonParser(isolate, source).ParseJson(), Object);
......
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