From 660d4fa7b0a8c487e163d1dd1c76a83a7e31f802 Mon Sep 17 00:00:00 2001 From: mlippautz Date: Mon, 28 Sep 2015 01:32:40 -0700 Subject: [PATCH] [heap] Adjust number of parallel compaction tasks 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 | 20 ++++++++++++++++---- src/heap/mark-compact.h | 7 ++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc index 87e1b34..bf49e28 100644 --- a/src/heap/mark-compact.cc +++ b/src/heap/mark-compact.cc @@ -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 = diff --git a/src/heap/mark-compact.h b/src/heap/mark-compact.h index 6558eb2..724650c 100644 --- a/src/heap/mark-compact.h +++ b/src/heap/mark-compact.h @@ -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(); -- 2.7.4