[heap] Adjust number of parallel compaction tasks
authormlippautz <mlippautz@chromium.org>
Mon, 28 Sep 2015 08:32:40 +0000 (01:32 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 28 Sep 2015 08:35:48 +0000 (08:35 +0000)
This is a trivial spinoff of the more complicated CL splitting up memory:
  https://codereview.chromium.org/1365743003/

- Parallel compaction is still off.
- We now compute the number of parallel compaction tasks, depending on the
  evacuation candidate list, the number of cores, and some hard limit.

BUG=chromium:524425
LOG=N

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

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

src/heap/mark-compact.cc
src/heap/mark-compact.h

index 87e1b34..bf49e28 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "src/base/atomicops.h"
 #include "src/base/bits.h"
+#include "src/base/sys-info.h"
 #include "src/code-stubs.h"
 #include "src/compilation-cache.h"
 #include "src/cpu-profiler.h"
@@ -3370,13 +3371,24 @@ bool MarkCompactCollector::EvacuateLiveObjectsFromPage(
 }
 
 
+int MarkCompactCollector::NumberOfParallelCompactionTasks() {
+  if (!FLAG_parallel_compaction) return 1;
+  // We cap the number of parallel compaction tasks by
+  // - (#cores - 1)
+  // - a value depending on the list of evacuation candidates
+  // - a hard limit
+  const int kPagesPerCompactionTask = 4;
+  const int kMaxCompactionTasks = 8;
+  return Min(kMaxCompactionTasks,
+             Min(1 + evacuation_candidates_.length() / kPagesPerCompactionTask,
+                 Max(1, base::SysInfo::NumberOfProcessors() - 1)));
+}
+
+
 void MarkCompactCollector::EvacuatePagesInParallel() {
   if (evacuation_candidates_.length() == 0) return;
 
-  int num_tasks = 1;
-  if (FLAG_parallel_compaction) {
-    num_tasks = NumberOfParallelCompactionTasks();
-  }
+  const int num_tasks = NumberOfParallelCompactionTasks();
 
   // Set up compaction spaces.
   CompactionSpaceCollection** compaction_spaces_for_tasks =
index 6558eb2..724650c 100644 (file)
@@ -709,11 +709,8 @@ class MarkCompactCollector {
 
   void EvacuatePagesInParallel();
 
-  int NumberOfParallelCompactionTasks() {
-    // TODO(hpayer, mlippautz): Figure out some logic to determine the number
-    // of compaction tasks.
-    return 1;
-  }
+  // The number of parallel compaction tasks, including the main thread.
+  int NumberOfParallelCompactionTasks();
 
   void WaitUntilCompactionCompleted();