Merge "Process adj could stay at UNKNOWN_ADJ till next full adj update"

This commit is contained in:
Jing Ji
2019-11-02 01:03:43 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 3 deletions

View File

@@ -410,6 +410,13 @@ public final class OomAdjuster {
mAdjSeq--;
// Update these reachable processes
updateOomAdjLockedInner(oomAdjReason, topApp, processes, uids, false);
} else if (app.getCurRawAdj() == ProcessList.UNKNOWN_ADJ) {
// In case the app goes from non-cached to cached but it doesn't have other reachable
// processes, its adj could be still unknown as of now, assign one.
processes.add(app);
assignCachedAdjIfNecessary(processes);
applyOomAdjLocked(app, false, SystemClock.uptimeMillis(),
SystemClock.elapsedRealtime());
}
mService.mOomAdjProfiler.oomAdjEnded();
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
@@ -490,7 +497,7 @@ public final class OomAdjuster {
}
}
assignCachedAdjIfNecessary();
assignCachedAdjIfNecessary(mProcessList.mLruProcesses);
if (fullUpdate) { // There won't be cycles if we didn't compute clients above.
// Cycle strategy:
@@ -564,8 +571,7 @@ public final class OomAdjuster {
}
}
private void assignCachedAdjIfNecessary() {
ArrayList<ProcessRecord> lruList = mProcessList.mLruProcesses;
private void assignCachedAdjIfNecessary(ArrayList<ProcessRecord> lruList) {
final int numLru = lruList.size();
// First update the OOM adjustment for each of the

View File

@@ -61,6 +61,7 @@ import static com.android.server.am.ProcessList.UNKNOWN_ADJ;
import static com.android.server.am.ProcessList.VISIBLE_APP_ADJ;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.AdditionalAnswers.answer;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
@@ -540,6 +541,21 @@ public class MockingOomAdjusterTests {
SCHED_GROUP_DEFAULT);
}
@SuppressWarnings("GuardedBy")
@Test
public void testUpdateOomAdj_DoOne_NonCachedToCached() {
ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID,
MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, false));
app.cached = false;
app.setCurRawAdj(SERVICE_ADJ);
doReturn(null).when(sService).getTopAppLocked();
sService.mWakefulness = PowerManagerInternal.WAKEFULNESS_AWAKE;
sService.mOomAdjuster.updateOomAdjLocked(app, OomAdjuster.OOM_ADJ_REASON_NONE);
assertTrue(ProcessList.CACHED_APP_MIN_ADJ <= app.setAdj);
assertTrue(ProcessList.CACHED_APP_MAX_ADJ >= app.setAdj);
}
@SuppressWarnings("GuardedBy")
@Test
public void testUpdateOomAdj_DoOne_Service_Started() {