Loading services/core/java/com/android/server/am/ActivityManagerConstants.java +0 −16 Original line number Diff line number Diff line Loading @@ -163,7 +163,6 @@ final class ActivityManagerConstants extends ContentObserver { static final String KEY_USE_TIERED_CACHED_ADJ = "use_tiered_cached_adj"; static final String KEY_TIERED_CACHED_ADJ_DECAY_TIME = "tiered_cached_adj_decay_time"; static final String KEY_USE_MODERN_TRIM = "use_modern_trim"; /** * Whether or not to enable the new oom adjuster implementation. Loading Loading @@ -239,8 +238,6 @@ final class ActivityManagerConstants extends ContentObserver { private static final boolean DEFAULT_USE_TIERED_CACHED_ADJ = false; private static final long DEFAULT_TIERED_CACHED_ADJ_DECAY_TIME = 60 * 1000; private static final boolean DEFAULT_USE_MODERN_TRIM = true; /** * The default value to {@link #KEY_ENABLE_NEW_OOMADJ}. */ Loading Loading @@ -1136,9 +1133,6 @@ final class ActivityManagerConstants extends ContentObserver { /** @see #KEY_TIERED_CACHED_ADJ_DECAY_TIME */ public long TIERED_CACHED_ADJ_DECAY_TIME = DEFAULT_TIERED_CACHED_ADJ_DECAY_TIME; /** @see #KEY_USE_MODERN_TRIM */ public boolean USE_MODERN_TRIM = DEFAULT_USE_MODERN_TRIM; /** @see #KEY_ENABLE_NEW_OOMADJ */ public boolean ENABLE_NEW_OOMADJ = DEFAULT_ENABLE_NEW_OOM_ADJ; Loading Loading @@ -1343,9 +1337,6 @@ final class ActivityManagerConstants extends ContentObserver { case KEY_TIERED_CACHED_ADJ_DECAY_TIME: updateUseTieredCachedAdj(); break; case KEY_USE_MODERN_TRIM: updateUseModernTrim(); break; case KEY_DISABLE_APP_PROFILER_PSS_PROFILING: updateDisableAppProfilerPssProfiling(); break; Loading Loading @@ -2233,13 +2224,6 @@ final class ActivityManagerConstants extends ContentObserver { DEFAULT_TIERED_CACHED_ADJ_DECAY_TIME); } private void updateUseModernTrim() { USE_MODERN_TRIM = DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_USE_MODERN_TRIM, DEFAULT_USE_MODERN_TRIM); } private void updateEnableNewOomAdj() { ENABLE_NEW_OOMADJ = DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT, Loading services/core/java/com/android/server/am/AppProfiler.java +27 −104 Original line number Diff line number Diff line Loading @@ -1357,7 +1357,7 @@ public class AppProfiler { } @GuardedBy({"mService", "mProcLock"}) boolean updateLowMemStateLSP(int numCached, int numEmpty, int numTrimming, long now) { void updateLowMemStateLSP(int numCached, int numEmpty, int numTrimming, long now) { int memFactor; if (mLowMemDetector != null && mLowMemDetector.isAvailable()) { memFactor = mLowMemDetector.getMemFactor(); Loading Loading @@ -1422,10 +1422,11 @@ public class AppProfiler { mLastMemoryLevel = memFactor; mLastNumProcesses = mService.mProcessList.getLruSizeLOSP(); if (mService.mConstants.USE_MODERN_TRIM) { // Modern trim is not sent based on lowmem state // Dispatch UI_HIDDEN to processes that need it mService.mProcessList.forEachLruProcessesLOSP(true, app -> { mService.mProcessList.forEachLruProcessesLOSP( true, app -> { final ProcessProfileRecord profile = app.mProfile; final IApplicationThread thread; final ProcessStateRecord state = app.mState; Loading @@ -1434,14 +1435,17 @@ public class AppProfiler { } int procState = app.mState.getCurProcState(); if (((procState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND && procState < ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) || app.mState.isSystemNoUi()) && app.mProfile.hasPendingUiClean()) { && procState < ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) || app.mState.isSystemNoUi()) && app.mProfile.hasPendingUiClean()) { // If this application is now in the background and it // had done UI, then give it the special trim level to // have it free UI resources. if ((thread = app.getThread()) != null) { try { thread.scheduleTrimMemory(ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN); thread.scheduleTrimMemory( ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN); app.mProfile.setPendingUiClean(false); } catch (RemoteException e) { Loading @@ -1449,87 +1453,6 @@ public class AppProfiler { } } }); return false; } if (memFactor != ADJ_MEM_FACTOR_NORMAL) { if (mLowRamStartTime == 0) { mLowRamStartTime = now; } int fgTrimLevel; switch (memFactor) { case ADJ_MEM_FACTOR_CRITICAL: fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL; break; case ADJ_MEM_FACTOR_LOW: fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW; break; default: fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE; break; } int factor = numTrimming / 3; int minFactor = 2; if (mHasHomeProcess) minFactor++; if (mHasPreviousProcess) minFactor++; if (factor < minFactor) factor = minFactor; final int actualFactor = factor; final int[] step = {0}; final int[] curLevel = {ComponentCallbacks2.TRIM_MEMORY_COMPLETE}; mService.mProcessList.forEachLruProcessesLOSP(true, app -> { final ProcessProfileRecord profile = app.mProfile; final int trimMemoryLevel = profile.getTrimMemoryLevel(); final ProcessStateRecord state = app.mState; final int curProcState = state.getCurProcState(); IApplicationThread thread; if (allChanged || state.hasProcStateChanged()) { mService.setProcessTrackerStateLOSP(app, trackerMemFactor); state.setProcStateChanged(false); } trimMemoryUiHiddenIfNecessaryLSP(app); if (curProcState >= ActivityManager.PROCESS_STATE_HOME && !app.isKilledByAm()) { scheduleTrimMemoryLSP(app, curLevel[0], "Trimming memory of "); profile.setTrimMemoryLevel(curLevel[0]); step[0]++; if (step[0] >= actualFactor) { step[0] = 0; switch (curLevel[0]) { case ComponentCallbacks2.TRIM_MEMORY_COMPLETE: curLevel[0] = ComponentCallbacks2.TRIM_MEMORY_MODERATE; break; case ComponentCallbacks2.TRIM_MEMORY_MODERATE: curLevel[0] = ComponentCallbacks2.TRIM_MEMORY_BACKGROUND; break; } } } else if (curProcState == ActivityManager.PROCESS_STATE_HEAVY_WEIGHT && !app.isKilledByAm()) { scheduleTrimMemoryLSP(app, ComponentCallbacks2.TRIM_MEMORY_BACKGROUND, "Trimming memory of heavy-weight "); profile.setTrimMemoryLevel(ComponentCallbacks2.TRIM_MEMORY_BACKGROUND); } else { scheduleTrimMemoryLSP(app, fgTrimLevel, "Trimming memory of fg "); profile.setTrimMemoryLevel(fgTrimLevel); } }); } else { if (mLowRamStartTime != 0) { mLowRamTimeSinceLastIdle += now - mLowRamStartTime; mLowRamStartTime = 0; } mService.mProcessList.forEachLruProcessesLOSP(true, app -> { final ProcessProfileRecord profile = app.mProfile; final IApplicationThread thread; final ProcessStateRecord state = app.mState; if (allChanged || state.hasProcStateChanged()) { mService.setProcessTrackerStateLOSP(app, trackerMemFactor); state.setProcStateChanged(false); } trimMemoryUiHiddenIfNecessaryLSP(app); profile.setTrimMemoryLevel(0); }); } return allChanged; } @GuardedBy({"mService", "mProcLock"}) Loading services/core/java/com/android/server/am/CachedAppOptimizer.java +1 −2 Original line number Diff line number Diff line Loading @@ -1461,8 +1461,7 @@ public final class CachedAppOptimizer { return; } if (mAm.mConstants.USE_MODERN_TRIM && app.mState.getSetAdj() >= ProcessList.CACHED_APP_MIN_ADJ) { if (app.mState.getSetAdj() >= ProcessList.CACHED_APP_MIN_ADJ) { final IApplicationThread thread = app.getThread(); if (thread != null) { try { Loading services/core/java/com/android/server/am/OomAdjuster.java +3 −8 Original line number Diff line number Diff line Loading @@ -1090,7 +1090,7 @@ public class OomAdjuster { mNumNonCachedProcs = 0; mNumCachedHiddenProcs = 0; final boolean allChanged = updateAndTrimProcessLSP(now, nowElapsed, oldTime, activeUids, updateAndTrimProcessLSP(now, nowElapsed, oldTime, activeUids, oomAdjReason, doingAll); mNumServiceProcs = mNewNumServiceProcs; Loading @@ -1100,11 +1100,6 @@ public class OomAdjuster { mService.mAtmInternal.scheduleDestroyAllActivities("always-finish"); } if (allChanged) { mService.mAppProfiler.requestPssAllProcsLPr(now, false, mService.mProcessStats.isMemFactorLowered()); } updateUidsLSP(activeUids, nowElapsed); synchronized (mService.mProcessStats.mLock) { Loading Loading @@ -1300,7 +1295,7 @@ public class OomAdjuster { } @GuardedBy({"mService", "mProcLock"}) private boolean updateAndTrimProcessLSP(final long now, final long nowElapsed, private void updateAndTrimProcessLSP(final long now, final long nowElapsed, final long oldTime, final ActiveUids activeUids, @OomAdjReason int oomAdjReason, boolean doingAll) { ArrayList<ProcessRecord> lruList = mProcessList.getLruProcessesLOSP(); Loading Loading @@ -1450,7 +1445,7 @@ public class OomAdjuster { mLastFreeSwapPercent = freeSwapPercent; return mService.mAppProfiler.updateLowMemStateLSP(numCached, numEmpty, numTrimming, now); mService.mAppProfiler.updateLowMemStateLSP(numCached, numEmpty, numTrimming, now); } @GuardedBy({"mService", "mProcLock"}) Loading services/tests/mockingservicestests/src/com/android/server/am/ServiceBindingOomAdjPolicyTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -186,7 +186,7 @@ public final class ServiceBindingOomAdjPolicyTest { doReturn(true).when(mAms.mOomAdjuster.mCachedAppOptimizer).useFreezer(); doNothing().when(mAms.mOomAdjuster.mCachedAppOptimizer).freezeAppAsyncAtEarliestLSP( any()); doReturn(false).when(mAms.mAppProfiler).updateLowMemStateLSP(anyInt(), anyInt(), doNothing().when(mAms.mAppProfiler).updateLowMemStateLSP(anyInt(), anyInt(), anyInt(), anyLong()); mCurrentCallingUid = TEST_APP1_UID; Loading Loading
services/core/java/com/android/server/am/ActivityManagerConstants.java +0 −16 Original line number Diff line number Diff line Loading @@ -163,7 +163,6 @@ final class ActivityManagerConstants extends ContentObserver { static final String KEY_USE_TIERED_CACHED_ADJ = "use_tiered_cached_adj"; static final String KEY_TIERED_CACHED_ADJ_DECAY_TIME = "tiered_cached_adj_decay_time"; static final String KEY_USE_MODERN_TRIM = "use_modern_trim"; /** * Whether or not to enable the new oom adjuster implementation. Loading Loading @@ -239,8 +238,6 @@ final class ActivityManagerConstants extends ContentObserver { private static final boolean DEFAULT_USE_TIERED_CACHED_ADJ = false; private static final long DEFAULT_TIERED_CACHED_ADJ_DECAY_TIME = 60 * 1000; private static final boolean DEFAULT_USE_MODERN_TRIM = true; /** * The default value to {@link #KEY_ENABLE_NEW_OOMADJ}. */ Loading Loading @@ -1136,9 +1133,6 @@ final class ActivityManagerConstants extends ContentObserver { /** @see #KEY_TIERED_CACHED_ADJ_DECAY_TIME */ public long TIERED_CACHED_ADJ_DECAY_TIME = DEFAULT_TIERED_CACHED_ADJ_DECAY_TIME; /** @see #KEY_USE_MODERN_TRIM */ public boolean USE_MODERN_TRIM = DEFAULT_USE_MODERN_TRIM; /** @see #KEY_ENABLE_NEW_OOMADJ */ public boolean ENABLE_NEW_OOMADJ = DEFAULT_ENABLE_NEW_OOM_ADJ; Loading Loading @@ -1343,9 +1337,6 @@ final class ActivityManagerConstants extends ContentObserver { case KEY_TIERED_CACHED_ADJ_DECAY_TIME: updateUseTieredCachedAdj(); break; case KEY_USE_MODERN_TRIM: updateUseModernTrim(); break; case KEY_DISABLE_APP_PROFILER_PSS_PROFILING: updateDisableAppProfilerPssProfiling(); break; Loading Loading @@ -2233,13 +2224,6 @@ final class ActivityManagerConstants extends ContentObserver { DEFAULT_TIERED_CACHED_ADJ_DECAY_TIME); } private void updateUseModernTrim() { USE_MODERN_TRIM = DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_USE_MODERN_TRIM, DEFAULT_USE_MODERN_TRIM); } private void updateEnableNewOomAdj() { ENABLE_NEW_OOMADJ = DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT, Loading
services/core/java/com/android/server/am/AppProfiler.java +27 −104 Original line number Diff line number Diff line Loading @@ -1357,7 +1357,7 @@ public class AppProfiler { } @GuardedBy({"mService", "mProcLock"}) boolean updateLowMemStateLSP(int numCached, int numEmpty, int numTrimming, long now) { void updateLowMemStateLSP(int numCached, int numEmpty, int numTrimming, long now) { int memFactor; if (mLowMemDetector != null && mLowMemDetector.isAvailable()) { memFactor = mLowMemDetector.getMemFactor(); Loading Loading @@ -1422,10 +1422,11 @@ public class AppProfiler { mLastMemoryLevel = memFactor; mLastNumProcesses = mService.mProcessList.getLruSizeLOSP(); if (mService.mConstants.USE_MODERN_TRIM) { // Modern trim is not sent based on lowmem state // Dispatch UI_HIDDEN to processes that need it mService.mProcessList.forEachLruProcessesLOSP(true, app -> { mService.mProcessList.forEachLruProcessesLOSP( true, app -> { final ProcessProfileRecord profile = app.mProfile; final IApplicationThread thread; final ProcessStateRecord state = app.mState; Loading @@ -1434,14 +1435,17 @@ public class AppProfiler { } int procState = app.mState.getCurProcState(); if (((procState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND && procState < ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) || app.mState.isSystemNoUi()) && app.mProfile.hasPendingUiClean()) { && procState < ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) || app.mState.isSystemNoUi()) && app.mProfile.hasPendingUiClean()) { // If this application is now in the background and it // had done UI, then give it the special trim level to // have it free UI resources. if ((thread = app.getThread()) != null) { try { thread.scheduleTrimMemory(ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN); thread.scheduleTrimMemory( ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN); app.mProfile.setPendingUiClean(false); } catch (RemoteException e) { Loading @@ -1449,87 +1453,6 @@ public class AppProfiler { } } }); return false; } if (memFactor != ADJ_MEM_FACTOR_NORMAL) { if (mLowRamStartTime == 0) { mLowRamStartTime = now; } int fgTrimLevel; switch (memFactor) { case ADJ_MEM_FACTOR_CRITICAL: fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL; break; case ADJ_MEM_FACTOR_LOW: fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW; break; default: fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE; break; } int factor = numTrimming / 3; int minFactor = 2; if (mHasHomeProcess) minFactor++; if (mHasPreviousProcess) minFactor++; if (factor < minFactor) factor = minFactor; final int actualFactor = factor; final int[] step = {0}; final int[] curLevel = {ComponentCallbacks2.TRIM_MEMORY_COMPLETE}; mService.mProcessList.forEachLruProcessesLOSP(true, app -> { final ProcessProfileRecord profile = app.mProfile; final int trimMemoryLevel = profile.getTrimMemoryLevel(); final ProcessStateRecord state = app.mState; final int curProcState = state.getCurProcState(); IApplicationThread thread; if (allChanged || state.hasProcStateChanged()) { mService.setProcessTrackerStateLOSP(app, trackerMemFactor); state.setProcStateChanged(false); } trimMemoryUiHiddenIfNecessaryLSP(app); if (curProcState >= ActivityManager.PROCESS_STATE_HOME && !app.isKilledByAm()) { scheduleTrimMemoryLSP(app, curLevel[0], "Trimming memory of "); profile.setTrimMemoryLevel(curLevel[0]); step[0]++; if (step[0] >= actualFactor) { step[0] = 0; switch (curLevel[0]) { case ComponentCallbacks2.TRIM_MEMORY_COMPLETE: curLevel[0] = ComponentCallbacks2.TRIM_MEMORY_MODERATE; break; case ComponentCallbacks2.TRIM_MEMORY_MODERATE: curLevel[0] = ComponentCallbacks2.TRIM_MEMORY_BACKGROUND; break; } } } else if (curProcState == ActivityManager.PROCESS_STATE_HEAVY_WEIGHT && !app.isKilledByAm()) { scheduleTrimMemoryLSP(app, ComponentCallbacks2.TRIM_MEMORY_BACKGROUND, "Trimming memory of heavy-weight "); profile.setTrimMemoryLevel(ComponentCallbacks2.TRIM_MEMORY_BACKGROUND); } else { scheduleTrimMemoryLSP(app, fgTrimLevel, "Trimming memory of fg "); profile.setTrimMemoryLevel(fgTrimLevel); } }); } else { if (mLowRamStartTime != 0) { mLowRamTimeSinceLastIdle += now - mLowRamStartTime; mLowRamStartTime = 0; } mService.mProcessList.forEachLruProcessesLOSP(true, app -> { final ProcessProfileRecord profile = app.mProfile; final IApplicationThread thread; final ProcessStateRecord state = app.mState; if (allChanged || state.hasProcStateChanged()) { mService.setProcessTrackerStateLOSP(app, trackerMemFactor); state.setProcStateChanged(false); } trimMemoryUiHiddenIfNecessaryLSP(app); profile.setTrimMemoryLevel(0); }); } return allChanged; } @GuardedBy({"mService", "mProcLock"}) Loading
services/core/java/com/android/server/am/CachedAppOptimizer.java +1 −2 Original line number Diff line number Diff line Loading @@ -1461,8 +1461,7 @@ public final class CachedAppOptimizer { return; } if (mAm.mConstants.USE_MODERN_TRIM && app.mState.getSetAdj() >= ProcessList.CACHED_APP_MIN_ADJ) { if (app.mState.getSetAdj() >= ProcessList.CACHED_APP_MIN_ADJ) { final IApplicationThread thread = app.getThread(); if (thread != null) { try { Loading
services/core/java/com/android/server/am/OomAdjuster.java +3 −8 Original line number Diff line number Diff line Loading @@ -1090,7 +1090,7 @@ public class OomAdjuster { mNumNonCachedProcs = 0; mNumCachedHiddenProcs = 0; final boolean allChanged = updateAndTrimProcessLSP(now, nowElapsed, oldTime, activeUids, updateAndTrimProcessLSP(now, nowElapsed, oldTime, activeUids, oomAdjReason, doingAll); mNumServiceProcs = mNewNumServiceProcs; Loading @@ -1100,11 +1100,6 @@ public class OomAdjuster { mService.mAtmInternal.scheduleDestroyAllActivities("always-finish"); } if (allChanged) { mService.mAppProfiler.requestPssAllProcsLPr(now, false, mService.mProcessStats.isMemFactorLowered()); } updateUidsLSP(activeUids, nowElapsed); synchronized (mService.mProcessStats.mLock) { Loading Loading @@ -1300,7 +1295,7 @@ public class OomAdjuster { } @GuardedBy({"mService", "mProcLock"}) private boolean updateAndTrimProcessLSP(final long now, final long nowElapsed, private void updateAndTrimProcessLSP(final long now, final long nowElapsed, final long oldTime, final ActiveUids activeUids, @OomAdjReason int oomAdjReason, boolean doingAll) { ArrayList<ProcessRecord> lruList = mProcessList.getLruProcessesLOSP(); Loading Loading @@ -1450,7 +1445,7 @@ public class OomAdjuster { mLastFreeSwapPercent = freeSwapPercent; return mService.mAppProfiler.updateLowMemStateLSP(numCached, numEmpty, numTrimming, now); mService.mAppProfiler.updateLowMemStateLSP(numCached, numEmpty, numTrimming, now); } @GuardedBy({"mService", "mProcLock"}) Loading
services/tests/mockingservicestests/src/com/android/server/am/ServiceBindingOomAdjPolicyTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -186,7 +186,7 @@ public final class ServiceBindingOomAdjPolicyTest { doReturn(true).when(mAms.mOomAdjuster.mCachedAppOptimizer).useFreezer(); doNothing().when(mAms.mOomAdjuster.mCachedAppOptimizer).freezeAppAsyncAtEarliestLSP( any()); doReturn(false).when(mAms.mAppProfiler).updateLowMemStateLSP(anyInt(), anyInt(), doNothing().when(mAms.mAppProfiler).updateLowMemStateLSP(anyInt(), anyInt(), anyInt(), anyLong()); mCurrentCallingUid = TEST_APP1_UID; Loading