lmkd: Set task profiles to the entire process am: 2bdf7f0c74 am: a734b3bff1 am: 85154e02b0 am: 3fcdbaaeab
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1956501 Change-Id: I2d05287f66408b2cead68ca92b51c63904e8a6aa
This commit is contained in:
commit
d385f7ec5c
4
lmkd.cpp
4
lmkd.cpp
|
|
@ -2088,7 +2088,7 @@ static void watchdog_callback() {
|
||||||
continue;
|
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);
|
ALOGW("lmkd watchdog killed process %d, oom_score_adj %d", target.pid, oom_score);
|
||||||
killinfo_log(&target, 0, 0, 0, NULL, NULL, NULL, NULL);
|
killinfo_log(&target, 0, 0, 0, NULL, NULL, NULL, NULL);
|
||||||
break;
|
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);
|
trace_kill_start(pid, desc);
|
||||||
|
|
||||||
start_wait_for_proc_kill(pidfd < 0 ? pid : pidfd);
|
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();
|
trace_kill_end();
|
||||||
|
|
||||||
|
|
|
||||||
16
reaper.cpp
16
reaper.cpp
|
|
@ -141,12 +141,16 @@ bool Reaper::init(int comm_fd) {
|
||||||
return true;
|
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) {
|
int prio) {
|
||||||
DIR* d;
|
DIR* d;
|
||||||
char proc_path[PATH_MAX];
|
char proc_path[PATH_MAX];
|
||||||
struct dirent* de;
|
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);
|
snprintf(proc_path, sizeof(proc_path), "/proc/%d/task", pid);
|
||||||
if (!(d = opendir(proc_path))) {
|
if (!(d = opendir(proc_path))) {
|
||||||
ALOGW("Failed to open %s; errno=%d: process pid(%d) might have died", proc_path, errno,
|
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) {
|
if (setpriority(PRIO_PROCESS, t_pid, prio) && errno != ESRCH) {
|
||||||
ALOGW("Unable to raise priority of killing t_pid (%d): errno=%d", t_pid, errno);
|
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);
|
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
|
// 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
|
// 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
|
// Wake up a reaper thread
|
||||||
cond_.notify_one();
|
cond_.notify_one();
|
||||||
mutex_.unlock();
|
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);
|
ANDROID_PRIORITY_HIGHEST);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue