Commit f034d6d8 authored by hpayer's avatar hpayer Committed by Commit bot

Uncommit and shrink semi-spaces only on low allocation rate.

BUG=chromium:481811
LOG=n

Review URL: https://codereview.chromium.org/1148633005

Cr-Commit-Position: refs/heads/master@{#28585}
parent eb0024d1
......@@ -58,8 +58,10 @@ void GCIdleTimeHandler::HeapState::Print() {
PrintF("scavenge_speed=%" V8_PTR_PREFIX "d ", scavenge_speed_in_bytes_per_ms);
PrintF("new_space_size=%" V8_PTR_PREFIX "d ", used_new_space_size);
PrintF("new_space_capacity=%" V8_PTR_PREFIX "d ", new_space_capacity);
PrintF("new_space_allocation_throughput=%" V8_PTR_PREFIX "d",
PrintF("new_space_allocation_throughput=%" V8_PTR_PREFIX "d ",
new_space_allocation_throughput_in_bytes_per_ms);
PrintF("current_new_space_allocation_throughput=%" V8_PTR_PREFIX "d",
current_new_space_allocation_throughput_in_bytes_per_ms);
}
......
......@@ -188,6 +188,7 @@ class GCIdleTimeHandler {
size_t used_new_space_size;
size_t new_space_capacity;
size_t new_space_allocation_throughput_in_bytes_per_ms;
size_t current_new_space_allocation_throughput_in_bytes_per_ms;
};
GCIdleTimeHandler()
......
......@@ -610,7 +610,7 @@ size_t GCTracer::NewSpaceAllocatedBytesInLast(double time_ms) const {
++iter;
}
if (durations < time_ms) return 0;
if (durations == 0.0) return 0;
bytes = static_cast<size_t>(bytes * (time_ms / durations) + 0.5);
// Return at least 1 since 0 means "no data".
......@@ -618,6 +618,15 @@ size_t GCTracer::NewSpaceAllocatedBytesInLast(double time_ms) const {
}
size_t GCTracer::CurrentNewSpaceAllocationThroughputInBytesPerMillisecond()
const {
static const double kThroughputTimeFrame = 5000;
size_t allocated_bytes = NewSpaceAllocatedBytesInLast(kThroughputTimeFrame);
if (allocated_bytes == 0) return 0;
return static_cast<size_t>((allocated_bytes / kThroughputTimeFrame) + 1);
}
double GCTracer::ContextDisposalRateInMilliseconds() const {
if (context_disposal_events_.size() < kRingBufferMaxSize) return 0.0;
......
......@@ -389,6 +389,11 @@ class GCTracer {
// Returns 0 if no allocation events have been recorded.
size_t NewSpaceAllocatedBytesInLast(double time_ms) const;
// Allocation throughput in the new space in bytes/milliseconds in
// the last five seconds.
// Returns 0 if no allocation events have been recorded.
size_t CurrentNewSpaceAllocationThroughputInBytesPerMillisecond() const;
// Computes the context disposal rate in milliseconds. It takes the time
// frame of the first recorded context disposal to the current time and
// divides it by the number of recorded events.
......
......@@ -733,6 +733,9 @@ void Heap::GarbageCollectionEpilogue() {
// whether we allocated in new space since the last GC.
new_space_top_after_last_gc_ = new_space()->top();
last_gc_time_ = MonotonicallyIncreasingTimeInMs();
ReduceNewSpaceSize(
tracer()->CurrentNewSpaceAllocationThroughputInBytesPerMillisecond());
}
......@@ -4569,11 +4572,15 @@ void Heap::MakeHeapIterable() {
}
void Heap::ReduceNewSpaceSize(GCIdleTimeAction action) {
if (action.reduce_memory &&
(action.type == DO_SCAVENGE || action.type == DO_FULL_GC ||
(action.type == DO_INCREMENTAL_MARKING &&
incremental_marking()->IsStopped()))) {
bool Heap::HasLowAllocationRate(size_t allocation_rate) {
static const size_t kLowAllocationRate = 1000;
if (allocation_rate == 0) return false;
return allocation_rate < kLowAllocationRate;
}
void Heap::ReduceNewSpaceSize(size_t allocation_rate) {
if (HasLowAllocationRate(allocation_rate)) {
new_space_.Shrink();
UncommitFromSpace();
}
......@@ -4639,6 +4646,8 @@ GCIdleTimeHandler::HeapState Heap::ComputeHeapState(bool reduce_memory) {
heap_state.new_space_capacity = new_space_.Capacity();
heap_state.new_space_allocation_throughput_in_bytes_per_ms =
tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond();
heap_state.current_new_space_allocation_throughput_in_bytes_per_ms =
tracer()->CurrentNewSpaceAllocationThroughputInBytesPerMillisecond();
return heap_state;
}
......@@ -4701,7 +4710,6 @@ bool Heap::PerformIdleTimeAction(GCIdleTimeAction action,
break;
}
ReduceNewSpaceSize(action);
return result;
}
......@@ -4966,6 +4974,7 @@ void Heap::Verify() {
void Heap::ZapFromSpace() {
if (!new_space_.IsFromSpaceCommitted()) return;
NewSpacePageIterator it(new_space_.FromSpaceStart(),
new_space_.FromSpaceEnd());
while (it.has_next()) {
......
......@@ -2127,7 +2127,9 @@ class Heap {
void SelectScavengingVisitorsTable();
void ReduceNewSpaceSize(GCIdleTimeAction action);
bool HasLowAllocationRate(size_t allocaion_rate);
void ReduceNewSpaceSize(size_t allocaion_rate);
bool TryFinalizeIdleIncrementalMarking(
double idle_time_in_ms, size_t size_of_objects,
......
......@@ -2607,6 +2607,8 @@ class NewSpace : public Space {
return from_space_.Uncommit();
}
bool IsFromSpaceCommitted() { return from_space_.is_committed(); }
inline intptr_t inline_allocation_limit_step() {
return inline_allocation_limit_step_;
}
......
......@@ -5551,7 +5551,7 @@ TEST(NewSpaceAllocationThroughput2) {
size_t counter2 = 2000;
tracer->SampleNewSpaceAllocation(time2, counter2);
size_t bytes = tracer->NewSpaceAllocatedBytesInLast(1000);
CHECK_EQ(0, bytes);
CHECK_EQ(10000, bytes);
int time3 = 1000;
size_t counter3 = 30000;
tracer->SampleNewSpaceAllocation(time3, counter3);
......
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