lmkd: Set task profiles to the entire process

set_process_group_and_prio sets task profiles for each thread in the
process separately. This can be avoided by setting task profiles to
the entire process using its pid.

Bug: 215557553
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I9c1917172019a42809385f6c9c084b8cb343b520
Merged-In: I9c1917172019a42809385f6c9c084b8cb343b520
This commit is contained in:
Suren Baghdasaryan 2022-01-20 18:48:52 -08:00
parent 931bf0954f
commit b8cdb6ac91
1 changed files with 8 additions and 8 deletions

View File

@ -1987,12 +1987,17 @@ static struct proc *proc_get_heaviest(int oomadj) {
return maxprocp; return maxprocp;
} }
static void set_process_group_and_prio(int pid, const std::vector<std::string>& profiles,
int prio) { static void set_process_group_and_prio(uid_t uid, int pid,
const std::vector<std::string>& profiles, 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,
@ -2014,11 +2019,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);
} }
@ -2191,7 +2191,7 @@ static int kill_one_process(struct proc* procp, int min_oom_score, struct kill_i
goto out; goto out;
} }
set_process_group_and_prio(pid, {"CPUSET_SP_FOREGROUND", "SCHED_SP_FOREGROUND"}, set_process_group_and_prio(uid, pid, {"CPUSET_SP_FOREGROUND", "SCHED_SP_FOREGROUND"},
ANDROID_PRIORITY_HIGHEST); ANDROID_PRIORITY_HIGHEST);
last_kill_tm = *tm; last_kill_tm = *tm;