Skip to content

Commit

Permalink
Revert "[heap] Add global memory controller"
Browse files Browse the repository at this point in the history
This reverts commit cfe281f.

Reason for revert: Fails on gcc bots

Original change's description:
> [heap] Add global memory controller
> 
> Provide a global memory controller used to compute limits for combined
> on-heap and embedder memory. The global controller uses the same
> mechanism (gc speed, mutator speed) and growing factors as the regular
> on-heap controller.
> 
> Rely on V8's mechanisms for configured state that stops shrinking the
> limit.
> 
> Bug: chromium:948807
> Change-Id: I3283a2c28e6ab889f8d2ad85c9b67b8f234b9900
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1619762
> Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
> Reviewed-by: Hannes Payer <hpayer@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#61712}

TBR=ulan@chromium.org,hpayer@chromium.org,mlippautz@chromium.org,bikineev@chromium.org

Change-Id: I503d5a1436eb9156556b5bca852d2b2f9da2446f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:948807
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1622967
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61713}
  • Loading branch information
mlippautz authored and Commit Bot committed May 21, 2019
1 parent cfe281f commit 5e043f2
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 387 deletions.
31 changes: 1 addition & 30 deletions include/v8.h
Expand Up @@ -7138,24 +7138,6 @@ class V8_EXPORT EmbedderHeapTracer {
virtual void VisitTracedGlobalHandle(const TracedGlobal<Value>& value) = 0;
};

/**
* Summary of a garbage collection cycle. See |TraceEpilogue| on how the
* summary is reported.
*/
struct TraceSummary {
/**
* Time spent managing the retained memory in milliseconds. This can e.g.
* include the time tracing through objects in the embedder.
*/
double time;

/**
* Memory retained by the embedder through the |EmbedderHeapTracer|
* mechanism in bytes.
*/
size_t allocated_size;
};

virtual ~EmbedderHeapTracer() = default;

/**
Expand Down Expand Up @@ -7202,12 +7184,9 @@ class V8_EXPORT EmbedderHeapTracer {
/**
* Called at the end of a GC cycle.
*
* Note that allocation is *not* allowed within |TraceEpilogue|. Can be
* overriden to fill a |TraceSummary| that is used by V8 to schedule future
* garbage collections.
* Note that allocation is *not* allowed within |TraceEpilogue|.
*/
virtual void TraceEpilogue() = 0;
virtual void TraceEpilogue(TraceSummary* trace_summary) { TraceEpilogue(); }

/**
* Called upon entering the final marking pause. No more incremental marking
Expand Down Expand Up @@ -7244,14 +7223,6 @@ class V8_EXPORT EmbedderHeapTracer {
*/
void GarbageCollectionForTesting(EmbedderStackState stack_state);

/*
* Called by the embedder to signal newly allocated memory. Not bound to
* tracing phases. Embedders should trade off when increments are reported as
* V8 may consult global heuristics on whether to trigger garbage collection
* on this change.
*/
void IncreaseAllocatedSize(size_t bytes);

/*
* Returns the v8::Isolate this tracer is attached too and |nullptr| if it
* is not attached to any v8::Isolate.
Expand Down
12 changes: 0 additions & 12 deletions src/api/api.cc
Expand Up @@ -41,7 +41,6 @@
#include "src/frames-inl.h"
#include "src/global-handles.h"
#include "src/globals.h"
#include "src/heap/embedder-tracing.h"
#include "src/heap/heap-inl.h"
#include "src/init/bootstrapper.h"
#include "src/init/icu_util.h"
Expand Down Expand Up @@ -10147,17 +10146,6 @@ void EmbedderHeapTracer::GarbageCollectionForTesting(
kGCCallbackFlagForced);
}

void EmbedderHeapTracer::IncreaseAllocatedSize(size_t bytes) {
if (isolate_) {
i::LocalEmbedderHeapTracer* const tracer =
reinterpret_cast<i::Isolate*>(isolate_)
->heap()
->local_embedder_heap_tracer();
DCHECK_NOT_NULL(tracer);
tracer->IncreaseAllocatedSize(bytes);
}
}

void EmbedderHeapTracer::RegisterEmbedderReference(
const TracedGlobal<v8::Value>& ref) {
if (ref.IsEmpty()) return;
Expand Down
2 changes: 0 additions & 2 deletions src/flag-definitions.h
Expand Up @@ -747,8 +747,6 @@ DEFINE_BOOL(huge_max_old_generation_size, false,
"Increase max size of the old space to 4 GB for x64 systems with"
"the physical memory bigger than 16 GB")
DEFINE_SIZE_T(initial_old_space_size, 0, "initial old space size (in Mbytes)")
DEFINE_BOOL(global_gc_scheduling, false,
"enable GC scheduling based on global memory")
DEFINE_BOOL(gc_global, false, "always perform global GCs")
DEFINE_INT(random_gc_interval, 0,
"Collect garbage after random(0, X) allocations. It overrides "
Expand Down
20 changes: 1 addition & 19 deletions src/heap/embedder-tracing.cc
Expand Up @@ -5,7 +5,6 @@
#include "src/heap/embedder-tracing.h"

#include "src/base/logging.h"
#include "src/heap/gc-tracer.h"
#include "src/objects/embedder-data-slot.h"
#include "src/objects/js-objects-inl.h"

Expand All @@ -32,17 +31,7 @@ void LocalEmbedderHeapTracer::TracePrologue(
void LocalEmbedderHeapTracer::TraceEpilogue() {
if (!InUse()) return;

EmbedderHeapTracer::TraceSummary summary;
remote_tracer_->TraceEpilogue(&summary);
remote_stats_.allocated_size = summary.allocated_size;
// Force a check next time increased memory is reported. This allows for
// setting limits close to actual heap sizes.
remote_stats_.allocated_size_limit_for_check = 0;
constexpr double kMinReportingTimeMs = 0.5;
if (summary.time > kMinReportingTimeMs) {
isolate_->heap()->tracer()->RecordEmbedderSpeed(summary.allocated_size,
summary.time);
}
remote_tracer_->TraceEpilogue();
}

void LocalEmbedderHeapTracer::EnterFinalPause() {
Expand Down Expand Up @@ -111,12 +100,5 @@ void LocalEmbedderHeapTracer::ProcessingScope::AddWrapperInfoForTesting(
FlushWrapperCacheIfFull();
}

void LocalEmbedderHeapTracer::StartIncrementalMarkingIfNeeded() {
Heap* heap = isolate_->heap();
heap->StartIncrementalMarkingIfAllocationLimitIsReached(
heap->GCFlagsForIncrementalMarking(),
kGCCallbackScheduleIdleGarbageCollection);
}

} // namespace internal
} // namespace v8
33 changes: 0 additions & 33 deletions src/heap/embedder-tracing.h
Expand Up @@ -76,27 +76,7 @@ class V8_EXPORT_PRIVATE LocalEmbedderHeapTracer final {
embedder_worklist_empty_ = is_empty;
}

void IncreaseAllocatedSize(size_t bytes) {
remote_stats_.allocated_size += bytes;
remote_stats_.accumulated_allocated_size += bytes;
if (remote_stats_.allocated_size >
remote_stats_.allocated_size_limit_for_check) {
StartIncrementalMarkingIfNeeded();
remote_stats_.allocated_size_limit_for_check =
remote_stats_.allocated_size + kEmbedderAllocatedThreshold;
}
}

void StartIncrementalMarkingIfNeeded();

size_t allocated_size() const { return remote_stats_.allocated_size; }
size_t accumulated_allocated_size() const {
return remote_stats_.accumulated_allocated_size;
}

private:
static constexpr size_t kEmbedderAllocatedThreshold = 128 * KB;

Isolate* const isolate_;
EmbedderHeapTracer* remote_tracer_ = nullptr;

Expand All @@ -108,19 +88,6 @@ class V8_EXPORT_PRIVATE LocalEmbedderHeapTracer final {
// segments of potential embedder fields to move to the main thread.
bool embedder_worklist_empty_ = false;

struct RemoteStatistics {
// Allocated size of objects in bytes reported by the embedder. Updated via
// TraceSummary at the end of tracing and incrementally when the GC is not
// in progress.
size_t allocated_size = 0;
// Limit for |allocated_size_| in bytes to avoid checking for starting a GC
// on each increment.
size_t allocated_size_limit_for_check = 0;
// Totally accumulated bytes allocated by the embedder. Monotonically
// increasing value. Used to approximate allocation rate.
size_t accumulated_allocated_size = 0;
} remote_stats_;

friend class EmbedderStackStateScope;
};

Expand Down
57 changes: 5 additions & 52 deletions src/heap/gc-tracer.cc
Expand Up @@ -191,7 +191,6 @@ void GCTracer::ResetForTesting() {
recorded_incremental_mark_compacts_.Reset();
recorded_new_generation_allocations_.Reset();
recorded_old_generation_allocations_.Reset();
recorded_embedder_generation_allocations_.Reset();
recorded_context_disposal_times_.Reset();
recorded_survival_ratios_.Reset();
start_counter_ = 0;
Expand Down Expand Up @@ -222,8 +221,7 @@ void GCTracer::Start(GarbageCollector collector,
previous_ = current_;
double start_time = heap_->MonotonicallyIncreasingTimeInMs();
SampleAllocation(start_time, heap_->NewSpaceAllocationCounter(),
heap_->OldGenerationAllocationCounter(),
heap_->EmbedderAllocationCounter());
heap_->OldGenerationAllocationCounter());

switch (collector) {
case SCAVENGER:
Expand Down Expand Up @@ -377,16 +375,15 @@ void GCTracer::Stop(GarbageCollector collector) {
}
}


void GCTracer::SampleAllocation(double current_ms,
size_t new_space_counter_bytes,
size_t old_generation_counter_bytes,
size_t embedder_allocation_bytes) {
size_t old_generation_counter_bytes) {
if (allocation_time_ms_ == 0) {
// It is the first sample.
allocation_time_ms_ = current_ms;
new_space_allocation_counter_bytes_ = new_space_counter_bytes;
old_generation_allocation_counter_bytes_ = old_generation_counter_bytes;
embedder_allocation_counter_bytes_ = embedder_allocation_bytes;
return;
}
// This assumes that counters are unsigned integers so that the subtraction
Expand All @@ -395,8 +392,6 @@ void GCTracer::SampleAllocation(double current_ms,
new_space_counter_bytes - new_space_allocation_counter_bytes_;
size_t old_generation_allocated_bytes =
old_generation_counter_bytes - old_generation_allocation_counter_bytes_;
size_t embedder_allocated_bytes =
embedder_allocation_bytes - embedder_allocation_counter_bytes_;
double duration = current_ms - allocation_time_ms_;
allocation_time_ms_ = current_ms;
new_space_allocation_counter_bytes_ = new_space_counter_bytes;
Expand All @@ -405,9 +400,9 @@ void GCTracer::SampleAllocation(double current_ms,
new_space_allocation_in_bytes_since_gc_ += new_space_allocated_bytes;
old_generation_allocation_in_bytes_since_gc_ +=
old_generation_allocated_bytes;
embedder_allocation_in_bytes_since_gc_ += embedder_allocated_bytes;
}


void GCTracer::AddAllocation(double current_ms) {
allocation_time_ms_ = current_ms;
if (allocation_duration_since_gc_ > 0) {
Expand All @@ -417,13 +412,10 @@ void GCTracer::AddAllocation(double current_ms) {
recorded_old_generation_allocations_.Push(
MakeBytesAndDuration(old_generation_allocation_in_bytes_since_gc_,
allocation_duration_since_gc_));
recorded_embedder_generation_allocations_.Push(MakeBytesAndDuration(
embedder_allocation_in_bytes_since_gc_, allocation_duration_since_gc_));
}
allocation_duration_since_gc_ = 0;
new_space_allocation_in_bytes_since_gc_ = 0;
old_generation_allocation_in_bytes_since_gc_ = 0;
embedder_allocation_in_bytes_since_gc_ = 0;
}


Expand Down Expand Up @@ -889,16 +881,6 @@ void GCTracer::RecordIncrementalMarkingSpeed(size_t bytes, double duration) {
}
}

void GCTracer::RecordEmbedderSpeed(size_t bytes, double duration) {
if (duration == 0 || bytes == 0) return;
double current_speed = bytes / duration;
if (recorded_embedder_speed_ == 0.0) {
recorded_embedder_speed_ = current_speed;
} else {
recorded_embedder_speed_ = (recorded_embedder_speed_ + current_speed) / 2;
}
}

void GCTracer::RecordMutatorUtilization(double mark_compact_end_time,
double mark_compact_duration) {
if (previous_mark_compact_end_time_ == 0) {
Expand Down Expand Up @@ -937,6 +919,7 @@ double GCTracer::CurrentMarkCompactMutatorUtilization() const {
}

double GCTracer::IncrementalMarkingSpeedInBytesPerMillisecond() const {
const int kConservativeSpeedInBytesPerMillisecond = 128 * KB;
if (recorded_incremental_marking_speed_ != 0) {
return recorded_incremental_marking_speed_;
}
Expand All @@ -946,13 +929,6 @@ double GCTracer::IncrementalMarkingSpeedInBytesPerMillisecond() const {
return kConservativeSpeedInBytesPerMillisecond;
}

double GCTracer::EmbedderSpeedInBytesPerMillisecond() const {
if (recorded_embedder_speed_ != 0.0) {
return recorded_embedder_speed_;
}
return kConservativeSpeedInBytesPerMillisecond;
}

double GCTracer::ScavengeSpeedInBytesPerMillisecond(
ScavengeSpeedMode mode) const {
if (mode == kForAllObjects) {
Expand Down Expand Up @@ -999,15 +975,6 @@ double GCTracer::CombinedMarkCompactSpeedInBytesPerMillisecond() {
return combined_mark_compact_speed_cache_;
}

double GCTracer::CombineSpeedsInBytesPerMillisecond(double default_speed,
double optional_speed) {
constexpr double kMinimumSpeed = 0.5;
if (optional_speed < kMinimumSpeed) {
return default_speed;
}
return default_speed * optional_speed / (default_speed + optional_speed);
}

double GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond(
double time_ms) const {
size_t bytes = new_space_allocation_in_bytes_since_gc_;
Expand All @@ -1024,14 +991,6 @@ double GCTracer::OldGenerationAllocationThroughputInBytesPerMillisecond(
MakeBytesAndDuration(bytes, durations), time_ms);
}

double GCTracer::EmbedderAllocationThroughputInBytesPerMillisecond(
double time_ms) const {
size_t bytes = embedder_allocation_in_bytes_since_gc_;
double durations = allocation_duration_since_gc_;
return AverageSpeed(recorded_embedder_generation_allocations_,
MakeBytesAndDuration(bytes, durations), time_ms);
}

double GCTracer::AllocationThroughputInBytesPerMillisecond(
double time_ms) const {
return NewSpaceAllocationThroughputInBytesPerMillisecond(time_ms) +
Expand All @@ -1048,12 +1007,6 @@ double GCTracer::CurrentOldGenerationAllocationThroughputInBytesPerMillisecond()
kThroughputTimeFrameMs);
}

double GCTracer::CurrentEmbedderAllocationThroughputInBytesPerMillisecond()
const {
return EmbedderAllocationThroughputInBytesPerMillisecond(
kThroughputTimeFrameMs);
}

double GCTracer::ContextDisposalRateInMilliseconds() const {
if (recorded_context_disposal_times_.Count() <
recorded_context_disposal_times_.kSize)
Expand Down

0 comments on commit 5e043f2

Please sign in to comment.