Skip to content

Commit

Permalink
lmkd: migrate process to FOREGROUND sched group before kill
Browse files Browse the repository at this point in the history
BG group may have settings such as cpu.shares impacting reclaim
performance. Let us migrate task to foreground sched group similarly to
cpuset group.

Test: Build
Bug: 199797672
Signed-off-by: Wei Wang <wvw@google.com>
Change-Id: I75ee9f3486a2c76e65267a98e39edff96a5e1673
  • Loading branch information
weivincewang authored and kdrag0n committed Oct 5, 2021
1 parent a810e9f commit 130c294
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lmkd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
#include <unistd.h>

#include <cutils/properties.h>
#include <cutils/sched_policy.h>
#include <cutils/sockets.h>
#include <liblmkd_utils.h>
#include <lmkd.h>
#include <log/log.h>
#include <log/log_event_list.h>
#include <log/log_time.h>
#include <private/android_filesystem_config.h>
#include <processgroup/processgroup.h>
#include <psi/psi.h>
#include <system/thread_defs.h>

Expand Down Expand Up @@ -1977,7 +1977,8 @@ static struct proc *proc_get_heaviest(int oomadj) {
return maxprocp;
}

static void set_process_group_and_prio(int pid, SchedPolicy sp, int prio) {
static void set_process_group_and_prio(int pid, const std::vector<std::string>& profiles,
int prio) {
DIR* d;
char proc_path[PATH_MAX];
struct dirent* de;
Expand All @@ -2004,8 +2005,8 @@ static void set_process_group_and_prio(int pid, SchedPolicy sp, int prio) {
ALOGW("Unable to raise priority of killing t_pid (%d): errno=%d", t_pid, errno);
}

if (set_cpuset_policy(t_pid, sp)) {
ALOGW("Failed to set_cpuset_policy on pid(%d) t_pid(%d) to %d", pid, t_pid, (int)sp);
if (!SetTaskProfiles(t_pid, profiles)) {
ALOGW("Failed to set task_profiles on pid(%d) t_pid(%d)", pid, t_pid);
continue;
}
}
Expand Down Expand Up @@ -2180,7 +2181,8 @@ static int kill_one_process(struct proc* procp, int min_oom_score, struct kill_i
goto out;
}

set_process_group_and_prio(pid, SP_FOREGROUND, ANDROID_PRIORITY_HIGHEST);
set_process_group_and_prio(pid, {"CPUSET_SP_BACKGROUND", "SCHED_SP_FOREGROUND"},
ANDROID_PRIORITY_HIGHEST);

last_kill_tm = *tm;

Expand Down

0 comments on commit 130c294

Please sign in to comment.