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: chrome/browser/memory/tab_manager_delegate_chromeos.h

Issue 2855973003: Revert "Do not kill recently killed ARC processes again" (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | chrome/browser/memory/tab_manager_delegate_chromeos.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 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>
10 #include <utility> 9 #include <utility>
11 #include <vector> 10 #include <vector>
12 11
13 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
14 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
15 #include "base/logging.h" 14 #include "base/logging.h"
16 #include "base/macros.h" 15 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
18 #include "base/process/process.h" 17 #include "base/process/process.h"
19 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 void LowMemoryKill(const TabStatsList& tab_stats); 71 void LowMemoryKill(const TabStatsList& tab_stats);
73 72
74 // Returns oom_score_adj of a process if the score is cached by |this|. 73 // Returns oom_score_adj of a process if the score is cached by |this|.
75 // If couldn't find the score in the cache, returns -1001 since the valid 74 // If couldn't find the score in the cache, returns -1001 since the valid
76 // range of oom_score_adj is [-1000, 1000]. 75 // range of oom_score_adj is [-1000, 1000].
77 int GetCachedOomScore(base::ProcessHandle process_handle); 76 int GetCachedOomScore(base::ProcessHandle process_handle);
78 77
79 // Called when the timer fires, sets oom_adjust_score for all renderers. 78 // Called when the timer fires, sets oom_adjust_score for all renderers.
80 void AdjustOomPriorities(const TabStatsList& tab_list); 79 void AdjustOomPriorities(const TabStatsList& tab_list);
81 80
82 // Returns true if the process has recently been killed.
83 // Virtual for unit testing.
84 virtual bool IsRecentlyKilledArcProcess(const std::string& process_name,
85 const base::TimeTicks& now);
86
87 protected: 81 protected:
88 // Kills an ARC process. Returns true if the kill request is successfully sent 82 // Kills an ARC process. Returns true if the kill request is successfully sent
89 // to Android. Virtual for unit testing. 83 // to Android. Virtual for unit testing.
90 virtual bool KillArcProcess(const int nspid); 84 virtual bool KillArcProcess(const int nspid);
91 85
92 // Kills a tab. Returns true if the tab is killed successfully. 86 // Kills a tab. Returns true if the tab is killed successfully.
93 // Virtual for unit testing. 87 // Virtual for unit testing.
94 virtual bool KillTab(int64_t tab_id); 88 virtual bool KillTab(int64_t tab_id);
95 89
96 // Get debugd client instance. Virtual for unit testing. 90 // Get debugd client instance.
97 virtual chromeos::DebugDaemonClient* GetDebugDaemonClient(); 91 virtual chromeos::DebugDaemonClient* GetDebugDaemonClient();
98 92
99 private: 93 private:
100 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, CandidatesSorted); 94 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, CandidatesSorted);
101 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, IsRecentlyKilledArcProcess);
102 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest,
103 DoNotKillRecentlyKilledArcProcesses);
104 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, KillMultipleProcesses); 95 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, KillMultipleProcesses);
105 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, SetOomScoreAdj); 96 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, SetOomScoreAdj);
106 97
107 class Candidate; 98 class Candidate;
108 class FocusedProcess; 99 class FocusedProcess;
109 100
110 friend std::ostream& operator<<(std::ostream& out, 101 friend std::ostream& operator<<(std::ostream& out,
111 const Candidate& candidate); 102 const Candidate& candidate);
112 103
113 // content::NotificationObserver: 104 // content::NotificationObserver:
114 void Observe(int type, 105 void Observe(int type,
115 const content::NotificationSource& source, 106 const content::NotificationSource& source,
116 const content::NotificationDetails& details) override; 107 const content::NotificationDetails& details) override;
117 108
118 // Pair to hold child process host id and ProcessHandle. 109 // Pair to hold child process host id and ProcessHandle.
119 typedef std::pair<int, base::ProcessHandle> ProcessInfo; 110 typedef std::pair<int, base::ProcessHandle> ProcessInfo;
120 111
121 // Cache OOM scores in memory. 112 // Cache OOM scores in memory.
122 typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap; 113 typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap;
123 114
124 // A map from an ARC process name to a monotonic timestamp when it's killed.
125 typedef base::hash_map<std::string, base::TimeTicks> KilledArcProcessesMap;
126
127 // Get the list of candidates to kill, sorted by descending importance. 115 // Get the list of candidates to kill, sorted by descending importance.
128 static std::vector<Candidate> GetSortedCandidates( 116 static std::vector<Candidate> GetSortedCandidates(
129 const TabStatsList& tab_list, 117 const TabStatsList& tab_list,
130 const std::vector<arc::ArcProcess>& arc_processes); 118 const std::vector<arc::ArcProcess>& arc_processes);
131 119
132 // Sets OOM score for the focused tab. 120 // Sets OOM score for the focused tab.
133 void OnFocusTabScoreAdjustmentTimeout(); 121 void OnFocusTabScoreAdjustmentTimeout();
134 122
135 // Kills a process after getting all info of tabs and apps. 123 // Kills a process after getting all info of tabs and apps.
136 void LowMemoryKillImpl(const TabStatsList& tab_list, 124 void LowMemoryKillImpl(const TabStatsList& tab_list,
(...skipping 17 matching lines...) Expand all
154 void DistributeOomScoreInRange( 142 void DistributeOomScoreInRange(
155 std::vector<TabManagerDelegate::Candidate>::const_iterator begin, 143 std::vector<TabManagerDelegate::Candidate>::const_iterator begin,
156 std::vector<TabManagerDelegate::Candidate>::const_iterator end, 144 std::vector<TabManagerDelegate::Candidate>::const_iterator end,
157 int range_begin, 145 int range_begin,
158 int range_end, 146 int range_end,
159 ProcessScoreMap* new_map); 147 ProcessScoreMap* new_map);
160 148
161 // Initiates an oom priority adjustment. 149 // Initiates an oom priority adjustment.
162 void ScheduleEarlyOomPrioritiesAdjustment(); 150 void ScheduleEarlyOomPrioritiesAdjustment();
163 151
164 // Returns a TimeDelta object that represents a minimum delay for killing
165 // the same ARC process again. ARC processes sometimes respawn right after
166 // being killed. In that case, killing them every time is just a waste of
167 // resources.
168 static constexpr base::TimeDelta GetArcRespawnKillDelay() {
169 return base::TimeDelta::FromSeconds(60);
170 }
171
172 // Holds a reference to the owning TabManager. 152 // Holds a reference to the owning TabManager.
173 const base::WeakPtr<TabManager> tab_manager_; 153 const base::WeakPtr<TabManager> tab_manager_;
174 154
175 // Registrar to receive renderer notifications. 155 // Registrar to receive renderer notifications.
176 content::NotificationRegistrar registrar_; 156 content::NotificationRegistrar registrar_;
177 157
178 // Timer to guarantee that the tab or app is focused for a certain amount of 158 // Timer to guarantee that the tab or app is focused for a certain amount of
179 // time. 159 // time.
180 base::OneShotTimer focus_process_score_adjust_timer_; 160 base::OneShotTimer focus_process_score_adjust_timer_;
181 // Holds the info of the newly focused tab or app. Its OOM score would be 161 // Holds the info of the newly focused tab or app. Its OOM score would be
182 // adjusted when |focus_process_score_adjust_timer_| is expired. 162 // adjusted when |focus_process_score_adjust_timer_| is expired.
183 std::unique_ptr<FocusedProcess> focused_process_; 163 std::unique_ptr<FocusedProcess> focused_process_;
184 164
185 // Map maintaining the process handle - oom_score mapping. 165 // Map maintaining the process handle - oom_score mapping.
186 ProcessScoreMap oom_score_map_; 166 ProcessScoreMap oom_score_map_;
187 167
188 // Map maintaing ARC process names and their last killed time.
189 KilledArcProcessesMap recently_killed_arc_processes_;
190
191 // Util for getting system memory status. 168 // Util for getting system memory status.
192 std::unique_ptr<TabManagerDelegate::MemoryStat> mem_stat_; 169 std::unique_ptr<TabManagerDelegate::MemoryStat> mem_stat_;
193 170
194 // Weak pointer factory used for posting tasks to other threads. 171 // Weak pointer factory used for posting tasks to other threads.
195 base::WeakPtrFactory<TabManagerDelegate> weak_ptr_factory_; 172 base::WeakPtrFactory<TabManagerDelegate> weak_ptr_factory_;
196 173
197 DISALLOW_COPY_AND_ASSIGN(TabManagerDelegate); 174 DISALLOW_COPY_AND_ASSIGN(TabManagerDelegate);
198 }; 175 };
199 176
200 // On ARC enabled machines, either a tab or an app could be a possible 177 // On ARC enabled machines, either a tab or an app could be a possible
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // reported if available memory is under the number. 229 // reported if available memory is under the number.
253 static int LowMemoryMarginKB(); 230 static int LowMemoryMarginKB();
254 231
255 // Reads in an integer. 232 // Reads in an integer.
256 static int ReadIntFromFile(const char* file_name, int default_val); 233 static int ReadIntFromFile(const char* file_name, int default_val);
257 }; 234 };
258 235
259 } // namespace memory 236 } // namespace memory
260 237
261 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ 238 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/memory/tab_manager_delegate_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698