Commit dedfa290 authored by khmel@google.com's avatar khmel@google.com Committed by Commit Bot

arc: Protect CloudDPC process from been killed by memory killer.

This adds explicit rule to protect CloudDPC

Test: unit_test
Bug: b:73064229
Change-Id: If56eec0800d3a7be4c2a1775e6ceedec0583833f
Reviewed-on: https://chromium-review.googlesource.com/996568Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Commit-Queue: Yury Khmel <khmel@google.com>
Cr-Commit-Position: refs/heads/master@{#548572}
parent dd0b658d
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
namespace arc { namespace arc {
constexpr char kCloudDpcrocessName[] =
"com.google.android.apps.work.clouddpc.arc";
ArcProcess::ArcProcess(base::ProcessId nspid, ArcProcess::ArcProcess(base::ProcessId nspid,
base::ProcessId pid, base::ProcessId pid,
const std::string& process_name, const std::string& process_name,
...@@ -37,14 +40,20 @@ ArcProcess::ArcProcess(ArcProcess&& other) = default; ...@@ -37,14 +40,20 @@ ArcProcess::ArcProcess(ArcProcess&& other) = default;
ArcProcess& ArcProcess::operator=(ArcProcess&& other) = default; ArcProcess& ArcProcess::operator=(ArcProcess&& other) = default;
bool ArcProcess::IsImportant() const { bool ArcProcess::IsImportant() const {
return process_state() <= mojom::ProcessState::IMPORTANT_FOREGROUND; return process_state() <= mojom::ProcessState::IMPORTANT_FOREGROUND ||
IsArcProtected();
} }
bool ArcProcess::IsKernelKillable() const { bool ArcProcess::IsKernelKillable() const {
// Protect PERSISTENT, PERSISTENT_UI, and our HOME processes since they should // Protect PERSISTENT, PERSISTENT_UI, our HOME and custom set of ARC processes
// never be killed even by the kernel. Returning false for them allows their // since they should never be killed even by the kernel. Returning false for
// OOM adjustment scores to remain negative. // them allows their OOM adjustment scores to remain negative.
return process_state() > arc::mojom::ProcessState::PERSISTENT_UI; return process_state() > arc::mojom::ProcessState::PERSISTENT_UI &&
!IsArcProtected();
}
bool ArcProcess::IsArcProtected() const {
return process_name() == kCloudDpcrocessName;
} }
std::ostream& operator<<(std::ostream& out, const ArcProcess& arc_process) { std::ostream& operator<<(std::ostream& out, const ArcProcess& arc_process) {
......
...@@ -53,6 +53,9 @@ class ArcProcess { ...@@ -53,6 +53,9 @@ class ArcProcess {
bool IsKernelKillable() const; bool IsKernelKillable() const;
private: private:
// Returns true if this is ARC protected process which we don't allow to kill.
bool IsArcProtected() const;
base::ProcessId nspid_; base::ProcessId nspid_;
base::ProcessId pid_; base::ProcessId pid_;
std::string process_name_; std::string process_name_;
......
...@@ -122,12 +122,17 @@ TEST(ArcProcess, TestIsImportant) { ...@@ -122,12 +122,17 @@ TEST(ArcProcess, TestIsImportant) {
EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::CACHED_EMPTY, EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::CACHED_EMPTY,
kIsNotFocused, 0) kIsNotFocused, 0)
.IsImportant()); .IsImportant());
// Custom ARC protected processes.
EXPECT_TRUE(ArcProcess(0, 0, "com.google.android.apps.work.clouddpc.arc",
mojom::ProcessState::SERVICE, kIsNotFocused, 0)
.IsImportant());
} }
TEST(ArcProcess, TestIsKernelKillable) { TEST(ArcProcess, TestIsKernelKillable) {
constexpr bool kIsNotFocused = false; constexpr bool kIsNotFocused = false;
// Only PERSISITENT* processes are protected from the kernel OOM killer. // PERSISITENT* processes are protected from the kernel OOM killer.
EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::PERSISTENT, EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::PERSISTENT,
kIsNotFocused, 0) kIsNotFocused, 0)
.IsKernelKillable()); .IsKernelKillable());
...@@ -189,6 +194,11 @@ TEST(ArcProcess, TestIsKernelKillable) { ...@@ -189,6 +194,11 @@ TEST(ArcProcess, TestIsKernelKillable) {
EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::CACHED_EMPTY, EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::CACHED_EMPTY,
kIsNotFocused, 0) kIsNotFocused, 0)
.IsKernelKillable()); .IsKernelKillable());
// Set of custom processes that are protected from the kernel OOM killer.
EXPECT_FALSE(ArcProcess(0, 0, "com.google.android.apps.work.clouddpc.arc",
mojom::ProcessState::SERVICE, kIsNotFocused, 0)
.IsKernelKillable());
} }
// Tests operator<<() does not crash and returns non-empty result, at least. // Tests operator<<() does not crash and returns non-empty result, at least.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment