summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2018-07-09 12:07:35 -0700
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-08-16 16:01:30 +0000
commit4bfc7a5dbba1515975f202d7a545cf7fe42bc021 (patch)
tree1ff92e78b3cad07ce9c012dae427e817ca9d0c8e
parent641b3da47a5164698088dc9046ea56c026df891a (diff)
downloadbase-4bfc7a5dbba1515975f202d7a545cf7fe42bc021.tar.gz
Fix for incorrect cycle evaluation in computeOomAdj DO NOT MERGE
Use the conservative value of adj and procstate if at least one evaluation pass was completed, even if the value is not final. The later iterations through the procs that have cycles will elevate the apps if necessary. Otherwise the dependencies will just get stuck in a low state. Bug: 79643956 Test: Manual test of connecting to AA and turning off screen atest CtsAppTestCases:ActivityManagerProcessStateTest Change-Id: If520eb239935782e2487b16e8bb650ded775f184 (cherry picked from commit d2aa4e1913c05d8c21e81eef3ad941565aded7d6)
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java36
1 files changed, 25 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 692d6063fc02..19b25f0590a1 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -23039,6 +23039,7 @@ public class ActivityManagerService extends IActivityManager.Stub
// The process is being computed, so there is a cycle. We cannot
// rely on this process's state.
app.containsCycle = true;
+
return false;
}
}
@@ -23063,6 +23064,7 @@ public class ActivityManagerService extends IActivityManager.Stub
final int logUid = mCurOomAdjUid;
int prevAppAdj = app.curAdj;
+ int prevProcState = app.curProcState;
if (app.maxAdj <= ProcessList.FOREGROUND_APP_ADJ) {
// The max adjustment doesn't allow this app to be anything
@@ -23541,11 +23543,16 @@ public class ActivityManagerService extends IActivityManager.Stub
ProcessRecord client = cr.binding.client;
computeOomAdjLocked(client, cachedAdj, TOP_APP, doingAll, now);
if (client.containsCycle) {
- // We've detected a cycle. We should ignore this connection and allow
- // this process to retry computeOomAdjLocked later in case a later-checked
- // connection from a client would raise its priority legitimately.
+ // We've detected a cycle. We should retry computeOomAdjLocked later in
+ // case a later-checked connection from a client would raise its
+ // priority legitimately.
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 clientProcState = client.curProcState;
@@ -23768,11 +23775,16 @@ public class ActivityManagerService extends IActivityManager.Stub
}
computeOomAdjLocked(client, cachedAdj, TOP_APP, doingAll, now);
if (client.containsCycle) {
- // We've detected a cycle. We should ignore this connection and allow
- // this process to retry computeOomAdjLocked later in case a later-checked
- // connection from a client would raise its priority legitimately.
+ // We've detected a cycle. We should retry computeOomAdjLocked later in
+ // case a later-checked connection from a client would raise its
+ // priority legitimately.
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 clientProcState = client.curProcState;
@@ -24004,8 +24016,8 @@ public class ActivityManagerService extends IActivityManager.Stub
app.foregroundActivities = foregroundActivities;
app.completedAdjSeq = mAdjSeq;
- // if curAdj is less than prevAppAdj, then this process was promoted
- return app.curAdj < prevAppAdj;
+ // if curAdj or curProcState improved, then this process was promoted
+ return app.curAdj < prevAppAdj || app.curProcState < prevProcState;
}
/**
@@ -25058,7 +25070,7 @@ public class ActivityManagerService extends IActivityManager.Stub
// - Continue retrying until no process was promoted.
// - Iterate from least important to most important.
int cycleCount = 0;
- while (retryCycles) {
+ while (retryCycles && cycleCount < 10) {
cycleCount++;
retryCycles = false;
@@ -25073,12 +25085,14 @@ public class ActivityManagerService extends IActivityManager.Stub
for (int i=0; i<N; i++) {
ProcessRecord app = mLruProcesses.get(i);
if (!app.killedByAm && app.thread != null && app.containsCycle == true) {
+
if (computeOomAdjLocked(app, ProcessList.UNKNOWN_ADJ, TOP_APP, true, now)) {
retryCycles = true;
}
}
}
}
+
for (int i=N-1; i>=0; i--) {
ProcessRecord app = mLruProcesses.get(i);
if (!app.killedByAm && app.thread != null) {