Merge "Fix for incorrect cycle evaluation in computeOomAdj DO NOT MERGE" into pi-dev

This commit is contained in:
TreeHugger Robot
2018-07-18 00:56:18 +00:00
committed by Android (Google) Code Review

View File

@@ -23042,6 +23042,7 @@ public class ActivityManagerService extends IActivityManager.Stub
// The process is being computed, so there is a cycle. We cannot // The process is being computed, so there is a cycle. We cannot
// rely on this process's state. // rely on this process's state.
app.containsCycle = true; app.containsCycle = true;
return false; return false;
} }
} }
@@ -23066,6 +23067,7 @@ public class ActivityManagerService extends IActivityManager.Stub
final int logUid = mCurOomAdjUid; final int logUid = mCurOomAdjUid;
int prevAppAdj = app.curAdj; int prevAppAdj = app.curAdj;
int prevProcState = app.curProcState;
if (app.maxAdj <= ProcessList.FOREGROUND_APP_ADJ) { if (app.maxAdj <= ProcessList.FOREGROUND_APP_ADJ) {
// The max adjustment doesn't allow this app to be anything // The max adjustment doesn't allow this app to be anything
@@ -23544,11 +23546,16 @@ public class ActivityManagerService extends IActivityManager.Stub
ProcessRecord client = cr.binding.client; ProcessRecord client = cr.binding.client;
computeOomAdjLocked(client, cachedAdj, TOP_APP, doingAll, now); computeOomAdjLocked(client, cachedAdj, TOP_APP, doingAll, now);
if (client.containsCycle) { if (client.containsCycle) {
// We've detected a cycle. We should ignore this connection and allow // We've detected a cycle. We should retry computeOomAdjLocked later in
// this process to retry computeOomAdjLocked later in case a later-checked // case a later-checked connection from a client would raise its
// connection from a client would raise its priority legitimately. // priority legitimately.
app.containsCycle = true; app.containsCycle = true;
continue; // If the client has not been completely evaluated, skip using its
// priority. Else use the conservative value for now and look for a
// better state in the next iteration.
if (client.completedAdjSeq < mAdjSeq) {
continue;
}
} }
int clientAdj = client.curRawAdj; int clientAdj = client.curRawAdj;
int clientProcState = client.curProcState; int clientProcState = client.curProcState;
@@ -23771,11 +23778,16 @@ public class ActivityManagerService extends IActivityManager.Stub
} }
computeOomAdjLocked(client, cachedAdj, TOP_APP, doingAll, now); computeOomAdjLocked(client, cachedAdj, TOP_APP, doingAll, now);
if (client.containsCycle) { if (client.containsCycle) {
// We've detected a cycle. We should ignore this connection and allow // We've detected a cycle. We should retry computeOomAdjLocked later in
// this process to retry computeOomAdjLocked later in case a later-checked // case a later-checked connection from a client would raise its
// connection from a client would raise its priority legitimately. // priority legitimately.
app.containsCycle = true; app.containsCycle = true;
continue; // If the client has not been completely evaluated, skip using its
// priority. Else use the conservative value for now and look for a
// better state in the next iteration.
if (client.completedAdjSeq < mAdjSeq) {
continue;
}
} }
int clientAdj = client.curRawAdj; int clientAdj = client.curRawAdj;
int clientProcState = client.curProcState; int clientProcState = client.curProcState;
@@ -24007,8 +24019,8 @@ public class ActivityManagerService extends IActivityManager.Stub
app.foregroundActivities = foregroundActivities; app.foregroundActivities = foregroundActivities;
app.completedAdjSeq = mAdjSeq; app.completedAdjSeq = mAdjSeq;
// if curAdj is less than prevAppAdj, then this process was promoted // if curAdj or curProcState improved, then this process was promoted
return app.curAdj < prevAppAdj; return app.curAdj < prevAppAdj || app.curProcState < prevProcState;
} }
/** /**
@@ -25061,7 +25073,7 @@ public class ActivityManagerService extends IActivityManager.Stub
// - Continue retrying until no process was promoted. // - Continue retrying until no process was promoted.
// - Iterate from least important to most important. // - Iterate from least important to most important.
int cycleCount = 0; int cycleCount = 0;
while (retryCycles) { while (retryCycles && cycleCount < 10) {
cycleCount++; cycleCount++;
retryCycles = false; retryCycles = false;
@@ -25076,12 +25088,14 @@ public class ActivityManagerService extends IActivityManager.Stub
for (int i=0; i<N; i++) { for (int i=0; i<N; i++) {
ProcessRecord app = mLruProcesses.get(i); ProcessRecord app = mLruProcesses.get(i);
if (!app.killedByAm && app.thread != null && app.containsCycle == true) { if (!app.killedByAm && app.thread != null && app.containsCycle == true) {
if (computeOomAdjLocked(app, ProcessList.UNKNOWN_ADJ, TOP_APP, true, now)) { if (computeOomAdjLocked(app, ProcessList.UNKNOWN_ADJ, TOP_APP, true, now)) {
retryCycles = true; retryCycles = true;
} }
} }
} }
} }
for (int i=N-1; i>=0; i--) { for (int i=N-1; i>=0; i--) {
ProcessRecord app = mLruProcesses.get(i); ProcessRecord app = mLruProcesses.get(i);
if (!app.killedByAm && app.thread != null) { if (!app.killedByAm && app.thread != null) {