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

Side by Side Diff: chrome/browser/memory/tab_manager_delegate_chromeos.h

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

Powered by Google App Engine
This is Rietveld 408576698