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

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

Issue 2811433002: Log app and tab discards. (Closed)
Patch Set: add estimated_memory_freed_kb Created 3 years, 8 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_unittest.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 #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>
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/memory/tab_stats.h" 31 #include "chrome/browser/memory/tab_stats.h"
32 #include "chrome/browser/ui/browser.h" 32 #include "chrome/browser/ui/browser.h"
33 #include "chrome/browser/ui/browser_list.h" 33 #include "chrome/browser/ui/browser_list.h"
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
35 #include "chrome/common/chrome_constants.h" 35 #include "chrome/common/chrome_constants.h"
36 #include "chrome/common/chrome_features.h" 36 #include "chrome/common/chrome_features.h"
37 #include "chromeos/dbus/dbus_thread_manager.h" 37 #include "chromeos/dbus/dbus_thread_manager.h"
38 #include "components/arc/arc_bridge_service.h" 38 #include "components/arc/arc_bridge_service.h"
39 #include "components/arc/arc_service_manager.h" 39 #include "components/arc/arc_service_manager.h"
40 #include "components/arc/common/process.mojom.h" 40 #include "components/arc/common/process.mojom.h"
41 #include "components/device_event_log/device_event_log.h"
41 #include "components/exo/shell_surface.h" 42 #include "components/exo/shell_surface.h"
42 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/notification_service.h" 44 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/notification_types.h" 45 #include "content/public/browser/notification_types.h"
45 #include "content/public/browser/render_process_host.h" 46 #include "content/public/browser/render_process_host.h"
46 #include "content/public/browser/render_widget_host.h" 47 #include "content/public/browser/render_widget_host.h"
47 #include "content/public/browser/zygote_host_linux.h" 48 #include "content/public/browser/zygote_host_linux.h"
48 #include "ui/aura/window.h" 49 #include "ui/aura/window.h"
49 #include "ui/wm/public/activation_client.h" 50 #include "ui/wm/public/activation_client.h"
50 51
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 } 574 }
574 575
575 576
576 chromeos::DebugDaemonClient* TabManagerDelegate::GetDebugDaemonClient() { 577 chromeos::DebugDaemonClient* TabManagerDelegate::GetDebugDaemonClient() {
577 return chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); 578 return chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
578 } 579 }
579 580
580 void TabManagerDelegate::LowMemoryKillImpl( 581 void TabManagerDelegate::LowMemoryKillImpl(
581 const TabStatsList& tab_list, 582 const TabStatsList& tab_list,
582 const std::vector<arc::ArcProcess>& arc_processes) { 583 const std::vector<arc::ArcProcess>& arc_processes) {
583 584 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
584 VLOG(2) << "LowMemoryKillImpl"; 585 VLOG(2) << "LowMemoryKillImpl";
585 586
586 const std::vector<TabManagerDelegate::Candidate> candidates = 587 const std::vector<TabManagerDelegate::Candidate> candidates =
587 GetSortedCandidates(tab_list, arc_processes); 588 GetSortedCandidates(tab_list, arc_processes);
588 589
589 int target_memory_to_free_kb = mem_stat_->TargetMemoryToFreeKB(); 590 int target_memory_to_free_kb = mem_stat_->TargetMemoryToFreeKB();
591 bool killed_candidate = false;
592
590 // Kill processes until the estimated amount of freed memory is sufficient to 593 // Kill processes until the estimated amount of freed memory is sufficient to
591 // bring the system memory back to a normal level. 594 // bring the system memory back to a normal level.
592 // The list is sorted by descending importance, so we go through the list 595 // The list is sorted by descending importance, so we go through the list
593 // backwards. 596 // backwards.
594 for (auto it = candidates.rbegin(); it != candidates.rend(); ++it) { 597 for (auto it = candidates.rbegin(); it != candidates.rend(); ++it) {
595 VLOG(3) << "Target memory to free: " << target_memory_to_free_kb << " KB"; 598 VLOG(3) << "Target memory to free: " << target_memory_to_free_kb << " KB";
596 // Never kill selected tab or Android foreground app, regardless whether 599 // Never kill selected tab or Android foreground app, regardless whether
597 // they're in the active window. Since the user experience would be bad. 600 // they're in the active window. Since the user experience would be bad.
598 ProcessType process_type = it->process_type(); 601 ProcessType process_type = it->process_type();
599 if (process_type == ProcessType::VISIBLE_APP || 602 if (process_type == ProcessType::VISIBLE_APP ||
600 process_type == ProcessType::FOCUSED_APP || 603 process_type == ProcessType::FOCUSED_APP ||
601 process_type == ProcessType::FOCUSED_TAB) { 604 process_type == ProcessType::FOCUSED_TAB) {
602 VLOG(2) << "Skipped killing " << *it; 605 VLOG(2) << "Skipped killing " << *it;
603 continue; 606 continue;
604 } 607 }
605 if (it->app()) { 608 if (it->app()) {
606 int estimated_memory_freed_kb = 609 int estimated_memory_freed_kb =
607 mem_stat_->EstimatedMemoryFreedKB(it->app()->pid()); 610 mem_stat_->EstimatedMemoryFreedKB(it->app()->pid());
608 if (KillArcProcess(it->app()->nspid())) { 611 if (KillArcProcess(it->app()->nspid())) {
609 target_memory_to_free_kb -= estimated_memory_freed_kb; 612 target_memory_to_free_kb -= estimated_memory_freed_kb;
610 MemoryKillsMonitor::LogLowMemoryKill("APP", estimated_memory_freed_kb); 613 MemoryKillsMonitor::LogLowMemoryKill("APP", estimated_memory_freed_kb);
611 VLOG(2) << "Killed " << *it; 614 MEMORY_LOG(ERROR) << "Killed " << *it << ", estimated "
615 << estimated_memory_freed_kb << " kB freed";
Daniel Erat 2017/04/10 17:39:49 nit: "KB" rather than "kB" here and below? i think
teravest 2017/04/10 17:52:03 Done.
616 killed_candidate = true;
612 } 617 }
613 } else { 618 } else {
614 int64_t tab_id = it->tab()->tab_contents_id; 619 int64_t tab_id = it->tab()->tab_contents_id;
615 // The estimation is problematic since multiple tabs may share the same 620 // The estimation is problematic since multiple tabs may share the same
616 // process, while the calculation counts memory used by the whole process. 621 // process, while the calculation counts memory used by the whole process.
617 // So |estimated_memory_freed_kb| is an over-estimation. 622 // So |estimated_memory_freed_kb| is an over-estimation.
618 int estimated_memory_freed_kb = 623 int estimated_memory_freed_kb =
619 mem_stat_->EstimatedMemoryFreedKB(it->tab()->renderer_handle); 624 mem_stat_->EstimatedMemoryFreedKB(it->tab()->renderer_handle);
620 if (KillTab(tab_id)) { 625 if (KillTab(tab_id)) {
621 target_memory_to_free_kb -= estimated_memory_freed_kb; 626 target_memory_to_free_kb -= estimated_memory_freed_kb;
622 MemoryKillsMonitor::LogLowMemoryKill("TAB", estimated_memory_freed_kb); 627 MemoryKillsMonitor::LogLowMemoryKill("TAB", estimated_memory_freed_kb);
623 VLOG(2) << "Killed " << *it; 628 MEMORY_LOG(ERROR) << "Killed " << *it << ", estimated "
629 << estimated_memory_freed_kb << " kB freed";
630 killed_candidate = true;
624 } 631 }
625 } 632 }
626 if (target_memory_to_free_kb < 0) 633 if (target_memory_to_free_kb < 0)
627 break; 634 break;
628 } 635 }
636 if (!killed_candidate) {
637 MEMORY_LOG(ERROR) << "No candidate killed.";
638 }
629 } 639 }
630 640
631 void TabManagerDelegate::AdjustOomPrioritiesImpl( 641 void TabManagerDelegate::AdjustOomPrioritiesImpl(
632 const TabStatsList& tab_list, 642 const TabStatsList& tab_list,
633 const std::vector<arc::ArcProcess>& arc_processes) { 643 const std::vector<arc::ArcProcess>& arc_processes) {
634 // Least important first. 644 // Least important first.
635 const auto candidates = GetSortedCandidates(tab_list, arc_processes); 645 const auto candidates = GetSortedCandidates(tab_list, arc_processes);
636 646
637 // Now we assign priorities based on the sorted list. We're assigning 647 // Now we assign priorities based on the sorted list. We're assigning
638 // priorities in the range of kLowestRendererOomScore to 648 // priorities in the range of kLowestRendererOomScore to
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 } 733 }
724 priority += priority_increment; 734 priority += priority_increment;
725 } 735 }
726 736
727 if (oom_scores_to_change.size()) 737 if (oom_scores_to_change.size())
728 GetDebugDaemonClient()->SetOomScoreAdj( 738 GetDebugDaemonClient()->SetOomScoreAdj(
729 oom_scores_to_change, base::Bind(&OnSetOomScoreAdj)); 739 oom_scores_to_change, base::Bind(&OnSetOomScoreAdj));
730 } 740 }
731 741
732 } // namespace memory 742 } // namespace memory
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/memory/tab_manager_delegate_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698