Activity Manager changes the scheduling group of processes.
The algorithm for this is currently very simple: all persistent processes are always in the normal scheduling group, all other processes are normal if their oom_adj is as good or better than VISIBLE, otherwise they are in the background group. Note that this currently results in a fair number of log messages about not being able to change the group, since the system process does not have permission to do so. Once a kernel fix is in, these will go away and the code will start working.
This commit is contained in:
@@ -4733,6 +4733,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
|
||||
|
||||
app.thread = thread;
|
||||
app.curAdj = app.setAdj = -100;
|
||||
app.curSchedGroup = app.setSchedGroup = Process.THREAD_GROUP_DEFAULT;
|
||||
app.forcingToForeground = null;
|
||||
app.foregroundServices = false;
|
||||
app.debugging = false;
|
||||
@@ -8802,9 +8803,9 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
|
||||
+ " #" + i + ":");
|
||||
r.dump(pw, prefix + " ");
|
||||
} else if (inclOomAdj) {
|
||||
pw.println(String.format("%s%s #%2d: oom_adj=%3d %s",
|
||||
pw.println(String.format("%s%s #%2d: adj=%3d/%d %s",
|
||||
prefix, (r.persistent ? persistentLabel : normalLabel),
|
||||
i, r.setAdj, r.toString()));
|
||||
i, r.setAdj, r.setSchedGroup, r.toString()));
|
||||
} else {
|
||||
pw.println(String.format("%s%s #%2d: %s",
|
||||
prefix, (r.persistent ? persistentLabel : normalLabel),
|
||||
@@ -11830,7 +11831,10 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
|
||||
}
|
||||
|
||||
app.curAdj = adj;
|
||||
|
||||
app.curSchedGroup = (adj > VISIBLE_APP_ADJ && !app.persistent)
|
||||
? Process.THREAD_GROUP_BG_NONINTERACTIVE
|
||||
: Process.THREAD_GROUP_DEFAULT;
|
||||
|
||||
return adj;
|
||||
}
|
||||
|
||||
@@ -11975,6 +11979,28 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (app.setSchedGroup != app.curSchedGroup) {
|
||||
app.setSchedGroup = app.curSchedGroup;
|
||||
if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Log.v(TAG,
|
||||
"Setting process group of " + app.processName
|
||||
+ " to " + app.curSchedGroup);
|
||||
if (true) {
|
||||
try {
|
||||
Process.setProcessGroup(app.pid, app.curSchedGroup);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Failed setting process group of " + app.pid
|
||||
+ " to " + app.curSchedGroup);
|
||||
}
|
||||
}
|
||||
if (false) {
|
||||
if (app.thread != null) {
|
||||
try {
|
||||
app.thread.setSchedulingGroup(app.curSchedGroup);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -56,6 +56,8 @@ class ProcessRecord implements Watchdog.PssRequestor {
|
||||
int setRawAdj; // Last set OOM unlimited adjustment for this process
|
||||
int curAdj; // Current OOM adjustment for this process
|
||||
int setAdj; // Last set OOM adjustment for this process
|
||||
int curSchedGroup; // Currently desired scheduling class
|
||||
int setSchedGroup; // Last set to background scheduling class
|
||||
boolean isForeground; // Is this app running the foreground UI?
|
||||
boolean setIsForeground; // Running foreground UI when last set?
|
||||
boolean foregroundServices; // Running any services that are foreground?
|
||||
@@ -147,6 +149,8 @@ class ProcessRecord implements Watchdog.PssRequestor {
|
||||
pw.print(" setRaw="); pw.print(setRawAdj);
|
||||
pw.print(" cur="); pw.print(curAdj);
|
||||
pw.print(" set="); pw.println(setAdj);
|
||||
pw.print(prefix); pw.print("curSchedGroup="); pw.print(curSchedGroup);
|
||||
pw.print(" setSchedGroup="); pw.println(setSchedGroup);
|
||||
pw.print(prefix); pw.print("isForeground="); pw.print(isForeground);
|
||||
pw.print(" setIsForeground="); pw.print(setIsForeground);
|
||||
pw.print(" foregroundServices="); pw.print(foregroundServices);
|
||||
|
||||
Reference in New Issue
Block a user