Clean up OomAdjusterModernImpl
Reorganize OomAdjusterModernImpl for future changes.
Moved most logic into reusable helper methods and functional interface
implementations.
Reimplemented the reachable process collection step to use the same
code as the process traversal step. It is important that the traversal
algorithm for these two steps are identical (If the traversal step finds
a process the reachable step did not find, the wrong values could get
calculated).
Replaced the excluded client process collection step with just
evaluating the connections into the target and reachable processes.
Bug: 323376416
Test: atest MockingOomAdjusterTests
Change-Id: If61a700c092574b1fc3a7a456d89dd0e478d2672
diff --git a/services/core/java/com/android/server/am/ConnectionRecord.java b/services/core/java/com/android/server/am/ConnectionRecord.java
index 4ef31bf..f2b9b25 100644
--- a/services/core/java/com/android/server/am/ConnectionRecord.java
+++ b/services/core/java/com/android/server/am/ConnectionRecord.java
@@ -17,6 +17,7 @@
package com.android.server.am;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
+import static com.android.server.am.ProcessList.UNKNOWN_ADJ;
import android.annotation.Nullable;
import android.app.IServiceConnection;
@@ -37,7 +38,7 @@
/**
* Description of a single binding to a service.
*/
-final class ConnectionRecord {
+final class ConnectionRecord implements OomAdjusterModernImpl.Connection{
final AppBindRecord binding; // The application/service binding.
final ActivityServiceConnectionsHolder<ConnectionRecord> activity; // If non-null, the owning activity.
final IServiceConnection conn; // The client connection.
@@ -127,6 +128,14 @@
aliasComponent = _aliasComponent;
}
+ @Override
+ public void computeHostOomAdjLSP(OomAdjuster oomAdjuster, ProcessRecord host,
+ ProcessRecord client, long now, ProcessRecord topApp, boolean doingAll,
+ int oomAdjReason, int cachedAdj) {
+ oomAdjuster.computeServiceHostOomAdjLSP(this, host, client, now, topApp, doingAll, false,
+ false, oomAdjReason, UNKNOWN_ADJ, false, false);
+ }
+
public long getFlags() {
return flags;
}
diff --git a/services/core/java/com/android/server/am/ContentProviderConnection.java b/services/core/java/com/android/server/am/ContentProviderConnection.java
index 825b938..3988277 100644
--- a/services/core/java/com/android/server/am/ContentProviderConnection.java
+++ b/services/core/java/com/android/server/am/ContentProviderConnection.java
@@ -18,6 +18,7 @@
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PROVIDER;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
+import static com.android.server.am.ProcessList.UNKNOWN_ADJ;
import android.annotation.UserIdInt;
import android.os.Binder;
@@ -32,7 +33,8 @@
/**
* Represents a link between a content provider and client.
*/
-public final class ContentProviderConnection extends Binder {
+public final class ContentProviderConnection extends Binder implements
+ OomAdjusterModernImpl.Connection {
public final ContentProviderRecord provider;
public final ProcessRecord client;
public final String clientPackage;
@@ -72,6 +74,14 @@
createTime = SystemClock.elapsedRealtime();
}
+ @Override
+ public void computeHostOomAdjLSP(OomAdjuster oomAdjuster, ProcessRecord host,
+ ProcessRecord client, long now, ProcessRecord topApp, boolean doingAll,
+ int oomAdjReason, int cachedAdj) {
+ oomAdjuster.computeProviderHostOomAdjLSP(this, host, client, now, topApp, doingAll, false,
+ false, oomAdjReason, UNKNOWN_ADJ, false, false);
+ }
+
public void startAssociationIfNeeded() {
// If we don't already have an active association, create one... but only if this
// is an association between two different processes.
diff --git a/services/core/java/com/android/server/am/OomAdjuster.java b/services/core/java/com/android/server/am/OomAdjuster.java
index 31328ae..cd6964e 100644
--- a/services/core/java/com/android/server/am/OomAdjuster.java
+++ b/services/core/java/com/android/server/am/OomAdjuster.java
@@ -587,7 +587,7 @@
}
@GuardedBy({"mService", "mProcLock"})
- private void performUpdateOomAdjLSP(@OomAdjReason int oomAdjReason) {
+ protected void performUpdateOomAdjLSP(@OomAdjReason int oomAdjReason) {
final ProcessRecord topApp = mService.getTopApp();
// Clear any pending ones because we are doing a full update now.
mPendingProcessSet.clear();
@@ -913,7 +913,7 @@
}
@GuardedBy("mService")
- private void performUpdateOomAdjPendingTargetsLocked(@OomAdjReason int oomAdjReason) {
+ protected void performUpdateOomAdjPendingTargetsLocked(@OomAdjReason int oomAdjReason) {
final ProcessRecord topApp = mService.getTopApp();
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, oomAdjReasonToString(oomAdjReason));
@@ -941,7 +941,7 @@
* must have called {@link collectReachableProcessesLocked} on it.
*/
@GuardedBy({"mService", "mProcLock"})
- protected void updateOomAdjInnerLSP(@OomAdjReason int oomAdjReason, final ProcessRecord topApp,
+ private void updateOomAdjInnerLSP(@OomAdjReason int oomAdjReason, final ProcessRecord topApp,
ArrayList<ProcessRecord> processes, ActiveUids uids, boolean potentialCycles,
boolean startProfiling) {
final boolean fullUpdate = processes == null;
@@ -1775,12 +1775,11 @@
state.setAdjSeq(mAdjSeq);
state.setCurrentSchedulingGroup(SCHED_GROUP_BACKGROUND);
state.setCurProcState(PROCESS_STATE_CACHED_EMPTY);
+ state.setCurRawProcState(PROCESS_STATE_CACHED_EMPTY);
state.setCurAdj(CACHED_APP_MAX_ADJ);
state.setCurRawAdj(CACHED_APP_MAX_ADJ);
state.setCompletedAdjSeq(state.getAdjSeq());
state.setCurCapability(PROCESS_CAPABILITY_NONE);
- onProcessStateChanged(app, prevProcState);
- onProcessOomAdjChanged(app, prevAppAdj);
return false;
}
@@ -1843,8 +1842,6 @@
state.setCurRawProcState(state.getCurProcState());
state.setCurAdj(state.getMaxAdj());
state.setCompletedAdjSeq(state.getAdjSeq());
- onProcessStateChanged(app, prevProcState);
- onProcessOomAdjChanged(app, prevAppAdj);
// if curAdj is less than prevAppAdj, then this process was promoted
return state.getCurAdj() < prevAppAdj || state.getCurProcState() < prevProcState;
}
@@ -2561,7 +2558,7 @@
}
@GuardedBy({"mService", "mProcLock"})
- protected boolean computeServiceHostOomAdjLSP(ConnectionRecord cr, ProcessRecord app,
+ public boolean computeServiceHostOomAdjLSP(ConnectionRecord cr, ProcessRecord app,
ProcessRecord client, long now, ProcessRecord topApp, boolean doingAll,
boolean cycleReEval, boolean computeClients, int oomAdjReason, int cachedAdj,
boolean couldRecurse, boolean dryRun) {
@@ -2991,7 +2988,11 @@
return updated;
}
- protected boolean computeProviderHostOomAdjLSP(ContentProviderConnection conn,
+ /**
+ * Computes the impact on {@code app} the provider connections from {@code client} has.
+ */
+ @GuardedBy({"mService", "mProcLock"})
+ public boolean computeProviderHostOomAdjLSP(ContentProviderConnection conn,
ProcessRecord app, ProcessRecord client, long now, ProcessRecord topApp,
boolean doingAll, boolean cycleReEval, boolean computeClients, int oomAdjReason,
int cachedAdj, boolean couldRecurse, boolean dryRun) {
@@ -3572,7 +3573,7 @@
int initialCapability = PROCESS_CAPABILITY_NONE;
boolean initialCached = true;
final ProcessStateRecord state = app.mState;
- final int prevProcState = state.getCurRawProcState();
+ final int prevProcState = state.getCurProcState();
final int prevAdj = state.getCurRawAdj();
// If the process has been marked as foreground, it is starting as the top app (with
// Zygote#START_AS_TOP_APP_ARG), so boost the thread priority of its default UI thread.
diff --git a/services/core/java/com/android/server/am/OomAdjusterModernImpl.java b/services/core/java/com/android/server/am/OomAdjusterModernImpl.java
index 1bf779a..dd75bc0 100644
--- a/services/core/java/com/android/server/am/OomAdjusterModernImpl.java
+++ b/services/core/java/com/android/server/am/OomAdjusterModernImpl.java
@@ -38,7 +38,6 @@
import static android.app.ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND;
import static android.app.ActivityManager.PROCESS_STATE_UNKNOWN;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_OOM_ADJ;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_UID_OBSERVERS;
import static com.android.server.am.ActivityManagerService.TAG_UID_OBSERVERS;
import static com.android.server.am.ProcessList.BACKUP_APP_ADJ;
@@ -67,8 +66,10 @@
import android.app.ActivityManager;
import android.app.ActivityManagerInternal.OomAdjReason;
import android.content.pm.ServiceInfo;
+import android.os.IBinder;
import android.os.SystemClock;
import android.os.Trace;
+import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Slog;
@@ -80,6 +81,7 @@
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.function.BiConsumer;
import java.util.function.Consumer;
/**
@@ -275,6 +277,7 @@
mProcessRecordNodes[i] = new LinkedProcessRecordList(type);
}
mLastNode = new ProcessRecordNode[size];
+ resetLastNodes();
}
int size() {
@@ -285,7 +288,7 @@
void reset() {
for (int i = 0; i < mProcessRecordNodes.length; i++) {
mProcessRecordNodes[i].reset();
- mLastNode[i] = null;
+ setLastNodeToHead(i);
}
}
@@ -509,26 +512,118 @@
}
/**
- * A helper consumer for collecting processes that have not been reached yet. To avoid object
- * allocations every OomAdjuster update, the results will be stored in
- * {@link UnreachedProcessCollector#processList}. The process list reader is responsible
- * for setting it before usage, as well as, clearing the reachable state of each process in the
- * list.
+ * A {@link Connection} represents any connection between two processes that can cause a
+ * change in importance in the host process based on the client process and connection state.
*/
- private static class UnreachedProcessCollector implements Consumer<ProcessRecord> {
- public ArrayList<ProcessRecord> processList = null;
+ public interface Connection {
+ /**
+ * Compute the impact this connection has on the host's importance values.
+ */
+ void computeHostOomAdjLSP(OomAdjuster oomAdjuster, ProcessRecord host, ProcessRecord client,
+ long now, ProcessRecord topApp, boolean doingAll, int oomAdjReason, int cachedAdj);
+ }
+
+ /**
+ * A helper consumer for marking and collecting reachable processes.
+ */
+ private static class ReachableCollectingConsumer implements
+ BiConsumer<Connection, ProcessRecord> {
+ ArrayList<ProcessRecord> mReachables = null;
+
+ public void init(ArrayList<ProcessRecord> reachables) {
+ mReachables = reachables;
+ }
+
@Override
- public void accept(ProcessRecord process) {
- if (process.mState.isReachable()) {
+ public void accept(Connection unused, ProcessRecord host) {
+ if (host.mState.isReachable()) {
return;
}
- process.mState.setReachable(true);
- processList.add(process);
+ host.mState.setReachable(true);
+ mReachables.add(host);
}
}
- private final UnreachedProcessCollector mUnreachedProcessCollector =
- new UnreachedProcessCollector();
+ private final ReachableCollectingConsumer mReachableCollectingConsumer =
+ new ReachableCollectingConsumer();
+
+ /**
+ * A helper consumer for computing the importance of a connection from a client.
+ * Connections for clients marked reachable will be ignored.
+ */
+ private class ComputeConnectionIgnoringReachableClientsConsumer implements
+ BiConsumer<Connection, ProcessRecord> {
+ public OomAdjusterArgs args = null;
+
+ @Override
+ public void accept(Connection conn, ProcessRecord client) {
+ final ProcessRecord host = args.mApp;
+ final ProcessRecord topApp = args.mTopApp;
+ final long now = args.mNow;
+ final @OomAdjReason int oomAdjReason = args.mOomAdjReason;
+
+ if (client.mState.isReachable()) return;
+
+ conn.computeHostOomAdjLSP(OomAdjusterModernImpl.this, host, client, now, topApp, false,
+ oomAdjReason, UNKNOWN_ADJ);
+ }
+ }
+
+ private final ComputeConnectionIgnoringReachableClientsConsumer
+ mComputeConnectionIgnoringReachableClientsConsumer =
+ new ComputeConnectionIgnoringReachableClientsConsumer();
+
+ /**
+ * A helper consumer for computing host process importance from a connection from a client app.
+ */
+ private class ComputeHostConsumer implements BiConsumer<Connection, ProcessRecord> {
+ public OomAdjusterArgs args = null;
+
+ @Override
+ public void accept(Connection conn, ProcessRecord host) {
+ final ProcessRecord client = args.mApp;
+ final int cachedAdj = args.mCachedAdj;
+ final ProcessRecord topApp = args.mTopApp;
+ final long now = args.mNow;
+ final @OomAdjReason int oomAdjReason = args.mOomAdjReason;
+ final boolean fullUpdate = args.mFullUpdate;
+
+ final int prevProcState = host.mState.getCurProcState();
+ final int prevAdj = host.mState.getCurRawAdj();
+
+ conn.computeHostOomAdjLSP(OomAdjusterModernImpl.this, host, client, now, topApp,
+ fullUpdate, oomAdjReason, cachedAdj);
+
+ updateProcStateSlotIfNecessary(host, prevProcState);
+ updateAdjSlotIfNecessary(host, prevAdj);
+ }
+ }
+ private final ComputeHostConsumer mComputeHostConsumer = new ComputeHostConsumer();
+
+ /**
+ * A helper consumer for computing all connections from an app.
+ */
+ private class ComputeConnectionsConsumer implements Consumer<OomAdjusterArgs> {
+ @Override
+ public void accept(OomAdjusterArgs args) {
+ final ProcessRecord app = args.mApp;
+ final ActiveUids uids = args.mUids;
+
+ // This process was updated in some way, mark that it was last calculated this sequence.
+ app.mState.setCompletedAdjSeq(mAdjSeq);
+ if (uids != null) {
+ final UidRecord uidRec = app.getUidRecord();
+
+ if (uidRec != null) {
+ uids.put(uidRec.getUid(), uidRec);
+ }
+ }
+ mComputeHostConsumer.args = args;
+ forEachConnectionLSP(app, mComputeHostConsumer);
+ }
+ }
+ private final ComputeConnectionsConsumer mComputeConnectionsConsumer =
+ new ComputeConnectionsConsumer();
OomAdjusterModernImpl(ActivityManagerService service, ProcessList processList,
ActiveUids activeUids) {
@@ -617,6 +712,12 @@
}
}
+ private void updateAdjSlot(ProcessRecord app, int prevRawAdj) {
+ final int slot = adjToSlot(app.mState.getCurRawAdj());
+ final int prevSlot = adjToSlot(prevRawAdj);
+ mProcessRecordAdjNodes.moveAppTo(app, prevSlot, slot);
+ }
+
private void updateProcStateSlotIfNecessary(ProcessRecord app, int prevProcState) {
if (app.mState.getCurProcState() != prevProcState) {
final int slot = processStateToSlot(app.mState.getCurProcState());
@@ -627,359 +728,247 @@
}
}
+ private void updateProcStateSlot(ProcessRecord app, int prevProcState) {
+ final int slot = processStateToSlot(app.mState.getCurProcState());
+ final int prevSlot = processStateToSlot(prevProcState);
+ mProcessRecordProcStateNodes.moveAppTo(app, prevSlot, slot);
+ }
+
@Override
- protected boolean performUpdateOomAdjLSP(ProcessRecord app, @OomAdjReason int oomAdjReason) {
+ protected void performUpdateOomAdjLSP(@OomAdjReason int oomAdjReason) {
final ProcessRecord topApp = mService.getTopApp();
+ // Clear any pending ones because we are doing a full update now.
+ mPendingProcessSet.clear();
+ mService.mAppProfiler.mHasPreviousProcess = mService.mAppProfiler.mHasHomeProcess = false;
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, oomAdjReasonToString(oomAdjReason));
mService.mOomAdjProfiler.oomAdjStarted();
- mAdjSeq++;
- final ProcessStateRecord state = app.mState;
- final int oldAdj = state.getCurRawAdj();
- final int cachedAdj = oldAdj >= CACHED_APP_MIN_ADJ
- ? oldAdj : UNKNOWN_ADJ;
-
- final ActiveUids uids = mTmpUidRecords;
- final ArraySet<ProcessRecord> targetProcesses = mTmpProcessSet;
- final ArrayList<ProcessRecord> reachableProcesses = mTmpProcessList;
- final long now = SystemClock.uptimeMillis();
- final long nowElapsed = SystemClock.elapsedRealtime();
-
- uids.clear();
- targetProcesses.clear();
- targetProcesses.add(app);
- reachableProcesses.clear();
-
- // Find out all reachable processes from this app.
- collectReachableProcessesLocked(targetProcesses, reachableProcesses, uids);
-
- // Copy all of the reachable processes into the target process set.
- targetProcesses.addAll(reachableProcesses);
- reachableProcesses.clear();
-
- final boolean result = performNewUpdateOomAdjLSP(oomAdjReason,
- topApp, targetProcesses, uids, false, now, cachedAdj);
-
- reachableProcesses.addAll(targetProcesses);
- assignCachedAdjIfNecessary(reachableProcesses);
- for (int i = uids.size() - 1; i >= 0; i--) {
- final UidRecord uidRec = uids.valueAt(i);
- uidRec.forEachProcess(this::updateAppUidRecIfNecessaryLSP);
- }
- updateUidsLSP(uids, nowElapsed);
- for (int i = 0, size = targetProcesses.size(); i < size; i++) {
- applyOomAdjLSP(targetProcesses.valueAt(i), false, now, nowElapsed, oomAdjReason);
- }
- targetProcesses.clear();
- reachableProcesses.clear();
+ fullUpdateLSP(oomAdjReason);
mService.mOomAdjProfiler.oomAdjEnded();
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
- return result;
}
@GuardedBy({"mService", "mProcLock"})
@Override
- protected void updateOomAdjInnerLSP(@OomAdjReason int oomAdjReason, final ProcessRecord topApp,
- ArrayList<ProcessRecord> processes, ActiveUids uids, boolean potentialCycles,
- boolean startProfiling) {
- final boolean fullUpdate = processes == null;
- final ArrayList<ProcessRecord> activeProcesses = fullUpdate
- ? mProcessList.getLruProcessesLOSP() : processes;
- ActiveUids activeUids = uids;
- if (activeUids == null) {
- final int numUids = mActiveUids.size();
- activeUids = mTmpUidRecords;
- activeUids.clear();
- for (int i = 0; i < numUids; i++) {
- UidRecord uidRec = mActiveUids.valueAt(i);
- activeUids.put(uidRec.getUid(), uidRec);
- }
- }
-
- if (startProfiling) {
- Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, oomAdjReasonToString(oomAdjReason));
- mService.mOomAdjProfiler.oomAdjStarted();
- }
- final long now = SystemClock.uptimeMillis();
- final long nowElapsed = SystemClock.elapsedRealtime();
- final long oldTime = now - mConstants.mMaxEmptyTimeMillis;
- final int numProc = activeProcesses.size();
-
- mAdjSeq++;
- if (fullUpdate) {
- mNewNumServiceProcs = 0;
- mNewNumAServiceProcs = 0;
- }
-
- final ArraySet<ProcessRecord> targetProcesses = mTmpProcessSet;
- targetProcesses.clear();
- if (!fullUpdate) {
- targetProcesses.addAll(activeProcesses);
- }
-
- performNewUpdateOomAdjLSP(oomAdjReason, topApp, targetProcesses, activeUids,
- fullUpdate, now, UNKNOWN_ADJ);
-
- // TODO: b/319163103 - optimize cache adj assignment to not require the whole lru list.
- assignCachedAdjIfNecessary(mProcessList.getLruProcessesLOSP());
- postUpdateOomAdjInnerLSP(oomAdjReason, activeUids, now, nowElapsed, oldTime);
- targetProcesses.clear();
-
- if (startProfiling) {
- mService.mOomAdjProfiler.oomAdjEnded();
- Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
- }
- return;
- }
-
- /**
- * Perform the oom adj update on the given {@code targetProcesses}.
- *
- * <p>Note: The expectation to the given {@code targetProcesses} is, the caller
- * must have called {@link collectReachableProcessesLocked} on it.
- */
- private boolean performNewUpdateOomAdjLSP(@OomAdjReason int oomAdjReason,
- ProcessRecord topApp, ArraySet<ProcessRecord> targetProcesses, ActiveUids uids,
- boolean fullUpdate, long now, int cachedAdj) {
-
- final ArrayList<ProcessRecord> clientProcesses = mTmpProcessList2;
- clientProcesses.clear();
-
- // We'll need to collect the upstream processes of the target apps here, because those
- // processes would potentially impact the procstate/adj via bindings.
- if (!fullUpdate) {
- collectExcludedClientProcessesLocked(targetProcesses, clientProcesses);
-
- for (int i = 0, size = targetProcesses.size(); i < size; i++) {
- final ProcessRecord app = targetProcesses.valueAt(i);
- app.mState.resetCachedInfo();
- final UidRecord uidRec = app.getUidRecord();
- if (uidRec != null) {
- if (DEBUG_UID_OBSERVERS) {
- Slog.i(TAG_UID_OBSERVERS, "Starting update of " + uidRec);
- }
- uidRec.reset();
- }
- }
- } else {
- final ArrayList<ProcessRecord> lru = mProcessList.getLruProcessesLOSP();
- for (int i = 0, size = lru.size(); i < size; i++) {
- final ProcessRecord app = lru.get(i);
- app.mState.resetCachedInfo();
- final UidRecord uidRec = app.getUidRecord();
- if (uidRec != null) {
- if (DEBUG_UID_OBSERVERS) {
- Slog.i(TAG_UID_OBSERVERS, "Starting update of " + uidRec);
- }
- uidRec.reset();
- }
- }
- }
-
- updateNewOomAdjInnerLSP(oomAdjReason, topApp, targetProcesses, clientProcesses, uids,
- cachedAdj, now, fullUpdate);
-
- clientProcesses.clear();
-
+ protected boolean performUpdateOomAdjLSP(ProcessRecord app, @OomAdjReason int oomAdjReason) {
+ mPendingProcessSet.add(app);
+ performUpdateOomAdjPendingTargetsLocked(oomAdjReason);
return true;
}
- /**
- * Collect the client processes from the given {@code apps}, the result will be returned in the
- * given {@code clientProcesses}, which will <em>NOT</em> include the processes from the given
- * {@code apps}.
- */
@GuardedBy("mService")
- private void collectExcludedClientProcessesLocked(ArraySet<ProcessRecord> apps,
- ArrayList<ProcessRecord> clientProcesses) {
- // Mark all of the provided apps as reachable to avoid including them in the client list.
- final int appsSize = apps.size();
- for (int i = 0; i < appsSize; i++) {
- final ProcessRecord app = apps.valueAt(i);
- app.mState.setReachable(true);
- }
+ @Override
+ protected void performUpdateOomAdjPendingTargetsLocked(@OomAdjReason int oomAdjReason) {
+ Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, oomAdjReasonToString(oomAdjReason));
+ mService.mOomAdjProfiler.oomAdjStarted();
- clientProcesses.clear();
- mUnreachedProcessCollector.processList = clientProcesses;
- for (int i = 0; i < appsSize; i++) {
- final ProcessRecord app = apps.valueAt(i);
- app.forEachClient(mUnreachedProcessCollector);
+ synchronized (mProcLock) {
+ partialUpdateLSP(oomAdjReason, mPendingProcessSet);
}
- mUnreachedProcessCollector.processList = null;
+ mPendingProcessSet.clear();
- // Reset the temporary bits.
- for (int i = clientProcesses.size() - 1; i >= 0; i--) {
- clientProcesses.get(i).mState.setReachable(false);
- }
- for (int i = 0, size = apps.size(); i < size; i++) {
- final ProcessRecord app = apps.valueAt(i);
- app.mState.setReachable(false);
- }
+ mService.mOomAdjProfiler.oomAdjEnded();
+ Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
}
+ /**
+ * Perform a full update on the entire process list.
+ */
@GuardedBy({"mService", "mProcLock"})
- private void updateNewOomAdjInnerLSP(@OomAdjReason int oomAdjReason, final ProcessRecord topApp,
- ArraySet<ProcessRecord> targetProcesses, ArrayList<ProcessRecord> clientProcesses,
- ActiveUids uids, int cachedAdj, long now, boolean fullUpdate) {
- mTmpOomAdjusterArgs.update(topApp, now, cachedAdj, oomAdjReason, uids, fullUpdate);
-
- mProcessRecordProcStateNodes.resetLastNodes();
- mProcessRecordAdjNodes.resetLastNodes();
-
- final int procStateTarget = mProcessRecordProcStateNodes.size() - 1;
- final int adjTarget = mProcessRecordAdjNodes.size() - 1;
+ private void fullUpdateLSP(@OomAdjReason int oomAdjReason) {
+ final ProcessRecord topApp = mService.getTopApp();
+ final long now = SystemClock.uptimeMillis();
+ final long nowElapsed = SystemClock.elapsedRealtime();
+ final long oldTime = now - mConstants.mMaxEmptyTimeMillis;
mAdjSeq++;
- // All apps to be updated will be moved to the lowest slot.
- if (fullUpdate) {
- // Move all the process record node to the lowest slot, we'll do recomputation on all of
- // them. Use the processes from the lru list, because the scanning order matters here.
- final ArrayList<ProcessRecord> lruList = mProcessList.getLruProcessesLOSP();
- for (int i = procStateTarget; i >= 0; i--) {
- mProcessRecordProcStateNodes.reset(i);
- // Force the last node to the head since we'll recompute all of them.
- mProcessRecordProcStateNodes.setLastNodeToHead(i);
+
+ mNewNumServiceProcs = 0;
+ mNewNumAServiceProcs = 0;
+
+ // Clear the priority queues.
+ mProcessRecordProcStateNodes.reset();
+ mProcessRecordAdjNodes.reset();
+
+ final ArrayList<ProcessRecord> lru = mProcessList.getLruProcessesLOSP();
+ for (int i = lru.size() - 1; i >= 0; i--) {
+ final ProcessRecord app = lru.get(i);
+ final int prevProcState = app.mState.getCurProcState();
+ final int prevAdj = app.mState.getCurRawAdj();
+ app.mState.resetCachedInfo();
+ final UidRecord uidRec = app.getUidRecord();
+ if (uidRec != null) {
+ if (DEBUG_UID_OBSERVERS) {
+ Slog.i(TAG_UID_OBSERVERS, "Starting update of " + uidRec);
+ }
+ uidRec.reset();
}
- // enqueue the targets in the reverse order of the lru list.
- for (int i = lruList.size() - 1; i >= 0; i--) {
- mProcessRecordProcStateNodes.append(lruList.get(i), procStateTarget);
- }
- // Do the same to the adj nodes.
- for (int i = adjTarget; i >= 0; i--) {
- mProcessRecordAdjNodes.reset(i);
- // Force the last node to the head since we'll recompute all of them.
- mProcessRecordAdjNodes.setLastNodeToHead(i);
- }
- for (int i = lruList.size() - 1; i >= 0; i--) {
- mProcessRecordAdjNodes.append(lruList.get(i), adjTarget);
- }
- } else {
- // Move the target processes to the lowest slot.
- for (int i = 0, size = targetProcesses.size(); i < size; i++) {
- final ProcessRecord app = targetProcesses.valueAt(i);
- final int procStateSlot = processStateToSlot(app.mState.getCurProcState());
- final int adjSlot = adjToSlot(app.mState.getCurRawAdj());
- mProcessRecordProcStateNodes.moveAppTo(app, procStateSlot, procStateTarget);
- mProcessRecordAdjNodes.moveAppTo(app, adjSlot, adjTarget);
- }
- // Move the "lastNode" to head to make sure we scan all nodes in this slot.
- mProcessRecordProcStateNodes.setLastNodeToHead(procStateTarget);
- mProcessRecordAdjNodes.setLastNodeToHead(adjTarget);
+
+ // Compute initial values, the procState and adj priority queues will be populated here.
+ computeOomAdjLSP(app, UNKNOWN_ADJ, topApp, true, now, false, false, oomAdjReason,
+ false);
+ updateProcStateSlot(app, prevProcState);
+ updateAdjSlot(app, prevAdj);
}
- // All apps to be updated have been moved to the lowest slot.
- // Do an initial pass of the computation.
- mProcessRecordProcStateNodes.forEachNewNode(mProcessRecordProcStateNodes.size() - 1,
- this::computeInitialOomAdjLSP);
-
- if (!fullUpdate) {
- // We didn't update the client processes with the computeInitialOomAdjLSP
- // because they don't need to do so. But they'll be playing vital roles in
- // computing the bindings. So include them into the scan list below.
- for (int i = 0, size = clientProcesses.size(); i < size; i++) {
- mProcessRecordProcStateNodes.moveAppToTail(clientProcesses.get(i));
- }
- // We don't update the adj list since we're resetting it below.
- }
-
- // Now nodes are set into their slots, without factoring in the bindings.
- // The nodes between the `lastNode` pointer and the TAIL should be the new nodes.
- //
- // The whole rationale here is that, the bindings from client to host app, won't elevate
- // the host app's procstate/adj higher than the client app's state (BIND_ABOVE_CLIENT
- // is a special case here, but client app's raw adj is still no less than the host app's).
- // Therefore, starting from the top to the bottom, for each slot, scan all of the new nodes,
- // check its bindings, elevate its host app's slot if necessary.
- //
- // We'd have to do this in two passes: 1) scan procstate node list; 2) scan adj node list.
- // Because the procstate and adj are not always in sync - there are cases where
- // the processes with lower proc state could be getting a higher oom adj score.
- // And because of this, the procstate and adj node lists are basically two priority heaps.
- //
- // As the 2nd pass with the adj node lists potentially includes a significant amount of
- // duplicated scans as the 1st pass has done, we'll reset the last node pointers for
- // the adj node list before the 1st pass; so during the 1st pass, if any app's adj slot
- // gets bumped, we'll only scan those in 2nd pass.
-
+ // Set adj last nodes now, this way a process will only be reevaluated during the adj node
+ // iteration if they adj score changed during the procState node iteration.
mProcessRecordAdjNodes.resetLastNodes();
+ mTmpOomAdjusterArgs.update(topApp, now, UNKNOWN_ADJ, oomAdjReason, null, true);
+ computeConnectionsLSP();
+ assignCachedAdjIfNecessary(mProcessList.getLruProcessesLOSP());
+ postUpdateOomAdjInnerLSP(oomAdjReason, mActiveUids, now, nowElapsed, oldTime);
+ }
+
+ /**
+ * Traverse the process graph and update processes based on changes in connection importances.
+ */
+ @GuardedBy({"mService", "mProcLock"})
+ private void computeConnectionsLSP() {
// 1st pass, scan each slot in the procstate node list.
for (int i = 0, end = mProcessRecordProcStateNodes.size() - 1; i < end; i++) {
- mProcessRecordProcStateNodes.forEachNewNode(i, this::computeHostOomAdjLSP);
+ mProcessRecordProcStateNodes.forEachNewNode(i, mComputeConnectionsConsumer);
}
// 2nd pass, scan each slot in the adj node list.
for (int i = 0, end = mProcessRecordAdjNodes.size() - 1; i < end; i++) {
- mProcessRecordAdjNodes.forEachNewNode(i, this::computeHostOomAdjLSP);
+ mProcessRecordAdjNodes.forEachNewNode(i, mComputeConnectionsConsumer);
}
}
- @GuardedBy({"mService", "mProcLock"})
- private void computeInitialOomAdjLSP(OomAdjusterArgs args) {
- final ProcessRecord app = args.mApp;
- final int cachedAdj = args.mCachedAdj;
- final ProcessRecord topApp = args.mTopApp;
- final long now = args.mNow;
- final int oomAdjReason = args.mOomAdjReason;
- final ActiveUids uids = args.mUids;
- final boolean fullUpdate = args.mFullUpdate;
-
- if (DEBUG_OOM_ADJ) {
- Slog.i(TAG, "OOM ADJ initial args app=" + app
- + " cachedAdj=" + cachedAdj
- + " topApp=" + topApp
- + " now=" + now
- + " oomAdjReason=" + oomAdjReasonToString(oomAdjReason)
- + " fullUpdate=" + fullUpdate);
- }
-
- if (uids != null) {
- final UidRecord uidRec = app.getUidRecord();
-
- if (uidRec != null) {
- uids.put(uidRec.getUid(), uidRec);
- }
- }
-
- computeOomAdjLSP(app, cachedAdj, topApp, fullUpdate, now, false, false, oomAdjReason,
- false);
- }
-
/**
- * @return The proposed change to the schedGroup.
+ * Perform a partial update on the target processes and their reachable processes.
*/
@GuardedBy({"mService", "mProcLock"})
- @Override
- protected int setIntermediateAdjLSP(ProcessRecord app, int adj, int prevRawAppAdj,
- int schedGroup) {
- schedGroup = super.setIntermediateAdjLSP(app, adj, prevRawAppAdj, schedGroup);
+ private void partialUpdateLSP(@OomAdjReason int oomAdjReason, ArraySet<ProcessRecord> targets) {
+ final ProcessRecord topApp = mService.getTopApp();
+ final long now = SystemClock.uptimeMillis();
+ final long nowElapsed = SystemClock.elapsedRealtime();
+ final long oldTime = now - mConstants.mMaxEmptyTimeMillis;
- updateAdjSlotIfNecessary(app, prevRawAppAdj);
+ ActiveUids activeUids = mTmpUidRecords;
+ activeUids.clear();
+ mTmpOomAdjusterArgs.update(topApp, now, UNKNOWN_ADJ, oomAdjReason, activeUids, false);
- return schedGroup;
+ mAdjSeq++;
+
+ final ArrayList<ProcessRecord> reachables = mTmpProcessList;
+ reachables.clear();
+
+ for (int i = 0, size = targets.size(); i < size; i++) {
+ final ProcessRecord target = targets.valueAtUnchecked(i);
+ target.mState.resetCachedInfo();
+ target.mState.setReachable(true);
+ reachables.add(target);
+ }
+
+ // Collect all processes that are reachable.
+ // Any process not found in this step will not change in importance during this update.
+ collectAndMarkReachableProcessesLSP(reachables);
+
+ // Initialize the reachable processes based on their own values plus any
+ // connections from processes not found in the previous step. Since those non-reachable
+ // processes cannot change as a part of this update, their current values can be used
+ // right now.
+ mProcessRecordProcStateNodes.resetLastNodes();
+ initReachableStatesLSP(reachables, mTmpOomAdjusterArgs);
+
+ // Set adj last nodes now, this way a process will only be reevaluated during the adj node
+ // iteration if they adj score changed during the procState node iteration.
+ mProcessRecordAdjNodes.resetLastNodes();
+ // Now traverse and compute the connections of processes with changed importance.
+ computeConnectionsLSP();
+
+ boolean unassignedAdj = false;
+ for (int i = 0, size = reachables.size(); i < size; i++) {
+ final ProcessStateRecord state = reachables.get(i).mState;
+ state.setReachable(false);
+ state.setCompletedAdjSeq(mAdjSeq);
+ if (state.getCurAdj() >= UNKNOWN_ADJ) {
+ unassignedAdj = true;
+ }
+ }
+
+ // If all processes have an assigned adj, no need to calculate and assign cached adjs.
+ if (unassignedAdj) {
+ // TODO: b/319163103 - optimize cache adj assignment to not require the whole lru list.
+ assignCachedAdjIfNecessary(mProcessList.getLruProcessesLOSP());
+ }
+
+ // Repopulate any uid record that may have changed.
+ for (int i = 0, size = activeUids.size(); i < size; i++) {
+ final UidRecord ur = activeUids.valueAt(i);
+ ur.reset();
+ for (int j = ur.getNumOfProcs() - 1; j >= 0; j--) {
+ final ProcessRecord proc = ur.getProcessRecordByIndex(j);
+ updateAppUidRecIfNecessaryLSP(proc);
+ }
+ }
+
+ postUpdateOomAdjInnerLSP(oomAdjReason, activeUids, now, nowElapsed, oldTime);
}
+ /**
+ * Mark all processes reachable from the {@code reachables} processes and add them to the
+ * provided {@code reachables} list (targets excluded).
+ *
+ * Returns true if a cycle exists within the reachable process graph.
+ */
@GuardedBy({"mService", "mProcLock"})
- @Override
- protected void setIntermediateProcStateLSP(ProcessRecord app, int procState,
- int prevProcState) {
- super.setIntermediateProcStateLSP(app, procState, prevProcState);
-
- updateProcStateSlotIfNecessary(app, prevProcState);
+ private void collectAndMarkReachableProcessesLSP(ArrayList<ProcessRecord> reachables) {
+ mReachableCollectingConsumer.init(reachables);
+ for (int i = 0; i < reachables.size(); i++) {
+ ProcessRecord pr = reachables.get(i);
+ forEachConnectionLSP(pr, mReachableCollectingConsumer);
+ }
}
+ /**
+ * Calculate initial importance states for {@code reachables} and update their slot position
+ * if necessary.
+ */
+ private void initReachableStatesLSP(ArrayList<ProcessRecord> reachables, OomAdjusterArgs args) {
+ for (int i = 0, size = reachables.size(); i < size; i++) {
+ final ProcessRecord reachable = reachables.get(i);
+ final int prevProcState = reachable.mState.getCurProcState();
+ final int prevAdj = reachable.mState.getCurRawAdj();
+
+ args.mApp = reachable;
+ computeOomAdjIgnoringReachablesLSP(args);
+
+ updateProcStateSlot(reachable, prevProcState);
+ updateAdjSlot(reachable, prevAdj);
+ }
+ }
+
+ /**
+ * Calculate initial importance states for {@code app}.
+ * Processes not marked reachable cannot change as a part of this update, so connections from
+ * those process can be calculated now.
+ */
@GuardedBy({"mService", "mProcLock"})
- private void computeHostOomAdjLSP(OomAdjusterArgs args) {
+ private void computeOomAdjIgnoringReachablesLSP(OomAdjusterArgs args) {
final ProcessRecord app = args.mApp;
- final int cachedAdj = args.mCachedAdj;
final ProcessRecord topApp = args.mTopApp;
final long now = args.mNow;
final @OomAdjReason int oomAdjReason = args.mOomAdjReason;
- final boolean fullUpdate = args.mFullUpdate;
- final ActiveUids uids = args.mUids;
+ computeOomAdjLSP(app, UNKNOWN_ADJ, topApp, false, now, false, false, oomAdjReason, false);
+
+ mComputeConnectionIgnoringReachableClientsConsumer.args = args;
+ forEachClientConnectionLSP(app, mComputeConnectionIgnoringReachableClientsConsumer);
+ }
+
+ /**
+ * Stream the connections with {@code app} as a client to
+ * {@code connectionConsumer}.
+ */
+ @GuardedBy({"mService", "mProcLock"})
+ private static void forEachConnectionLSP(ProcessRecord app,
+ BiConsumer<Connection, ProcessRecord> connectionConsumer) {
final ProcessServiceRecord psr = app.mServices;
for (int i = psr.numberOfConnections() - 1; i >= 0; i--) {
ConnectionRecord cr = psr.getConnectionAt(i);
@@ -987,16 +976,14 @@
? cr.binding.service.isolationHostProc : cr.binding.service.app;
if (service == null || service == app
|| (service.mState.getMaxAdj() >= SYSTEM_ADJ
- && service.mState.getMaxAdj() < FOREGROUND_APP_ADJ)
+ && service.mState.getMaxAdj() < FOREGROUND_APP_ADJ)
|| (service.mState.getCurAdj() <= FOREGROUND_APP_ADJ
- && service.mState.getCurrentSchedulingGroup() > SCHED_GROUP_BACKGROUND
- && service.mState.getCurProcState() <= PROCESS_STATE_TOP)
+ && service.mState.getCurrentSchedulingGroup() > SCHED_GROUP_BACKGROUND
+ && service.mState.getCurProcState() <= PROCESS_STATE_TOP)
|| (service.isSdkSandbox && cr.binding.attributedClient != null)) {
continue;
}
-
- computeServiceHostOomAdjLSP(cr, service, app, now, topApp, fullUpdate, false, false,
- oomAdjReason, cachedAdj, false, false);
+ connectionConsumer.accept(cr, service);
}
for (int i = psr.numberOfSdkSandboxConnections() - 1; i >= 0; i--) {
@@ -1004,15 +991,13 @@
final ProcessRecord service = cr.binding.service.app;
if (service == null || service == app
|| (service.mState.getMaxAdj() >= SYSTEM_ADJ
- && service.mState.getMaxAdj() < FOREGROUND_APP_ADJ)
+ && service.mState.getMaxAdj() < FOREGROUND_APP_ADJ)
|| (service.mState.getCurAdj() <= FOREGROUND_APP_ADJ
- && service.mState.getCurrentSchedulingGroup() > SCHED_GROUP_BACKGROUND
- && service.mState.getCurProcState() <= PROCESS_STATE_TOP)) {
+ && service.mState.getCurrentSchedulingGroup() > SCHED_GROUP_BACKGROUND
+ && service.mState.getCurProcState() <= PROCESS_STATE_TOP)) {
continue;
}
-
- computeServiceHostOomAdjLSP(cr, service, app, now, topApp, fullUpdate, false, false,
- oomAdjReason, cachedAdj, false, false);
+ connectionConsumer.accept(cr, service);
}
final ProcessProviderRecord ppr = app.mProviders;
@@ -1021,15 +1006,51 @@
ProcessRecord provider = cpc.provider.proc;
if (provider == null || provider == app
|| (provider.mState.getMaxAdj() >= ProcessList.SYSTEM_ADJ
- && provider.mState.getMaxAdj() < FOREGROUND_APP_ADJ)
+ && provider.mState.getMaxAdj() < FOREGROUND_APP_ADJ)
|| (provider.mState.getCurAdj() <= FOREGROUND_APP_ADJ
- && provider.mState.getCurrentSchedulingGroup() > SCHED_GROUP_BACKGROUND
- && provider.mState.getCurProcState() <= PROCESS_STATE_TOP)) {
+ && provider.mState.getCurrentSchedulingGroup() > SCHED_GROUP_BACKGROUND
+ && provider.mState.getCurProcState() <= PROCESS_STATE_TOP)) {
continue;
}
+ connectionConsumer.accept(cpc, provider);
+ }
+ }
- computeProviderHostOomAdjLSP(cpc, provider, app, now, topApp, fullUpdate, false, false,
- oomAdjReason, cachedAdj, false, false);
+ /**
+ * Stream the connections from clients with {@code app} as the host to {@code
+ * connectionConsumer}.
+ */
+ @GuardedBy({"mService", "mProcLock"})
+ private static void forEachClientConnectionLSP(ProcessRecord app,
+ BiConsumer<Connection, ProcessRecord> connectionConsumer) {
+ final ProcessServiceRecord psr = app.mServices;
+
+ for (int i = psr.numberOfRunningServices() - 1; i >= 0; i--) {
+ final ServiceRecord s = psr.getRunningServiceAt(i);
+ final ArrayMap<IBinder, ArrayList<ConnectionRecord>> serviceConnections =
+ s.getConnections();
+ for (int j = serviceConnections.size() - 1; j >= 0; j--) {
+ final ArrayList<ConnectionRecord> clist = serviceConnections.valueAt(j);
+ for (int k = clist.size() - 1; k >= 0; k--) {
+ final ConnectionRecord cr = clist.get(k);
+ final ProcessRecord client;
+ if (app.isSdkSandbox && cr.binding.attributedClient != null) {
+ client = cr.binding.attributedClient;
+ } else {
+ client = cr.binding.client;
+ }
+ connectionConsumer.accept(cr, client);
+ }
+ }
+ }
+
+ final ProcessProviderRecord ppr = app.mProviders;
+ for (int i = ppr.numberOfProviders() - 1; i >= 0; i--) {
+ final ContentProviderRecord cpr = ppr.getProviderAt(i);
+ for (int j = cpr.connections.size() - 1; j >= 0; j--) {
+ final ContentProviderConnection conn = cpr.connections.get(j);
+ connectionConsumer.accept(conn, conn.client);
+ }
}
}
}
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index 89c8994..a1fdd50 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -208,7 +208,7 @@
// Number of levels we have available for different service connection group importance
// levels.
- static final int CACHED_APP_IMPORTANCE_LEVELS = 5;
+ public static final int CACHED_APP_IMPORTANCE_LEVELS = 5;
// The B list of SERVICE_ADJ -- these are the old and decrepit
// services that aren't as shiny and interesting as the ones in the A list.
diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java
index 7009bd0..7356588 100644
--- a/services/core/java/com/android/server/am/ProcessRecord.java
+++ b/services/core/java/com/android/server/am/ProcessRecord.java
@@ -69,10 +69,8 @@
import com.android.server.wm.WindowProcessListener;
import java.io.PrintWriter;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.function.Consumer;
/**
* Full information about a particular process that
@@ -1659,34 +1657,4 @@
&& !mOptRecord.shouldNotFreeze()
&& mState.getCurAdj() >= ProcessList.FREEZER_CUTOFF_ADJ;
}
-
- /**
- * Traverses all client processes and feed them to consumer.
- */
- @GuardedBy("mProcLock")
- void forEachClient(@NonNull Consumer<ProcessRecord> consumer) {
- for (int i = mServices.numberOfRunningServices() - 1; i >= 0; i--) {
- final ServiceRecord s = mServices.getRunningServiceAt(i);
- final ArrayMap<IBinder, ArrayList<ConnectionRecord>> serviceConnections =
- s.getConnections();
- for (int j = serviceConnections.size() - 1; j >= 0; j--) {
- final ArrayList<ConnectionRecord> clist = serviceConnections.valueAt(j);
- for (int k = clist.size() - 1; k >= 0; k--) {
- final ConnectionRecord cr = clist.get(k);
- if (isSdkSandbox && cr.binding.attributedClient != null) {
- consumer.accept(cr.binding.attributedClient);
- } else {
- consumer.accept(cr.binding.client);
- }
- }
- }
- }
- for (int i = mProviders.numberOfProviders() - 1; i >= 0; i--) {
- final ContentProviderRecord cpr = mProviders.getProviderAt(i);
- for (int j = cpr.connections.size() - 1; j >= 0; j--) {
- final ContentProviderConnection conn = cpr.connections.get(j);
- consumer.accept(conn.client);
- }
- }
- }
}
diff --git a/services/core/java/com/android/server/am/ProcessServiceRecord.java b/services/core/java/com/android/server/am/ProcessServiceRecord.java
index 562beaf..3d695bc 100644
--- a/services/core/java/com/android/server/am/ProcessServiceRecord.java
+++ b/services/core/java/com/android/server/am/ProcessServiceRecord.java
@@ -541,7 +541,7 @@
private void removeSdkSandboxConnectionIfNecessary(ConnectionRecord connection) {
final ProcessRecord attributedClient = connection.binding.attributedClient;
if (attributedClient != null && connection.binding.service.isSdkSandbox) {
- if (attributedClient.mServices.mSdkSandboxConnections == null) {
+ if (attributedClient.mServices.mSdkSandboxConnections != null) {
attributedClient.mServices.mSdkSandboxConnections.remove(connection);
}
}
diff --git a/services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java b/services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java
index 1226f0c..872ac40 100644
--- a/services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java
+++ b/services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java
@@ -297,6 +297,10 @@
} else {
updateProcessRecordNodes(Arrays.asList(apps));
if (apps.length == 1) {
+ final ProcessRecord app = apps[0];
+ if (!sService.mProcessList.getLruProcessesLOSP().contains(app)) {
+ sService.mProcessList.getLruProcessesLOSP().add(app);
+ }
sService.mOomAdjuster.updateOomAdjLocked(apps[0], OOM_ADJ_REASON_NONE);
} else {
setProcessesToLru(apps);
@@ -475,7 +479,16 @@
sService.mWakefulness.set(PowerManagerInternal.WAKEFULNESS_AWAKE);
updateOomAdj(app);
- assertProcStates(app, PROCESS_STATE_CACHED_EMPTY, CACHED_APP_MIN_ADJ,
+ final int expectedAdj;
+ if (sService.mConstants.ENABLE_NEW_OOMADJ) {
+ // A cached empty process can be at best a level higher than the min cached adj.
+ expectedAdj = sFirstCachedAdj;
+ } else {
+ // This is wrong but legacy behavior is going to be removed and not worth fixing.
+ expectedAdj = CACHED_APP_MIN_ADJ;
+ }
+
+ assertProcStates(app, PROCESS_STATE_CACHED_EMPTY, expectedAdj,
SCHED_GROUP_BACKGROUND);
}