Index: chrome/browser/memory/tab_manager_delegate_chromeos.cc |
diff --git a/chrome/browser/memory/tab_manager_delegate_chromeos.cc b/chrome/browser/memory/tab_manager_delegate_chromeos.cc |
index 67d1f88d8ca6f75dd032aefe92e88c49f9db3a08..05dfb79660281845ec9a87b6d86b820811c49dfb 100644 |
--- a/chrome/browser/memory/tab_manager_delegate_chromeos.cc |
+++ b/chrome/browser/memory/tab_manager_delegate_chromeos.cc |
@@ -32,6 +32,8 @@ |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/common/chrome_constants.h" |
#include "chrome/common/chrome_features.h" |
+#include "chromeos/dbus/dbus_thread_manager.h" |
+#include "chromeos/dbus/debug_daemon_client.h" |
#include "components/arc/arc_bridge_service.h" |
#include "components/arc/common/process.mojom.h" |
#include "components/arc/metrics/oom_kills_histogram.h" |
@@ -80,6 +82,13 @@ bool IsArcMemoryManagementEnabled() { |
return base::FeatureList::IsEnabled(features::kArcMemoryManagement); |
} |
+void OnSetOomScoreAdj(bool success, const std::string& output) { |
+ VLOG(2) << "OnSetOomScoreAdj " << success << " " << output; |
+ if (!success || output != "") { |
Georges Khalil
2016/08/15 18:47:54
nit: !output.empty()
nit: no braces
cylee1
2016/08/16 19:47:10
Done.
|
+ LOG(WARNING) << "Set OOM score error: " << output; |
+ } |
+} |
+ |
} // namespace |
std::ostream& operator<<(std::ostream& os, const ProcessType& type) { |
@@ -487,8 +496,10 @@ void TabManagerDelegate::AdjustFocusedTabScoreOnFileThread() { |
} |
VLOG(3) << "Set OOM score " << chrome::kLowestRendererOomScore |
<< " for focused tab " << pid; |
- content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( |
- pid, chrome::kLowestRendererOomScore); |
+ std::map<int, int> dict; |
+ dict[pid] = chrome::kLowestRendererOomScore; |
+ chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->SetOomScoreAdj( |
+ dict, base::Bind(&OnSetOomScoreAdj)); |
} |
void TabManagerDelegate::OnFocusTabScoreAdjustmentTimeout() { |
@@ -746,32 +757,27 @@ void TabManagerDelegate::AdjustOomPrioritiesImpl( |
oom_score_map_.swap(new_map); |
} |
-void TabManagerDelegate::SetOomScoreAdjForApp(int nspid, int score) { |
- if (!arc_process_instance_) |
- return; |
- if (arc_process_instance_version_ < 2) { |
- VLOG(1) << "ProcessInstance version < 2 does not " |
- "support SetOomScoreAdj() yet."; |
- return; |
- } |
- arc_process_instance_->SetOomScoreAdj(nspid, score); |
-} |
- |
-void TabManagerDelegate::SetOomScoreAdjForTabs( |
+void TabManagerDelegate::SetOomScoreAdj( |
const std::vector<std::pair<base::ProcessHandle, int>>& entries) { |
BrowserThread::PostTask( |
BrowserThread::FILE, FROM_HERE, |
- base::Bind(&TabManagerDelegate::SetOomScoreAdjForTabsOnFileThread, |
+ base::Bind(&TabManagerDelegate::SetOomScoreAdjOnFileThread, |
base::Unretained(this), entries)); |
} |
-void TabManagerDelegate::SetOomScoreAdjForTabsOnFileThread( |
+// XXX: In the past it writes to procfs directly so running in file thread. |
+// Now it talks to debugd via DBus and the write is done in debugd |
+// asynchronously. Consider moving it back to UI thread. |
+void TabManagerDelegate::SetOomScoreAdjOnFileThread( |
const std::vector<std::pair<base::ProcessHandle, int>>& entries) { |
DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
- for (const auto& entry : entries) { |
- content::ZygoteHost::GetInstance()->AdjustRendererOOMScore(entry.first, |
- entry.second); |
- } |
+ |
+ std::map<int, int> dict; |
+ // Ignore duplicated keys but the last occurrence. |
+ for (const auto& entry : entries) |
+ dict[entry.first] = entry.second; |
+ chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->SetOomScoreAdj( |
hashimoto
2016/08/15 03:54:23
D-Bus clients are not thread-safe.
They must be ac
cylee1
2016/08/16 19:47:10
Done.
|
+ dict, base::Bind(&OnSetOomScoreAdj)); |
} |
void TabManagerDelegate::DistributeOomScoreInRange( |
@@ -780,9 +786,7 @@ void TabManagerDelegate::DistributeOomScoreInRange( |
int range_begin, |
int range_end, |
ProcessScoreMap* new_map) { |
- // OOM score setting for tabs involves file system operation so should be |
- // done on file thread. |
- std::vector<std::pair<base::ProcessHandle, int>> oom_score_for_tabs; |
+ std::vector<std::pair<base::ProcessHandle, int>> oom_scores_to_change; |
// Though there might be duplicate process handles, it doesn't matter to |
// overestimate the number of processes here since the we don't need to |
@@ -795,16 +799,17 @@ void TabManagerDelegate::DistributeOomScoreInRange( |
for (auto cur = begin; cur != end; ++cur) { |
int score = static_cast<int>(priority + 0.5f); |
if (cur->app()) { |
+ base::ProcessHandle pid = cur->app()->pid(); |
// Use pid as map keys so it's globally unique. |
- (*new_map)[cur->app()->pid()] = score; |
+ (*new_map)[pid] = score; |
int cur_app_pid_score = 0; |
{ |
base::AutoLock oom_score_autolock(oom_score_lock_); |
- cur_app_pid_score = oom_score_map_[cur->app()->pid()]; |
+ cur_app_pid_score = oom_score_map_[pid]; |
} |
if (cur_app_pid_score != score) { |
VLOG(3) << "Set OOM score " << score << " for " << *cur; |
- SetOomScoreAdjForApp(cur->app()->nspid(), score); |
+ oom_scores_to_change.push_back(std::make_pair(pid, score)); |
} |
} else { |
base::ProcessHandle process_handle = cur->tab()->renderer_handle; |
@@ -822,8 +827,8 @@ void TabManagerDelegate::DistributeOomScoreInRange( |
process_handle_score = oom_score_map_[process_handle]; |
} |
if (process_handle_score != score) { |
- oom_score_for_tabs.push_back(std::make_pair(process_handle, score)); |
VLOG(3) << "Set OOM score " << score << " for " << *cur; |
+ oom_scores_to_change.push_back(std::make_pair(process_handle, score)); |
} |
} else { |
continue; // Skip priority increment. |
@@ -832,8 +837,8 @@ void TabManagerDelegate::DistributeOomScoreInRange( |
priority += priority_increment; |
} |
- if (oom_score_for_tabs.size()) |
- SetOomScoreAdjForTabs(oom_score_for_tabs); |
+ if (oom_scores_to_change.size()) |
+ SetOomScoreAdj(oom_scores_to_change); |
} |
} // namespace memory |