OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium 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 #ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ |
6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ | 6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 23 matching lines...) Expand all Loading... |
34 // important. | 34 // important. |
35 enum class ProcessType { | 35 enum class ProcessType { |
36 // Conceptually, the system cannot have both FOCUSED_TAB and FOCUSED_APP at | 36 // Conceptually, the system cannot have both FOCUSED_TAB and FOCUSED_APP at |
37 // the same time, but because Chrome cannot retrieve FOCUSED_APP status | 37 // the same time, but because Chrome cannot retrieve FOCUSED_APP status |
38 // synchronously, Chrome may still see both at the same time. When that | 38 // synchronously, Chrome may still see both at the same time. When that |
39 // happens, treat FOCUSED_TAB as the most important since the (synchronously | 39 // happens, treat FOCUSED_TAB as the most important since the (synchronously |
40 // retrieved) tab information is more reliable and up-to-date. | 40 // retrieved) tab information is more reliable and up-to-date. |
41 FOCUSED_TAB = 1, | 41 FOCUSED_TAB = 1, |
42 FOCUSED_APP = 2, | 42 FOCUSED_APP = 2, |
43 | 43 |
44 VISIBLE_APP = 3, | 44 // Important apps are protected in two ways: 1) Chrome never kills them, and |
| 45 // 2) the kernel is still allowed to kill them, but their OOM adjustment |
| 46 // scores are better than BACKGROUND_TABs and BACKGROUND_APPs. |
| 47 IMPORTANT_APP = 3, |
| 48 |
45 BACKGROUND_TAB = 4, | 49 BACKGROUND_TAB = 4, |
46 BACKGROUND_APP = 5, | 50 BACKGROUND_APP = 5, |
47 UNKNOWN_TYPE = 6, | 51 UNKNOWN_TYPE = 6, |
48 }; | 52 }; |
49 | 53 |
50 // The Chrome OS TabManagerDelegate is responsible for keeping the | 54 // The Chrome OS TabManagerDelegate is responsible for keeping the |
51 // renderers' scores up to date in /proc/<pid>/oom_score_adj. | 55 // renderers' scores up to date in /proc/<pid>/oom_score_adj. |
52 class TabManagerDelegate : public aura::client::ActivationChangeObserver, | 56 class TabManagerDelegate : public aura::client::ActivationChangeObserver, |
53 public content::NotificationObserver, | 57 public content::NotificationObserver, |
54 public chrome::BrowserListObserver { | 58 public chrome::BrowserListObserver { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // Sets OOM score for processes in the range [|rbegin|, |rend|) to integers | 159 // Sets OOM score for processes in the range [|rbegin|, |rend|) to integers |
156 // distributed evenly in [|range_begin|, |range_end|). | 160 // distributed evenly in [|range_begin|, |range_end|). |
157 // The new score is set in |new_map|. | 161 // The new score is set in |new_map|. |
158 void DistributeOomScoreInRange( | 162 void DistributeOomScoreInRange( |
159 std::vector<TabManagerDelegate::Candidate>::const_iterator begin, | 163 std::vector<TabManagerDelegate::Candidate>::const_iterator begin, |
160 std::vector<TabManagerDelegate::Candidate>::const_iterator end, | 164 std::vector<TabManagerDelegate::Candidate>::const_iterator end, |
161 int range_begin, | 165 int range_begin, |
162 int range_end, | 166 int range_end, |
163 ProcessScoreMap* new_map); | 167 ProcessScoreMap* new_map); |
164 | 168 |
| 169 // Changes |candidates|' OOM scores to |score|. The new scores are set in |
| 170 // |new_map|. |
| 171 void SetOomScore(const std::vector<TabManagerDelegate::Candidate>& candidates, |
| 172 int score, |
| 173 ProcessScoreMap* new_map); |
| 174 |
165 // Initiates an oom priority adjustment. | 175 // Initiates an oom priority adjustment. |
166 void ScheduleEarlyOomPrioritiesAdjustment(); | 176 void ScheduleEarlyOomPrioritiesAdjustment(); |
167 | 177 |
168 // Returns a TimeDelta object that represents a minimum delay for killing | 178 // Returns a TimeDelta object that represents a minimum delay for killing |
169 // the same ARC process again. ARC processes sometimes respawn right after | 179 // the same ARC process again. ARC processes sometimes respawn right after |
170 // being killed. In that case, killing them every time is just a waste of | 180 // being killed. In that case, killing them every time is just a waste of |
171 // resources. | 181 // resources. |
172 static constexpr base::TimeDelta GetArcRespawnKillDelay() { | 182 static constexpr base::TimeDelta GetArcRespawnKillDelay() { |
173 return base::TimeDelta::FromSeconds(60); | 183 return base::TimeDelta::FromSeconds(60); |
174 } | 184 } |
175 | 185 |
| 186 // The lowest OOM adjustment score that will make the process non-killable. |
| 187 static const int kLowestOomScore; |
| 188 |
176 // Holds a reference to the owning TabManager. | 189 // Holds a reference to the owning TabManager. |
177 const base::WeakPtr<TabManager> tab_manager_; | 190 const base::WeakPtr<TabManager> tab_manager_; |
178 | 191 |
179 // Registrar to receive renderer notifications. | 192 // Registrar to receive renderer notifications. |
180 content::NotificationRegistrar registrar_; | 193 content::NotificationRegistrar registrar_; |
181 | 194 |
182 // Timer to guarantee that the tab or app is focused for a certain amount of | 195 // Timer to guarantee that the tab or app is focused for a certain amount of |
183 // time. | 196 // time. |
184 base::OneShotTimer focus_process_score_adjust_timer_; | 197 base::OneShotTimer focus_process_score_adjust_timer_; |
185 // Holds the info of the newly focused tab or app. Its OOM score would be | 198 // Holds the info of the newly focused tab or app. Its OOM score would be |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 // reported if available memory is under the number. | 269 // reported if available memory is under the number. |
257 static int LowMemoryMarginKB(); | 270 static int LowMemoryMarginKB(); |
258 | 271 |
259 // Reads in an integer. | 272 // Reads in an integer. |
260 static int ReadIntFromFile(const char* file_name, int default_val); | 273 static int ReadIntFromFile(const char* file_name, int default_val); |
261 }; | 274 }; |
262 | 275 |
263 } // namespace memory | 276 } // namespace memory |
264 | 277 |
265 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ | 278 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ |
OLD | NEW |