Uncommit and shrink semi-spaces only on low allocation rate.
authorhpayer <hpayer@chromium.org>
Fri, 22 May 2015 11:43:11 +0000 (04:43 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 22 May 2015 11:42:52 +0000 (11:42 +0000)
BUG=chromium:481811
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#28585}

src/heap/gc-idle-time-handler.cc
src/heap/gc-idle-time-handler.h
src/heap/gc-tracer.cc
src/heap/gc-tracer.h
src/heap/heap.cc
src/heap/heap.h
src/heap/spaces.h
test/cctest/test-heap.cc

index e88710bd1d10533c8905aab3ef1a8422e95feba2..86587c6fd19671d919a291da07a31a21fcdf4886 100644 (file)
@@ -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);
 }
 
 
index 5c0a80a1d25653107afac42b393bc16179977646..e5b671cd063d9b4e36444a23fc8908dfbda07ab9 100644 (file)
@@ -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()
index 927915d7554bae15b4e26c43b997734824f8c231..815baa440c308bf4fd619929e74a09db7fa11cf3 100644 (file)
@@ -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;
 
index df30dccb6b5dd18d3ea4694241d348bbb7514e91..7fb6a766a6037181758eebd67eadaaa8f23b8bef 100644 (file)
@@ -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.
index 8b08802f461acd17f24c2e2676a39f2812fcd684..4e4f04a11293e71b330eba36293406c69c8e628d 100644 (file)
@@ -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()) {
index 8ecf7ae1328df4e495242eb777a128b1e7d6efc0..742aa4ba89c0c3535e7a3c7d8ab0b473479e2544 100644 (file)
@@ -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,
index 9f57ecc3dd92e533ed59cbed048c319b093adf08..c81cf77257407fc25bea7466703f9a875df7d8b5 100644 (file)
@@ -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_;
   }
index d9d2a861ebf30d4644d91f71ee49ceaf10627f47..a37da264d498e1ef438e36f1c98ce36da109cb2a 100644 (file)
@@ -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);