init: set oom_adj early before fork vendor_init
right now vendor_init is forked before we set oom_adj for init which
leaves a chance vendor_init could be killed in heavy memory pressure.
this CL set the oom_adj before forking everything to ensure all native
have correct oom_adj settings.
Fixes: 130824864
Test: procrank -o
(cherry picked from commit 45d8174fe7b6f35883f74ceefdf591b209f1fab2)
Change-Id: I68c18f9db24d55239f7f0608592fcc702f04542e
diff --git a/init/init.cpp b/init/init.cpp
index 0f44efd..ac0e67a 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -630,6 +630,11 @@
InitKernelLogging(argv, InitAborter);
LOG(INFO) << "init second stage started!";
+ // Set init and its forked children's oom_adj.
+ if (auto result = WriteFile("/proc/1/oom_score_adj", "-1000"); !result) {
+ LOG(ERROR) << "Unable to write -1000 to /proc/1/oom_score_adj: " << result.error();
+ }
+
// Enable seccomp if global boot option was passed (otherwise it is enabled in zygote).
GlobalSeccomp();