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 @@
namespace arc {
constexpr char kCloudDpcrocessName[] =
"com.google.android.apps.work.clouddpc.arc";
ArcProcess::ArcProcess(base::ProcessId nspid,
base::ProcessId pid,
const std::string& process_name,
......@@ -37,14 +40,20 @@ ArcProcess::ArcProcess(ArcProcess&& other) = default;
ArcProcess& ArcProcess::operator=(ArcProcess&& other) = default;
bool ArcProcess::IsImportant() const {
return process_state() <= mojom::ProcessState::IMPORTANT_FOREGROUND;
return process_state() <= mojom::ProcessState::IMPORTANT_FOREGROUND ||
IsArcProtected();
}
bool ArcProcess::IsKernelKillable() const {
// Protect PERSISTENT, PERSISTENT_UI, and our HOME processes since they should
// never be killed even by the kernel. Returning false for them allows their
// OOM adjustment scores to remain negative.
return process_state() > arc::mojom::ProcessState::PERSISTENT_UI;
// Protect PERSISTENT, PERSISTENT_UI, our HOME and custom set of ARC processes
// since they should never be killed even by the kernel. Returning false for
// them allows their OOM adjustment scores to remain negative.
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) {
......
......@@ -53,6 +53,9 @@ class ArcProcess {
bool IsKernelKillable() const;
private:
// Returns true if this is ARC protected process which we don't allow to kill.
bool IsArcProtected() const;
base::ProcessId nspid_;
base::ProcessId pid_;
std::string process_name_;
......
......@@ -122,12 +122,17 @@ TEST(ArcProcess, TestIsImportant) {
EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::CACHED_EMPTY,
kIsNotFocused, 0)
.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) {
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,
kIsNotFocused, 0)
.IsKernelKillable());
......@@ -189,6 +194,11 @@ TEST(ArcProcess, TestIsKernelKillable) {
EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::CACHED_EMPTY,
kIsNotFocused, 0)
.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.
......
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