summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkilesh Kailash <akailash@google.com>2022-06-02 08:00:39 +0000
committerAkilesh Kailash <akailash@google.com>2022-06-02 21:19:46 +0000
commit1a2f870cb3012af551d05edbe460e1056ef24d12 (patch)
tree02d05249e1c0b0c4fb6acfe36c85130cd4b74f8a
parent2cf162748fef8fa077e582f9f25eef45884ce9b8 (diff)
downloadcore-1a2f870cb3012af551d05edbe460e1056ef24d12.tar.gz
init: Set oom_score_adj to snapuserd process
When a process is started as a native service, oom_score_adj is set to -1000 so that processes are unkillable by lmkd. During boot, snapuserd process is not started as a service; hence, we need to set the oom_score_adj explicitly else in the event of low memory situation, lmkd can kill the process thereby device can never boot. Bug: 234691483 Test: th and OTA on Pixel Ignore-AOSP-First: cherry-pick from AOSP Signed-off-by: Akilesh Kailash <akailash@google.com> Change-Id: Ic2c85aa470522b4bc847a16b4f5cebfc528ed3cf
-rw-r--r--init/snapuserd_transition.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/init/snapuserd_transition.cpp b/init/snapuserd_transition.cpp
index 5deaf3156..5c821b05c 100644
--- a/init/snapuserd_transition.cpp
+++ b/init/snapuserd_transition.cpp
@@ -29,6 +29,7 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/parseint.h>
+#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <cutils/sockets.h>
@@ -40,6 +41,7 @@
#include <snapuserd/snapuserd_client.h>
#include "block_dev_initializer.h"
+#include "lmkd_service.h"
#include "service_utils.h"
#include "util.h"
@@ -320,6 +322,14 @@ void SnapuserdSelinuxHelper::RelaunchFirstStageSnapuserd() {
LOG(INFO) << "Relaunched snapuserd with pid: " << pid;
+ // Since daemon is not started as a service, we have
+ // to explicitly set the OOM score to default which is unkillable
+ std::string oom_str = std::to_string(DEFAULT_OOM_SCORE_ADJUST);
+ std::string oom_file = android::base::StringPrintf("/proc/%d/oom_score_adj", pid);
+ if (!android::base::WriteStringToFile(oom_str, oom_file)) {
+ PLOG(ERROR) << "couldn't write oom_score_adj to snapuserd daemon with pid: " << pid;
+ }
+
if (!TestSnapuserdIsReady()) {
PLOG(FATAL) << "snapuserd daemon failed to launch";
} else {