| 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 dbc66dc5b1c7890a2c157059468a1368d7953961..9911b548bbaabf011aab64603800014f3ce57e2c 100644
|
| --- a/chrome/browser/memory/tab_manager_delegate_chromeos.cc
|
| +++ b/chrome/browser/memory/tab_manager_delegate_chromeos.cc
|
| @@ -8,7 +8,6 @@
|
|
|
| #include <algorithm>
|
| #include <map>
|
| -#include <string>
|
| #include <vector>
|
|
|
| #include "ash/shell.h"
|
| @@ -51,6 +50,7 @@
|
|
|
| using base::ProcessHandle;
|
| using base::TimeDelta;
|
| +using base::TimeTicks;
|
| using content::BrowserThread;
|
|
|
| namespace memory {
|
| @@ -552,6 +552,20 @@ TabManagerDelegate::GetSortedCandidates(
|
| return candidates;
|
| }
|
|
|
| +bool TabManagerDelegate::IsRecentlyKilledArcProcess(
|
| + const std::string& process_name,
|
| + const TimeTicks& now) {
|
| + // A constant to avoid killing a process too often. ARC processes
|
| + // sometimes respawn right after being killed. In that case, killing
|
| + // them every time is just a waste of resources.
|
| + static constexpr TimeDelta kArcSkipKillingTime = TimeDelta::FromMinutes(1);
|
| +
|
| + auto it = recently_killed_arc_processes_.find(process_name);
|
| + if (it == recently_killed_arc_processes_.end())
|
| + return false;
|
| + return (now - it->second) <= kArcSkipKillingTime;
|
| +}
|
| +
|
| bool TabManagerDelegate::KillArcProcess(const int nspid) {
|
| auto* arc_service_manager = arc::ArcServiceManager::Get();
|
| if (!arc_service_manager)
|
| @@ -588,6 +602,7 @@ void TabManagerDelegate::LowMemoryKillImpl(
|
| GetSortedCandidates(tab_list, arc_processes);
|
|
|
| int target_memory_to_free_kb = mem_stat_->TargetMemoryToFreeKB();
|
| + const TimeTicks now = TimeTicks::Now();
|
|
|
| // Kill processes until the estimated amount of freed memory is sufficient to
|
| // bring the system memory back to a normal level.
|
| @@ -608,9 +623,14 @@ void TabManagerDelegate::LowMemoryKillImpl(
|
| continue;
|
| }
|
| if (it->app()) {
|
| + if (IsRecentlyKilledArcProcess(it->app()->process_name(), now)) {
|
| + MEMORY_LOG(ERROR) << "Avoided killing " << *it << " too often";
|
| + continue;
|
| + }
|
| int estimated_memory_freed_kb =
|
| mem_stat_->EstimatedMemoryFreedKB(it->app()->pid());
|
| if (KillArcProcess(it->app()->nspid())) {
|
| + recently_killed_arc_processes_[it->app()->process_name()] = now;
|
| target_memory_to_free_kb -= estimated_memory_freed_kb;
|
| MemoryKillsMonitor::LogLowMemoryKill("APP", estimated_memory_freed_kb);
|
| MEMORY_LOG(ERROR) << "Killed " << *it << ", estimated "
|
|
|