Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87dbb46d authored by Jing Ji's avatar Jing Ji
Browse files

Use the UNKNOWN_ADJ as the cached adj in cycle recomputation

This reverts the behavior introduced in a previous commit 853d509c,
where if a cached app binds to a non-cached app, and this cached app
forms cycles with other cached apps, it might end up bumping
the oom adj score to the non-cached state. So now we'll be using
the UNKNOWN_ADJ. And as we're doing cached oom adj assignment
after that so we won't be running into the unassigned adj problem.

Bug: 286750917
Test: atest MockingOomAdjusterTests
Change-Id: I9284d3d6318dccac1460adae12f24f89bd85b88e
parent 0f07b01f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1009,7 +1009,6 @@ public class OomAdjuster {
            mCacheOomRanker.reRankLruCachedAppsLSP(mProcessList.getLruProcessesLSP(),
                    mProcessList.getLruProcessServiceStartLOSP());
        }
        assignCachedAdjIfNecessary(mProcessList.getLruProcessesLOSP());

        if (computeClients) { // There won't be cycles if we didn't compute clients above.
            // Cycle strategy:
@@ -1034,7 +1033,7 @@ public class OomAdjuster {
                    ProcessRecord app = activeProcesses.get(i);
                    final ProcessStateRecord state = app.mState;
                    if (!app.isKilledByAm() && app.getThread() != null && state.containsCycle()) {
                        if (computeOomAdjLSP(app, state.getCurRawAdj(), topApp, true, now,
                        if (computeOomAdjLSP(app, UNKNOWN_ADJ, topApp, true, now,
                                true, true)) {
                            retryCycles = true;
                        }
@@ -1044,6 +1043,8 @@ public class OomAdjuster {
        }
        mProcessesInCycle.clear();

        assignCachedAdjIfNecessary(mProcessList.getLruProcessesLOSP());

        mNumNonCachedProcs = 0;
        mNumCachedHiddenProcs = 0;

+29 −0
Original line number Diff line number Diff line
@@ -2512,6 +2512,35 @@ public class MockingOomAdjusterTests {
        assertEquals(FOREGROUND_APP_ADJ, app.mState.getSetAdj());
    }

    @SuppressWarnings("GuardedBy")
    @Test
    public void testUpdateOomAdj_DoAll_Side_Cycle() {
        final ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID,
                MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, false));
        final ProcessRecord app2 = spy(makeDefaultProcessRecord(MOCKAPP2_PID, MOCKAPP2_UID,
                MOCKAPP2_PROCESSNAME, MOCKAPP2_PACKAGENAME, false));
        final ProcessRecord app3 = spy(makeDefaultProcessRecord(MOCKAPP3_PID, MOCKAPP3_UID,
                MOCKAPP3_PROCESSNAME, MOCKAPP3_PACKAGENAME, false));
        long now = SystemClock.uptimeMillis();
        ServiceRecord s = bindService(app, app2, null, 0, mock(IBinder.class));
        s.startRequested = true;
        s.lastActivity = now;
        s = bindService(app2, app3, null, 0, mock(IBinder.class));
        s.lastActivity = now;
        s = bindService(app3, app2, null, 0, mock(IBinder.class));
        s.lastActivity = now;

        sService.mWakefulness.set(PowerManagerInternal.WAKEFULNESS_AWAKE);
        sService.mOomAdjuster.mNumServiceProcs = 3;
        updateOomAdj(app, app2, app3);

        assertEquals(SERVICE_ADJ, app.mState.getSetAdj());
        assertTrue(sFirstCachedAdj <= app2.mState.getSetAdj());
        assertTrue(sFirstCachedAdj <= app3.mState.getSetAdj());
        assertTrue(CACHED_APP_MAX_ADJ >= app2.mState.getSetAdj());
        assertTrue(CACHED_APP_MAX_ADJ >= app3.mState.getSetAdj());
    }

    private ProcessRecord makeDefaultProcessRecord(int pid, int uid, String processName,
            String packageName, boolean hasShownUi) {
        long now = SystemClock.uptimeMillis();