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

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

Issue 2877653003: Reland: 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
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 #include "chrome/browser/memory/tab_manager_delegate_chromeos.h" 5 #include "chrome/browser/memory/tab_manager_delegate_chromeos.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
11 #include <string>
12 #include <vector> 11 #include <vector>
13 12
14 #include "ash/shell.h" 13 #include "ash/shell.h"
15 #include "base/bind.h" 14 #include "base/bind.h"
16 #include "base/command_line.h" 15 #include "base/command_line.h"
17 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
18 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
19 #include "base/memory/memory_pressure_monitor_chromeos.h" 18 #include "base/memory/memory_pressure_monitor_chromeos.h"
20 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
21 #include "base/process/process_handle.h" // kNullProcessHandle. 20 #include "base/process/process_handle.h" // kNullProcessHandle.
(...skipping 22 matching lines...) Expand all
44 #include "content/public/browser/notification_service.h" 43 #include "content/public/browser/notification_service.h"
45 #include "content/public/browser/notification_types.h" 44 #include "content/public/browser/notification_types.h"
46 #include "content/public/browser/render_process_host.h" 45 #include "content/public/browser/render_process_host.h"
47 #include "content/public/browser/render_widget_host.h" 46 #include "content/public/browser/render_widget_host.h"
48 #include "content/public/browser/zygote_host_linux.h" 47 #include "content/public/browser/zygote_host_linux.h"
49 #include "ui/aura/window.h" 48 #include "ui/aura/window.h"
50 #include "ui/wm/public/activation_client.h" 49 #include "ui/wm/public/activation_client.h"
51 50
52 using base::ProcessHandle; 51 using base::ProcessHandle;
53 using base::TimeDelta; 52 using base::TimeDelta;
53 using base::TimeTicks;
54 using content::BrowserThread; 54 using content::BrowserThread;
55 55
56 namespace memory { 56 namespace memory {
57 namespace { 57 namespace {
58 58
59 const char kExoShellSurfaceWindowName[] = "ExoShellSurface"; 59 const char kExoShellSurfaceWindowName[] = "ExoShellSurface";
60 const char kArcProcessNamePrefix[] = "org.chromium.arc."; 60 const char kArcProcessNamePrefix[] = "org.chromium.arc.";
61 61
62 // When switching to a new tab the tab's renderer's OOM score needs to be 62 // When switching to a new tab the tab's renderer's OOM score needs to be
63 // updated to reflect its front-most status and protect it from discard. 63 // updated to reflect its front-most status and protect it from discard.
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 } 547 }
548 candidates.emplace_back(&app); 548 candidates.emplace_back(&app);
549 } 549 }
550 550
551 // Sort candidates according to priority. 551 // Sort candidates according to priority.
552 std::sort(candidates.begin(), candidates.end()); 552 std::sort(candidates.begin(), candidates.end());
553 553
554 return candidates; 554 return candidates;
555 } 555 }
556 556
557 bool TabManagerDelegate::IsRecentlyKilledArcProcess(
558 const std::string& process_name,
559 const TimeTicks& now) {
560 const auto it = recently_killed_arc_processes_.find(process_name);
561 if (it == recently_killed_arc_processes_.end())
562 return false;
563 return (now - it->second) <= GetArcRespawnKillDelay();
564 }
565
557 bool TabManagerDelegate::KillArcProcess(const int nspid) { 566 bool TabManagerDelegate::KillArcProcess(const int nspid) {
558 auto* arc_service_manager = arc::ArcServiceManager::Get(); 567 auto* arc_service_manager = arc::ArcServiceManager::Get();
559 if (!arc_service_manager) 568 if (!arc_service_manager)
560 return false; 569 return false;
561 570
562 auto* arc_process_instance = ARC_GET_INSTANCE_FOR_METHOD( 571 auto* arc_process_instance = ARC_GET_INSTANCE_FOR_METHOD(
563 arc_service_manager->arc_bridge_service()->process(), KillProcess); 572 arc_service_manager->arc_bridge_service()->process(), KillProcess);
564 if (!arc_process_instance) 573 if (!arc_process_instance)
565 return false; 574 return false;
566 575
(...skipping 17 matching lines...) Expand all
584 const TabStatsList& tab_list, 593 const TabStatsList& tab_list,
585 const std::vector<arc::ArcProcess>& arc_processes) { 594 const std::vector<arc::ArcProcess>& arc_processes) {
586 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 595 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
587 VLOG(2) << "LowMemoryKillImpl"; 596 VLOG(2) << "LowMemoryKillImpl";
588 597
589 const std::vector<TabManagerDelegate::Candidate> candidates = 598 const std::vector<TabManagerDelegate::Candidate> candidates =
590 GetSortedCandidates(tab_list, arc_processes); 599 GetSortedCandidates(tab_list, arc_processes);
591 600
592 int target_memory_to_free_kb = mem_stat_->TargetMemoryToFreeKB(); 601 int target_memory_to_free_kb = mem_stat_->TargetMemoryToFreeKB();
593 bool killed_candidate = false; 602 bool killed_candidate = false;
603 const TimeTicks now = TimeTicks::Now();
594 604
595 // Kill processes until the estimated amount of freed memory is sufficient to 605 // Kill processes until the estimated amount of freed memory is sufficient to
596 // bring the system memory back to a normal level. 606 // bring the system memory back to a normal level.
597 // The list is sorted by descending importance, so we go through the list 607 // The list is sorted by descending importance, so we go through the list
598 // backwards. 608 // backwards.
599 for (auto it = candidates.rbegin(); it != candidates.rend(); ++it) { 609 for (auto it = candidates.rbegin(); it != candidates.rend(); ++it) {
600 VLOG(3) << "Target memory to free: " << target_memory_to_free_kb << " KB"; 610 VLOG(3) << "Target memory to free: " << target_memory_to_free_kb << " KB";
601 // Never kill selected tab or Android foreground app, regardless whether 611 // Never kill selected tab or Android foreground app, regardless whether
602 // they're in the active window. Since the user experience would be bad. 612 // they're in the active window. Since the user experience would be bad.
603 ProcessType process_type = it->process_type(); 613 ProcessType process_type = it->process_type();
604 if (process_type == ProcessType::VISIBLE_APP || 614 if (process_type == ProcessType::VISIBLE_APP ||
605 process_type == ProcessType::FOCUSED_APP || 615 process_type == ProcessType::FOCUSED_APP ||
606 process_type == ProcessType::FOCUSED_TAB) { 616 process_type == ProcessType::FOCUSED_TAB) {
607 VLOG(2) << "Skipped killing " << *it; 617 VLOG(2) << "Skipped killing " << *it;
608 continue; 618 continue;
609 } 619 }
610 if (it->app()) { 620 if (it->app()) {
621 if (IsRecentlyKilledArcProcess(it->app()->process_name(), now)) {
622 MEMORY_LOG(ERROR) << "Avoided killing " << *it << " too often";
623 continue;
624 }
611 int estimated_memory_freed_kb = 625 int estimated_memory_freed_kb =
612 mem_stat_->EstimatedMemoryFreedKB(it->app()->pid()); 626 mem_stat_->EstimatedMemoryFreedKB(it->app()->pid());
613 if (KillArcProcess(it->app()->nspid())) { 627 if (KillArcProcess(it->app()->nspid())) {
628 recently_killed_arc_processes_[it->app()->process_name()] = now;
614 target_memory_to_free_kb -= estimated_memory_freed_kb; 629 target_memory_to_free_kb -= estimated_memory_freed_kb;
615 MemoryKillsMonitor::LogLowMemoryKill("APP", estimated_memory_freed_kb); 630 MemoryKillsMonitor::LogLowMemoryKill("APP", estimated_memory_freed_kb);
616 MEMORY_LOG(ERROR) << "Killed " << *it << ", estimated " 631 MEMORY_LOG(ERROR) << "Killed " << *it << ", estimated "
617 << estimated_memory_freed_kb << " KB freed"; 632 << estimated_memory_freed_kb << " KB freed";
618 killed_candidate = true; 633 killed_candidate = true;
619 } 634 }
620 } else { 635 } else {
621 int64_t tab_id = it->tab()->tab_contents_id; 636 int64_t tab_id = it->tab()->tab_contents_id;
622 // The estimation is problematic since multiple tabs may share the same 637 // The estimation is problematic since multiple tabs may share the same
623 // process, while the calculation counts memory used by the whole process. 638 // process, while the calculation counts memory used by the whole process.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 752 }
738 priority += priority_increment; 753 priority += priority_increment;
739 } 754 }
740 755
741 if (oom_scores_to_change.size()) 756 if (oom_scores_to_change.size())
742 GetDebugDaemonClient()->SetOomScoreAdj( 757 GetDebugDaemonClient()->SetOomScoreAdj(
743 oom_scores_to_change, base::Bind(&OnSetOomScoreAdj)); 758 oom_scores_to_change, base::Bind(&OnSetOomScoreAdj));
744 } 759 }
745 760
746 } // namespace memory 761 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/memory/tab_manager_delegate_chromeos.h ('k') | chrome/browser/memory/tab_manager_delegate_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698