Implement new ranking for apps and tabs in tab manager delegate
This CL modifies the ranking of apps and tabs for OOM-killing
in tab manager delegate, such that cached apps are killed first,
and background apps/tabs are ranked together. This is to address
cached apps that are (currently) never killed and to enable
ActivityManagerService to send trim memory signals.
The design doc in progress at go/arc-oom-new-ranking explains the
changes in more detail.
Change-Id: I47e8281faacdf8e72a3dd834c5b8f4308c3bb92d
BUG: b:62353695
TEST: TabManagerDelegate unit tests, and manual memory pressure tests
Reviewed-on: https://chromium-review.googlesource.com/c/1362493
Commit-Queue: Willie Koomson <[email protected]>
Reviewed-by: Christopher Morin <[email protected]>
Reviewed-by: Cheng-Yu Lee <[email protected]>
Cr-Commit-Position: refs/heads/master@{#617578}
diff --git a/chrome/browser/chromeos/arc/process/arc_process.cc b/chrome/browser/chromeos/arc/process/arc_process.cc
index d10eb28..17088eb 100644
--- a/chrome/browser/chromeos/arc/process/arc_process.cc
+++ b/chrome/browser/chromeos/arc/process/arc_process.cc
@@ -4,15 +4,55 @@
#include "chrome/browser/chromeos/arc/process/arc_process.h"
+#include <unordered_set>
#include <utility>
#include "base/strings/string_util.h"
namespace arc {
+using mojom::ProcessState;
+
constexpr char kCloudDpcrocessName[] =
"com.google.android.apps.work.clouddpc.arc";
+const std::unordered_set<ProcessState> kImportantStates = {
+ ProcessState::IMPORTANT_FOREGROUND,
+ ProcessState::BOUND_FOREGROUND_SERVICE,
+ ProcessState::FOREGROUND_SERVICE,
+ ProcessState::TOP,
+ ProcessState::PERSISTENT_UI,
+ ProcessState::PERSISTENT
+};
+const std::unordered_set<ProcessState> kPersistentStates = {
+ ProcessState::PERSISTENT_UI,
+ ProcessState::PERSISTENT
+};
+const std::unordered_set<ProcessState> kProtectedBackgroundStates = {
+ ProcessState::TOP,
+ ProcessState::FOREGROUND_SERVICE,
+ ProcessState::BOUND_FOREGROUND_SERVICE,
+ ProcessState::IMPORTANT_FOREGROUND,
+ ProcessState::IMPORTANT_FOREGROUND
+};
+const std::unordered_set<ProcessState> kBackgroundStates = {
+ ProcessState::TRANSIENT_BACKGROUND,
+ ProcessState::BACKUP,
+ ProcessState::SERVICE,
+ ProcessState::RECEIVER,
+ ProcessState::TOP_SLEEPING,
+ ProcessState::HEAVY_WEIGHT,
+ ProcessState::HOME,
+ ProcessState::LAST_ACTIVITY,
+ ProcessState::CACHED_ACTIVITY
+};
+const std::unordered_set<ProcessState> kCachedStates = {
+ ProcessState::CACHED_ACTIVITY_CLIENT,
+ ProcessState::CACHED_RECENT,
+ ProcessState::CACHED_EMPTY,
+ ProcessState::NONEXISTENT
+};
+
ArcProcess::ArcProcess(base::ProcessId nspid,
base::ProcessId pid,
const std::string& process_name,
@@ -40,15 +80,21 @@
ArcProcess& ArcProcess::operator=(ArcProcess&& other) = default;
bool ArcProcess::IsImportant() const {
- return process_state() <= mojom::ProcessState::IMPORTANT_FOREGROUND ||
- IsArcProtected();
+ return kImportantStates.count(process_state()) == 1 || IsArcProtected();
}
bool ArcProcess::IsPersistent() const {
// Protect PERSISTENT, PERSISTENT_UI, our HOME and custom set of ARC processes
// since they should have lower priority to be killed.
- return process_state() <= arc::mojom::ProcessState::PERSISTENT_UI ||
- IsArcProtected();
+ return kPersistentStates.count(process_state()) == 1 || IsArcProtected();
+}
+
+bool ArcProcess::IsCached() const {
+ return kCachedStates.count(process_state()) == 1;
+}
+
+bool ArcProcess::IsBackgroundProtected() const {
+ return kProtectedBackgroundStates.count(process_state()) == 1;
}
bool ArcProcess::IsArcProtected() const {
diff --git a/chrome/browser/chromeos/arc/process/arc_process.h b/chrome/browser/chromeos/arc/process/arc_process.h
index 2cb36ac..54dbd0e 100644
--- a/chrome/browser/chromeos/arc/process/arc_process.h
+++ b/chrome/browser/chromeos/arc/process/arc_process.h
@@ -57,6 +57,14 @@
// IsImportant() might be good enough.
bool IsPersistent() const;
+ // Returns true if the process is cached or empty and should have a higher
+ // oom_score_adj to be killed earlier.
+ bool IsCached() const;
+
+ // Returns true if process is in the background but should have a lower
+ // oom_score_adj.
+ bool IsBackgroundProtected() const;
+
private:
// Returns true if this is ARC protected process which we don't allow to kill.
bool IsArcProtected() const;