Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: src/heap/memory-reducer.cc

Issue 1705183003: Activate memory reducer for small heaps in background tabs. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: typo Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/memory-reducer.h ('k') | test/unittests/heap/memory-reducer-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/heap/memory-reducer.h" 5 #include "src/heap/memory-reducer.h"
6 6
7 #include "src/flags.h" 7 #include "src/flags.h"
8 #include "src/heap/gc-tracer.h" 8 #include "src/heap/gc-tracer.h"
9 #include "src/heap/heap-inl.h" 9 #include "src/heap/heap-inl.h"
10 #include "src/utils.h" 10 #include "src/utils.h"
(...skipping 29 matching lines...) Expand all
40 optimize_for_memory ? "background" : "foreground"); 40 optimize_for_memory ? "background" : "foreground");
41 } 41 }
42 event.type = kTimer; 42 event.type = kTimer;
43 event.time_ms = time_ms; 43 event.time_ms = time_ms;
44 // The memory reducer will start incremental markig if 44 // The memory reducer will start incremental markig if
45 // 1) mutator is likely idle: js call rate is low and allocation rate is low. 45 // 1) mutator is likely idle: js call rate is low and allocation rate is low.
46 // 2) mutator is in background: optimize for memory flag is set. 46 // 2) mutator is in background: optimize for memory flag is set.
47 event.should_start_incremental_gc = is_idle || optimize_for_memory; 47 event.should_start_incremental_gc = is_idle || optimize_for_memory;
48 event.can_start_incremental_gc = 48 event.can_start_incremental_gc =
49 heap->incremental_marking()->IsStopped() && 49 heap->incremental_marking()->IsStopped() &&
50 heap->incremental_marking()->CanBeActivated(); 50 (heap->incremental_marking()->CanBeActivated() || optimize_for_memory);
51 memory_reducer_->NotifyTimer(event); 51 memory_reducer_->NotifyTimer(event);
52 } 52 }
53 53
54 54
55 double MemoryReducer::SampleAndGetJsCallsPerMs(double time_ms) { 55 double MemoryReducer::SampleAndGetJsCallsPerMs(double time_ms) {
56 unsigned int counter = heap()->isolate()->js_calls_from_api_counter(); 56 unsigned int counter = heap()->isolate()->js_calls_from_api_counter();
57 unsigned int call_delta = counter - js_calls_counter_; 57 unsigned int call_delta = counter - js_calls_counter_;
58 double time_delta_ms = time_ms - js_calls_sample_time_ms_; 58 double time_delta_ms = time_ms - js_calls_sample_time_ms_;
59 js_calls_counter_ = counter; 59 js_calls_counter_ = counter;
60 js_calls_sample_time_ms_ = time_ms; 60 js_calls_sample_time_ms_ = time_ms;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 111 }
112 if (old_action == kRun) { 112 if (old_action == kRun) {
113 if (FLAG_trace_gc_verbose) { 113 if (FLAG_trace_gc_verbose) {
114 PrintIsolate(heap()->isolate(), "Memory reducer: finished GC #%d (%s)\n", 114 PrintIsolate(heap()->isolate(), "Memory reducer: finished GC #%d (%s)\n",
115 state_.started_gcs, 115 state_.started_gcs,
116 state_.action == kWait ? "will do more" : "done"); 116 state_.action == kWait ? "will do more" : "done");
117 } 117 }
118 } 118 }
119 } 119 }
120 120
121 121 void MemoryReducer::NotifyPossibleGarbage(const Event& event) {
122 void MemoryReducer::NotifyContextDisposed(const Event& event) { 122 DCHECK_EQ(kPossibleGarbage, event.type);
123 DCHECK_EQ(kContextDisposed, event.type);
124 Action old_action = state_.action; 123 Action old_action = state_.action;
125 state_ = Step(state_, event); 124 state_ = Step(state_, event);
126 if (old_action != kWait && state_.action == kWait) { 125 if (old_action != kWait && state_.action == kWait) {
127 // If we are transitioning to the WAIT state, start the timer. 126 // If we are transitioning to the WAIT state, start the timer.
128 ScheduleTimer(event.time_ms, state_.next_gc_start_ms - event.time_ms); 127 ScheduleTimer(event.time_ms, state_.next_gc_start_ms - event.time_ms);
129 } 128 }
130 } 129 }
131 130
132 131
133 bool MemoryReducer::WatchdogGC(const State& state, const Event& event) { 132 bool MemoryReducer::WatchdogGC(const State& state, const Event& event) {
134 return state.last_gc_time_ms != 0 && 133 return state.last_gc_time_ms != 0 &&
135 event.time_ms > state.last_gc_time_ms + kWatchdogDelayMs; 134 event.time_ms > state.last_gc_time_ms + kWatchdogDelayMs;
136 } 135 }
137 136
138 137
139 // For specification of this function see the comment for MemoryReducer class. 138 // For specification of this function see the comment for MemoryReducer class.
140 MemoryReducer::State MemoryReducer::Step(const State& state, 139 MemoryReducer::State MemoryReducer::Step(const State& state,
141 const Event& event) { 140 const Event& event) {
142 if (!FLAG_incremental_marking || !FLAG_memory_reducer) { 141 if (!FLAG_incremental_marking || !FLAG_memory_reducer) {
143 return State(kDone, 0, 0, state.last_gc_time_ms); 142 return State(kDone, 0, 0, state.last_gc_time_ms);
144 } 143 }
145 switch (state.action) { 144 switch (state.action) {
146 case kDone: 145 case kDone:
147 if (event.type == kTimer) { 146 if (event.type == kTimer) {
148 return state; 147 return state;
149 } else { 148 } else {
150 DCHECK(event.type == kContextDisposed || event.type == kMarkCompact); 149 DCHECK(event.type == kPossibleGarbage || event.type == kMarkCompact);
151 return State( 150 return State(
152 kWait, 0, event.time_ms + kLongDelayMs, 151 kWait, 0, event.time_ms + kLongDelayMs,
153 event.type == kMarkCompact ? event.time_ms : state.last_gc_time_ms); 152 event.type == kMarkCompact ? event.time_ms : state.last_gc_time_ms);
154 } 153 }
155 case kWait: 154 case kWait:
156 switch (event.type) { 155 switch (event.type) {
157 case kContextDisposed: 156 case kPossibleGarbage:
158 return state; 157 return state;
159 case kTimer: 158 case kTimer:
160 if (state.started_gcs >= kMaxNumberOfGCs) { 159 if (state.started_gcs >= kMaxNumberOfGCs) {
161 return State(kDone, kMaxNumberOfGCs, 0.0, state.last_gc_time_ms); 160 return State(kDone, kMaxNumberOfGCs, 0.0, state.last_gc_time_ms);
162 } else if (event.can_start_incremental_gc && 161 } else if (event.can_start_incremental_gc &&
163 (event.should_start_incremental_gc || 162 (event.should_start_incremental_gc ||
164 WatchdogGC(state, event))) { 163 WatchdogGC(state, event))) {
165 if (state.next_gc_start_ms <= event.time_ms) { 164 if (state.next_gc_start_ms <= event.time_ms) {
166 return State(kRun, state.started_gcs + 1, 0.0, 165 return State(kRun, state.started_gcs + 1, 0.0,
167 state.last_gc_time_ms); 166 state.last_gc_time_ms);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 auto timer_task = new MemoryReducer::TimerTask(this); 203 auto timer_task = new MemoryReducer::TimerTask(this);
205 V8::GetCurrentPlatform()->CallDelayedOnForegroundThread( 204 V8::GetCurrentPlatform()->CallDelayedOnForegroundThread(
206 isolate, timer_task, (delay_ms + kSlackMs) / 1000.0); 205 isolate, timer_task, (delay_ms + kSlackMs) / 1000.0);
207 } 206 }
208 207
209 208
210 void MemoryReducer::TearDown() { state_ = State(kDone, 0, 0, 0.0); } 209 void MemoryReducer::TearDown() { state_ = State(kDone, 0, 0, 0.0); }
211 210
212 } // namespace internal 211 } // namespace internal
213 } // namespace v8 212 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/memory-reducer.h ('k') | test/unittests/heap/memory-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698