OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_OOM_PRIORITY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_OOM_PRIORITY_MANAGER_H_ |
6 #define CHROME_BROWSER_OOM_PRIORITY_MANAGER_H_ | 6 #define CHROME_BROWSER_OOM_PRIORITY_MANAGER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/timer.h" | 10 #include "base/timer.h" |
11 #include "base/process.h" | 11 #include "base/process.h" |
12 | 12 |
13 namespace browser { | 13 namespace browser { |
14 | 14 |
15 // The OomPriorityManager periodically checks (see | 15 // The OomPriorityManager periodically checks (see |
16 // ADJUSTMENT_INTERVAL_SECONDS in the source) the status of renderers | 16 // ADJUSTMENT_INTERVAL_SECONDS in the source) the status of renderers |
17 // and adjusts the out of memory (OOM) adjustment value (in | 17 // and adjusts the out of memory (OOM) adjustment value (in |
18 // /proc/<pid>/oom_adj) of the renderers so that they match the | 18 // /proc/<pid>/oom_score_adj) of the renderers so that they match the |
19 // algorithm embedded here for priority in being killed upon OOM | 19 // algorithm embedded here for priority in being killed upon OOM |
20 // conditions. | 20 // conditions. |
21 // | 21 // |
22 // The algorithm used favors killing tabs that are not pinned, have | 22 // The algorithm used favors killing tabs that are not pinned, have |
23 // been idle for longest, and take up the most memory, in that order | 23 // been idle for longest, and take up the most memory, in that order |
24 // of priority. We round the idle times to the nearest few minutes | 24 // of priority. We round the idle times to the nearest few minutes |
25 // (see BUCKET_INTERVAL_MINUTES in the source) so that we can bucket | 25 // (see BUCKET_INTERVAL_MINUTES in the source) so that we can bucket |
26 // them, as no two tabs will have exactly the same idle time. | 26 // them, as no two tabs will have exactly the same idle time. |
27 class OomPriorityManager { | 27 class OomPriorityManager { |
28 public: | 28 public: |
29 OomPriorityManager(); | 29 OomPriorityManager(); |
30 ~OomPriorityManager(); | 30 ~OomPriorityManager(); |
31 | 31 |
32 private: | 32 private: |
33 struct RendererStats { | 33 struct RendererStats { |
34 bool is_pinned; | 34 bool is_pinned; |
| 35 bool is_selected; |
35 base::TimeTicks last_selected; | 36 base::TimeTicks last_selected; |
36 size_t memory_used; | 37 size_t memory_used; |
37 base::ProcessHandle renderer_handle; | 38 base::ProcessHandle renderer_handle; |
38 }; | 39 }; |
39 typedef std::list<RendererStats> StatsList; | 40 typedef std::list<RendererStats> StatsList; |
40 | 41 |
41 void StartTimer(); | 42 void StartTimer(); |
42 void StopTimer(); | 43 void StopTimer(); |
43 | 44 |
44 // Posts DoAdjustOomPriorities task to the file thread. Called when | 45 // Posts DoAdjustOomPriorities task to the file thread. Called when |
45 // the timer fires. | 46 // the timer fires. |
46 void AdjustOomPriorities(); | 47 void AdjustOomPriorities(); |
47 | 48 |
48 // Called by AdjustOomPriorities. Runs on the file thread. | 49 // Called by AdjustOomPriorities. Runs on the file thread. |
49 void DoAdjustOomPriorities(StatsList list); | 50 void DoAdjustOomPriorities(StatsList list); |
50 | 51 |
51 static bool CompareRendererStats(RendererStats first, RendererStats second); | 52 static bool CompareRendererStats(RendererStats first, RendererStats second); |
52 | 53 |
53 base::RepeatingTimer<OomPriorityManager> timer_; | 54 base::RepeatingTimer<OomPriorityManager> timer_; |
54 | 55 |
55 DISALLOW_COPY_AND_ASSIGN(OomPriorityManager); | 56 DISALLOW_COPY_AND_ASSIGN(OomPriorityManager); |
56 }; | 57 }; |
57 } // namespace browser | 58 } // namespace browser |
58 | 59 |
59 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser::OomPriorityManager); | 60 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser::OomPriorityManager); |
60 | 61 |
61 #endif // CHROME_BROWSER_OOM_PRIORITY_MANAGER_H_ | 62 #endif // CHROME_BROWSER_OOM_PRIORITY_MANAGER_H_ |
OLD | NEW |