Commit 96eb702e authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Oilpan: Update incremental marking step duration dynamically

Calls UpdateIncrementalMarkingStepDuration() every time we allocate a new page.
UpdateIncrementalMarkingStepDuration() will check if the estimated time left is increasing (i.e. marking speed is not keeping up with allocations).
If so it will double the step size.

Also increases default duration from 1ms to 2ms.

Bug: 757440
Change-Id: Icf262a4b851fd730698e6b09384c5c181c671de2
Reviewed-on: https://chromium-review.googlesource.com/1105695
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572208}
parent 59f0d053
......@@ -222,6 +222,10 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector {
// Statistics for the previously running garbage collection.
const Event& previous() const { return previous_; }
TimeDelta marking_time_so_far() const {
return TimeDelta::FromMilliseconds(current_.marking_time_in_ms());
}
private:
// Statistics for the currently running garbage collection. Note that the
// Event may not be fully populated yet as some phase may not have been run.
......
......@@ -88,8 +88,8 @@ const size_t kDefaultAllocatedObjectSizeThreshold = 100 * 1024;
// Duration of one incremental marking step. Should be short enough that it
// doesn't cause jank even though it is scheduled as a normal task.
constexpr TimeDelta kIncrementalMarkingStepDuration =
TimeDelta::FromMilliseconds(1);
constexpr TimeDelta kDefaultIncrementalMarkingStepDuration =
TimeDelta::FromMilliseconds(2);
constexpr size_t kMaxTerminationGCLoops = 20;
......@@ -600,6 +600,8 @@ void ThreadState::ScheduleGCIfNeeded() {
VLOG(2) << "[state:" << this << "] ScheduleGCIfNeeded";
DCHECK(CheckThread());
UpdateIncrementalMarkingStepDuration();
// Allocation is allowed during sweeping, but those allocations should not
// trigger nested GCs.
if (IsGCForbidden() || SweepForbidden())
......@@ -1451,6 +1453,9 @@ void ThreadState::IncrementalMarkingStart(BlinkGC::GCReason reason) {
Heap().stats_collector(),
ThreadHeapStatsCollector::kIncrementalMarkingStartMarking);
AtomicPauseScope atomic_pause_scope(this);
next_incremental_marking_step_duration_ =
kDefaultIncrementalMarkingStepDuration;
previous_incremental_marking_time_left_ = TimeDelta::Max();
MarkPhasePrologue(BlinkGC::kNoHeapPointersOnStack,
BlinkGC::kIncrementalMarking, reason);
MarkPhaseVisitRoots();
......@@ -1468,8 +1473,8 @@ void ThreadState::IncrementalMarkingStep() {
<< "IncrementalMarking: Step";
AtomicPauseScope atomic_pause_scope(this);
DCHECK(IsMarkingInProgress());
bool complete = MarkPhaseAdvanceMarking(CurrentTimeTicks() +
kIncrementalMarkingStepDuration);
bool complete = MarkPhaseAdvanceMarking(
CurrentTimeTicks() + next_incremental_marking_step_duration_);
if (complete)
ScheduleIncrementalMarkingFinalize();
else
......@@ -1758,4 +1763,17 @@ void ThreadState::CollectAllGarbage() {
}
}
void ThreadState::UpdateIncrementalMarkingStepDuration() {
if (!IsIncrementalMarking())
return;
TimeDelta time_left = Heap().stats_collector()->estimated_marking_time() -
Heap().stats_collector()->marking_time_so_far();
// Increase step size if estimated time left is increasing.
if (previous_incremental_marking_time_left_ < time_left) {
constexpr double ratio = 2.0;
next_incremental_marking_step_duration_ *= ratio;
}
previous_incremental_marking_time_left_ = time_left;
}
} // namespace blink
......@@ -655,6 +655,8 @@ class PLATFORM_EXPORT ThreadState {
void RunScheduledGC(BlinkGC::StackState);
void UpdateIncrementalMarkingStepDuration();
void EagerSweep();
void InvokePreFinalizers();
......@@ -703,6 +705,9 @@ class PLATFORM_EXPORT ThreadState {
bool object_resurrection_forbidden_;
bool in_atomic_pause_;
TimeDelta next_incremental_marking_step_duration_;
TimeDelta previous_incremental_marking_time_left_;
GarbageCollectedMixinConstructorMarkerBase* gc_mixin_marker_;
GCState gc_state_;
......
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