Process adj could stay at UNKNOWN_ADJ till next full adj update
Fix an issue that a non-cached process goes to cached state, but there is no other connections to this app, its adj value could be UNKNOWN_ADJ, till the next full adj update occurs. Bug: 135941673 Test: atest MockingOomAdjusterTests Change-Id: I397b26c0b4c2b84a8c418cc21f6e0c85950e39e7
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user