lmkd: Set task profiles to the entire process am: 2bdf7f0c74

Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1956501

Change-Id: I752c7df4c1bc4fe9867f88da95081949eaaa51b3
This commit is contained in:
Suren Baghdasaryan 2022-01-25 05:32:53 +00:00 committed by Automerger Merge Worker
commit a734b3bff1
3 changed files with 11 additions and 10 deletions

View File

@ -2088,7 +2088,7 @@ static void watchdog_callback() {
continue;
}
if (reaper.kill({ target.pidfd, target.pid }, true) == 0) {
if (reaper.kill({ target.pidfd, target.pid, target.uid }, true) == 0) {
ALOGW("lmkd watchdog killed process %d, oom_score_adj %d", target.pid, oom_score);
killinfo_log(&target, 0, 0, 0, NULL, NULL, NULL, NULL);
break;
@ -2260,7 +2260,7 @@ static int kill_one_process(struct proc* procp, int min_oom_score, struct kill_i
trace_kill_start(pid, desc);
start_wait_for_proc_kill(pidfd < 0 ? pid : pidfd);
kill_result = reaper.kill({ pidfd, pid }, false);
kill_result = reaper.kill({ pidfd, pid, uid }, false);
trace_kill_end();

View File

@ -141,12 +141,16 @@ bool Reaper::init(int comm_fd) {
return true;
}
static void set_process_group_and_prio(int pid, const std::vector<std::string>& profiles,
static void set_process_group_and_prio(uid_t uid, int pid, const std::vector<std::string>& profiles,
int prio) {
DIR* d;
char proc_path[PATH_MAX];
struct dirent* de;
if (!SetProcessProfilesCached(uid, pid, profiles)) {
ALOGW("Failed to set task profiles for the process (%d) being killed", pid);
}
snprintf(proc_path, sizeof(proc_path), "/proc/%d/task", pid);
if (!(d = opendir(proc_path))) {
ALOGW("Failed to open %s; errno=%d: process pid(%d) might have died", proc_path, errno,
@ -168,11 +172,6 @@ static void set_process_group_and_prio(int pid, const std::vector<std::string>&
if (setpriority(PRIO_PROCESS, t_pid, prio) && errno != ESRCH) {
ALOGW("Unable to raise priority of killing t_pid (%d): errno=%d", t_pid, errno);
}
if (!SetTaskProfiles(t_pid, profiles, true)) {
ALOGW("Failed to set task_profiles on pid(%d) t_pid(%d)", pid, t_pid);
continue;
}
}
closedir(d);
}
@ -195,12 +194,13 @@ bool Reaper::async_kill(const struct target_proc& target) {
// Duplicate pidfd instead of reusing the original one to avoid synchronization and refcounting
// when both reaper and main threads are using or closing the pidfd
queue_.push_back({ dup(target.pidfd), target.pid });
queue_.push_back({ dup(target.pidfd), target.pid, target.uid });
// Wake up a reaper thread
cond_.notify_one();
mutex_.unlock();
set_process_group_and_prio(target.pid, {"CPUSET_SP_FOREGROUND", "SCHED_SP_FOREGROUND"},
set_process_group_and_prio(target.uid, target.pid,
{"CPUSET_SP_FOREGROUND", "SCHED_SP_FOREGROUND"},
ANDROID_PRIORITY_HIGHEST);
return true;

View File

@ -25,6 +25,7 @@ public:
struct target_proc {
int pidfd;
int pid;
uid_t uid;
};
private:
// mutex_ and cond_ are used to wakeup the reaper thread.