Loading services/core/java/com/android/server/am/OomAdjuster.java +18 −3 Original line number Diff line number Diff line Loading @@ -1376,10 +1376,12 @@ public class OomAdjuster { ProcessRecord app = lruList.get(i); final ProcessStateRecord state = app.mState; if (!app.isKilledByAm() && app.getThread() != null) { if (!Flags.fixApplyOomadjOrder()) { // We don't need to apply the update for the process which didn't get computed if (state.getCompletedAdjSeq() == mAdjSeq) { applyOomAdjLSP(app, doingAll, now, nowElapsed, oomAdjReason, true); } } if (app.isPendingFinishAttach()) { // Avoid trimming processes that are still initializing. If they aren't Loading Loading @@ -1480,6 +1482,19 @@ public class OomAdjuster { } } if (Flags.fixApplyOomadjOrder()) { // We need to apply the update starting from the least recently used. // Otherwise, they won't be in the correct LRU order in LMKD. for (int i = 0; i < numLru; i++) { ProcessRecord app = lruList.get(i); // We don't need to apply the update for the process which didn't get computed if (!app.isKilledByAm() && app.getThread() != null && app.mState.getCompletedAdjSeq() == mAdjSeq) { applyOomAdjLSP(app, doingAll, now, nowElapsed, oomAdjReason, true); } } } if (!mProcsToOomAdj.isEmpty()) { mInjector.batchSetOomAdj(mProcsToOomAdj); mProcsToOomAdj.clear(); Loading services/core/java/com/android/server/am/flags.aconfig +8 −0 Original line number Diff line number Diff line Loading @@ -244,6 +244,14 @@ flag { bug: "359912586" } flag { name: "fix_apply_oomadj_order" namespace: "backstage_power" is_fixed_read_only: true description: "Fix the iteration direction of process LRU list when applying oom adj" bug: "378580264" } flag { name: "phantom_processes_fix" namespace: "backstage_power" Loading services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java +28 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,7 @@ import android.os.PowerManagerInternal; import android.os.Process; import android.os.SystemClock; import android.os.UserHandle; import android.platform.test.annotations.EnableFlags; import android.platform.test.annotations.Presubmit; import android.platform.test.flag.junit.SetFlagsRule; import android.util.ArrayMap; Loading Loading @@ -3260,6 +3261,24 @@ public class MockingOomAdjusterTests { "cch-empty"); } @SuppressWarnings("GuardedBy") @Test @EnableFlags(Flags.FLAG_FIX_APPLY_OOMADJ_ORDER) public void testUpdateOomAdj_ApplyOomAdjInCorrectOrder() { final int numberOfApps = 5; final ProcessRecord[] apps = new ProcessRecord[numberOfApps]; for (int i = 0; i < numberOfApps; i++) { apps[i] = spy(makeDefaultProcessRecord(MOCKAPP_PID + i, MOCKAPP_UID + i, MOCKAPP_PROCESSNAME + i, MOCKAPP_PACKAGENAME + i, true)); } updateOomAdj(apps); for (int i = 1; i < numberOfApps; i++) { final int pre = mInjector.mSetOomAdjAppliedAt.get(apps[i - 1].mPid); final int cur = mInjector.mSetOomAdjAppliedAt.get(apps[i].mPid); assertTrue("setOomAdj is called in wrong order", pre < cur); } } private ProcessRecord makeDefaultProcessRecord(int pid, int uid, String processName, String packageName, boolean hasShownUi) { return new ProcessRecordBuilder(pid, uid, processName, packageName).setHasShownUi( Loading Loading @@ -3589,9 +3608,16 @@ public class MockingOomAdjusterTests { long mTimeOffsetMillis = 0; private SparseIntArray mLastSetOomAdj = new SparseIntArray(); // A sequence number that increases every time setOomAdj is called int mLastAppliedAt = 0; // Holds the last sequence number setOomAdj is called for a pid private SparseIntArray mSetOomAdjAppliedAt = new SparseIntArray(); void reset() { mTimeOffsetMillis = 0; mLastSetOomAdj.clear(); mLastAppliedAt = 0; mSetOomAdjAppliedAt.clear(); } void jumpUptimeAheadTo(long uptimeMillis) { Loading @@ -3616,6 +3642,7 @@ public class MockingOomAdjusterTests { final int pid = proc.getPid(); if (pid <= 0) continue; mLastSetOomAdj.put(pid, proc.mState.getCurAdj()); mSetOomAdjAppliedAt.put(pid, mLastAppliedAt++); } } Loading @@ -3623,6 +3650,7 @@ public class MockingOomAdjusterTests { void setOomAdj(int pid, int uid, int adj) { if (pid <= 0) return; mLastSetOomAdj.put(pid, adj); mSetOomAdjAppliedAt.put(pid, mLastAppliedAt++); } @Override Loading Loading
services/core/java/com/android/server/am/OomAdjuster.java +18 −3 Original line number Diff line number Diff line Loading @@ -1376,10 +1376,12 @@ public class OomAdjuster { ProcessRecord app = lruList.get(i); final ProcessStateRecord state = app.mState; if (!app.isKilledByAm() && app.getThread() != null) { if (!Flags.fixApplyOomadjOrder()) { // We don't need to apply the update for the process which didn't get computed if (state.getCompletedAdjSeq() == mAdjSeq) { applyOomAdjLSP(app, doingAll, now, nowElapsed, oomAdjReason, true); } } if (app.isPendingFinishAttach()) { // Avoid trimming processes that are still initializing. If they aren't Loading Loading @@ -1480,6 +1482,19 @@ public class OomAdjuster { } } if (Flags.fixApplyOomadjOrder()) { // We need to apply the update starting from the least recently used. // Otherwise, they won't be in the correct LRU order in LMKD. for (int i = 0; i < numLru; i++) { ProcessRecord app = lruList.get(i); // We don't need to apply the update for the process which didn't get computed if (!app.isKilledByAm() && app.getThread() != null && app.mState.getCompletedAdjSeq() == mAdjSeq) { applyOomAdjLSP(app, doingAll, now, nowElapsed, oomAdjReason, true); } } } if (!mProcsToOomAdj.isEmpty()) { mInjector.batchSetOomAdj(mProcsToOomAdj); mProcsToOomAdj.clear(); Loading
services/core/java/com/android/server/am/flags.aconfig +8 −0 Original line number Diff line number Diff line Loading @@ -244,6 +244,14 @@ flag { bug: "359912586" } flag { name: "fix_apply_oomadj_order" namespace: "backstage_power" is_fixed_read_only: true description: "Fix the iteration direction of process LRU list when applying oom adj" bug: "378580264" } flag { name: "phantom_processes_fix" namespace: "backstage_power" Loading
services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java +28 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,7 @@ import android.os.PowerManagerInternal; import android.os.Process; import android.os.SystemClock; import android.os.UserHandle; import android.platform.test.annotations.EnableFlags; import android.platform.test.annotations.Presubmit; import android.platform.test.flag.junit.SetFlagsRule; import android.util.ArrayMap; Loading Loading @@ -3260,6 +3261,24 @@ public class MockingOomAdjusterTests { "cch-empty"); } @SuppressWarnings("GuardedBy") @Test @EnableFlags(Flags.FLAG_FIX_APPLY_OOMADJ_ORDER) public void testUpdateOomAdj_ApplyOomAdjInCorrectOrder() { final int numberOfApps = 5; final ProcessRecord[] apps = new ProcessRecord[numberOfApps]; for (int i = 0; i < numberOfApps; i++) { apps[i] = spy(makeDefaultProcessRecord(MOCKAPP_PID + i, MOCKAPP_UID + i, MOCKAPP_PROCESSNAME + i, MOCKAPP_PACKAGENAME + i, true)); } updateOomAdj(apps); for (int i = 1; i < numberOfApps; i++) { final int pre = mInjector.mSetOomAdjAppliedAt.get(apps[i - 1].mPid); final int cur = mInjector.mSetOomAdjAppliedAt.get(apps[i].mPid); assertTrue("setOomAdj is called in wrong order", pre < cur); } } private ProcessRecord makeDefaultProcessRecord(int pid, int uid, String processName, String packageName, boolean hasShownUi) { return new ProcessRecordBuilder(pid, uid, processName, packageName).setHasShownUi( Loading Loading @@ -3589,9 +3608,16 @@ public class MockingOomAdjusterTests { long mTimeOffsetMillis = 0; private SparseIntArray mLastSetOomAdj = new SparseIntArray(); // A sequence number that increases every time setOomAdj is called int mLastAppliedAt = 0; // Holds the last sequence number setOomAdj is called for a pid private SparseIntArray mSetOomAdjAppliedAt = new SparseIntArray(); void reset() { mTimeOffsetMillis = 0; mLastSetOomAdj.clear(); mLastAppliedAt = 0; mSetOomAdjAppliedAt.clear(); } void jumpUptimeAheadTo(long uptimeMillis) { Loading @@ -3616,6 +3642,7 @@ public class MockingOomAdjusterTests { final int pid = proc.getPid(); if (pid <= 0) continue; mLastSetOomAdj.put(pid, proc.mState.getCurAdj()); mSetOomAdjAppliedAt.put(pid, mLastAppliedAt++); } } Loading @@ -3623,6 +3650,7 @@ public class MockingOomAdjusterTests { void setOomAdj(int pid, int uid, int adj) { if (pid <= 0) return; mLastSetOomAdj.put(pid, adj); mSetOomAdjAppliedAt.put(pid, mLastAppliedAt++); } @Override Loading