diff options
author | Wei Wang <wvw@google.com> | 2019-04-18 14:56:24 -0700 |
---|---|---|
committer | Wei Wang <wvw@google.com> | 2019-04-18 16:31:11 -0700 |
commit | bb2bc1586d1de2afec9874fdbeb1e204b996aadf (patch) | |
tree | 425d2e548580723822a216eb0be032337bb8fb42 | |
parent | 84ababefb7b7ec04027b741d7a6fe937cffee54b (diff) |
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
-rw-r--r-- | init/init.cpp | 5 | ||||
-rw-r--r-- | rootdir/init.rc | 3 |
2 files changed, 5 insertions, 3 deletions
diff --git a/init/init.cpp b/init/init.cpp index 0f44efda4..ac0e67a80 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -630,6 +630,11 @@ int SecondStageMain(int argc, char** argv) { 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(); diff --git a/rootdir/init.rc b/rootdir/init.rc index b274cf30e..17dd1457b 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -13,9 +13,6 @@ import /init.${ro.zygote}.rc # Cgroups are mounted right before early-init using list from /etc/cgroups.json on early-init - # Set init and its forked children's oom_adj. - write /proc/1/oom_score_adj -1000 - # Disable sysrq from keyboard write /proc/sys/kernel/sysrq 0 |