Loading core/proto/android/server/activitymanagerservice.proto +1 −1 Original line number Diff line number Diff line Loading @@ -764,7 +764,7 @@ message ActivityManagerServiceDumpProcessesProto { optional int32 last_memory_level = 56; optional int32 last_num_processes = 57; optional .android.util.Duration last_idle_time = 58; optional int64 low_ram_since_last_idle_ms = 59; optional int64 low_ram_since_last_idle_ms = 59 [deprecated=true]; } message ActiveInstrumentationProto { Loading services/core/java/com/android/server/am/ActivityManagerService.java +1 −78 Original line number Diff line number Diff line Loading @@ -116,7 +116,6 @@ import static android.os.Process.ZYGOTE_POLICY_FLAG_EMPTY; import static android.os.Process.ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE; import static android.os.Process.ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS; import static android.os.Process.ZYGOTE_PROCESS; import static android.os.Process.getTotalMemory; import static android.os.Process.isThreadInProcess; import static android.os.Process.killProcess; import static android.os.Process.killProcessGroup; Loading Loading @@ -611,9 +610,6 @@ public class ActivityManagerService extends IActivityManager.Stub // If set, we will push process association information in to procstats. static final boolean TRACK_PROCSTATS_ASSOCIATIONS = true; // The minimum memory growth threshold (in KB) for low RAM devices. private static final int MINIMUM_MEMORY_GROWTH_THRESHOLD = 10 * 1000; // 10 MB /** * The number of binder proxies we need to have before we start dumping debug info * and kill the offenders. Loading Loading @@ -8871,31 +8867,13 @@ public class ActivityManagerService extends IActivityManager.Stub mOomAdjuster.mCachedAppOptimizer.compactAllSystem(); } final long lowRamSinceLastIdle = mAppProfiler.getLowRamTimeSinceIdleLPr(now); mLastIdleTime = now; mAppProfiler.updateLowRamTimestampLPr(now); StringBuilder sb = new StringBuilder(128); sb.append("Idle maintenance over "); TimeUtils.formatDuration(timeSinceLastIdle, sb); sb.append(" low RAM for "); TimeUtils.formatDuration(lowRamSinceLastIdle, sb); Slog.i(TAG, sb.toString()); // If at least 1/3 of our time since the last idle period has been spent // with RAM low, then we want to kill processes. boolean doKilling = lowRamSinceLastIdle > (timeSinceLastIdle/3); // If the processes' memory has increased by more than 1% of the total memory, // or 10 MB, whichever is greater, then the processes' are eligible to be killed. final long totalMemoryInKb = getTotalMemory() / 1000; // This threshold should be applicable to both PSS and RSS because the value is absolute // and represents an increase in process memory relative to its own previous state. // // TODO(b/296454553): Tune this value during the flag rollout process if more processes // seem to be getting killed than before. final long memoryGrowthThreshold = Math.max(totalMemoryInKb / 100, MINIMUM_MEMORY_GROWTH_THRESHOLD); mProcessList.forEachLruProcessesLOSP(false, proc -> { if (proc.getThread() == null) { return; Loading @@ -8903,59 +8881,9 @@ public class ActivityManagerService extends IActivityManager.Stub final ProcessProfileRecord pr = proc.mProfile; final ProcessStateRecord state = proc.mState; final int setProcState = state.getSetProcState(); if (state.isNotCachedSinceIdle()) { if (setProcState >= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE && setProcState <= ActivityManager.PROCESS_STATE_SERVICE) { final long initialIdlePssOrRss, lastPssOrRss, lastSwapPss; synchronized (mAppProfiler.mProfilerLock) { initialIdlePssOrRss = pr.getInitialIdlePssOrRss(); lastPssOrRss = mAppProfiler.isProfilingPss() ? pr.getLastPss() : pr.getLastRss(); lastSwapPss = pr.getLastSwapPss(); } if (doKilling && initialIdlePssOrRss != 0 && lastPssOrRss > (initialIdlePssOrRss * 3 / 2) && lastPssOrRss > (initialIdlePssOrRss + memoryGrowthThreshold)) { final StringBuilder sb2 = new StringBuilder(128); sb2.append("Kill"); sb2.append(proc.processName); if (mAppProfiler.isProfilingPss()) { sb2.append(" in idle maint: pss="); } else { sb2.append(" in idle maint: rss="); } sb2.append(lastPssOrRss); if (mAppProfiler.isProfilingPss()) { sb2.append(", swapPss="); sb2.append(lastSwapPss); sb2.append(", initialPss="); } else { sb2.append(", initialRss="); } sb2.append(initialIdlePssOrRss); sb2.append(", period="); TimeUtils.formatDuration(timeSinceLastIdle, sb2); sb2.append(", lowRamPeriod="); TimeUtils.formatDuration(lowRamSinceLastIdle, sb2); Slog.wtfQuiet(TAG, sb2.toString()); mHandler.post(() -> { synchronized (ActivityManagerService.this) { proc.killLocked(mAppProfiler.isProfilingPss() ? "idle maint (pss " : "idle maint (rss " + lastPssOrRss + " from " + initialIdlePssOrRss + ")", ApplicationExitInfo.REASON_OTHER, ApplicationExitInfo.SUBREASON_MEMORY_PRESSURE, true); } }); } } } else if (setProcState < ActivityManager.PROCESS_STATE_HOME if (setProcState < ActivityManager.PROCESS_STATE_HOME && setProcState >= ActivityManager.PROCESS_STATE_PERSISTENT) { state.setNotCachedSinceIdle(true); synchronized (mAppProfiler.mProfilerLock) { pr.setInitialIdlePssOrRss(0); mAppProfiler.updateNextPssTimeLPf( state.getSetProcState(), proc.mProfile, now, true); } Loading Loading @@ -11509,9 +11437,6 @@ public class ActivityManagerService extends IActivityManager.Stub long now = SystemClock.uptimeMillis(); pw.print(" mLastIdleTime="); TimeUtils.formatDuration(now, mLastIdleTime, pw); pw.print(" mLowRamSinceLastIdle="); TimeUtils.formatDuration( mAppProfiler.getLowRamTimeSinceIdleLPr(now), pw); pw.println(); pw.println(); Loading Loading @@ -11674,8 +11599,6 @@ public class ActivityManagerService extends IActivityManager.Stub mAppProfiler.writeMemoryLevelsToProtoLocked(proto); long now = SystemClock.uptimeMillis(); ProtoUtils.toDuration(proto, ActivityManagerServiceDumpProcessesProto.LAST_IDLE_TIME, mLastIdleTime, now); proto.write(ActivityManagerServiceDumpProcessesProto.LOW_RAM_SINCE_LAST_IDLE_MS, mAppProfiler.getLowRamTimeSinceIdleLPr(now)); } } Loading services/core/java/com/android/server/am/AppProfiler.java +0 −31 Original line number Diff line number Diff line Loading @@ -245,18 +245,6 @@ public class AppProfiler { @GuardedBy("mService") private int mLastNumProcesses; /** * Total time spent with RAM that has been added in the past since the last idle time. */ @GuardedBy("mProcLock") private long mLowRamTimeSinceLastIdle = 0; /** * If RAM is currently low, when that horrible situation started. */ @GuardedBy("mProcLock") private long mLowRamStartTime = 0; /** * Last time we report a memory usage. */ Loading Loading @@ -919,9 +907,6 @@ public class AppProfiler { + " lastPss=" + profile.getLastPss() + " state=" + ProcessList.makeProcStateString(procState)); } if (profile.getInitialIdlePssOrRss() == 0) { profile.setInitialIdlePssOrRss(pss); } profile.setLastPss(pss); profile.setLastSwapPss(swapPss); if (procState >= ActivityManager.PROCESS_STATE_HOME) { Loading Loading @@ -986,9 +971,6 @@ public class AppProfiler { + " lastRss=" + profile.getLastRss() + " state=" + ProcessList.makeProcStateString(procState)); } if (profile.getInitialIdlePssOrRss() == 0) { profile.setInitialIdlePssOrRss(rss); } profile.setLastRss(rss); if (procState >= ActivityManager.PROCESS_STATE_HOME) { profile.setLastCachedRss(rss); Loading Loading @@ -1334,14 +1316,6 @@ public class AppProfiler { return mLastMemoryLevel <= ADJ_MEM_FACTOR_NORMAL; } @GuardedBy("mProcLock") void updateLowRamTimestampLPr(long now) { mLowRamTimeSinceLastIdle = 0; if (mLowRamStartTime != 0) { mLowRamStartTime = now; } } @GuardedBy("mService") void setAllowLowerMemLevelLocked(boolean allowLowerMemLevel) { mAllowLowerMemLevel = allowLowerMemLevel; Loading Loading @@ -1482,11 +1456,6 @@ public class AppProfiler { } } @GuardedBy("mProcLock") long getLowRamTimeSinceIdleLPr(long now) { return mLowRamTimeSinceLastIdle + (mLowRamStartTime > 0 ? (now - mLowRamStartTime) : 0); } /** * Ask a given process to GC right now. */ Loading services/core/java/com/android/server/am/OomAdjuster.java +0 −3 Original line number Diff line number Diff line Loading @@ -2201,9 +2201,6 @@ public abstract class OomAdjuster { maybeUpdateLastTopTime(state, now); state.setSetProcState(state.getCurProcState()); if (state.getSetProcState() >= ActivityManager.PROCESS_STATE_HOME) { state.setNotCachedSinceIdle(false); } if (!doingAll) { synchronized (mService.mProcessStats.mLock) { mService.setProcessTrackerStateLOSP(app, Loading services/core/java/com/android/server/am/ProcessProfileRecord.java +0 −16 Original line number Diff line number Diff line Loading @@ -73,12 +73,6 @@ final class ProcessProfileRecord { @GuardedBy("mProfilerLock") private long mNextPssTime; /** * Initial memory pss of process for idle maintenance. */ @GuardedBy("mProfilerLock") private long mInitialIdlePssOrRss; /** * Last computed memory pss. */ Loading Loading @@ -355,16 +349,6 @@ final class ProcessProfileRecord { mNextPssTime = nextPssTime; } @GuardedBy("mProfilerLock") long getInitialIdlePssOrRss() { return mInitialIdlePssOrRss; } @GuardedBy("mProfilerLock") void setInitialIdlePssOrRss(long initialIdlePssOrRss) { mInitialIdlePssOrRss = initialIdlePssOrRss; } @GuardedBy("mProfilerLock") long getLastPss() { return mLastPss; Loading Loading
core/proto/android/server/activitymanagerservice.proto +1 −1 Original line number Diff line number Diff line Loading @@ -764,7 +764,7 @@ message ActivityManagerServiceDumpProcessesProto { optional int32 last_memory_level = 56; optional int32 last_num_processes = 57; optional .android.util.Duration last_idle_time = 58; optional int64 low_ram_since_last_idle_ms = 59; optional int64 low_ram_since_last_idle_ms = 59 [deprecated=true]; } message ActiveInstrumentationProto { Loading
services/core/java/com/android/server/am/ActivityManagerService.java +1 −78 Original line number Diff line number Diff line Loading @@ -116,7 +116,6 @@ import static android.os.Process.ZYGOTE_POLICY_FLAG_EMPTY; import static android.os.Process.ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE; import static android.os.Process.ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS; import static android.os.Process.ZYGOTE_PROCESS; import static android.os.Process.getTotalMemory; import static android.os.Process.isThreadInProcess; import static android.os.Process.killProcess; import static android.os.Process.killProcessGroup; Loading Loading @@ -611,9 +610,6 @@ public class ActivityManagerService extends IActivityManager.Stub // If set, we will push process association information in to procstats. static final boolean TRACK_PROCSTATS_ASSOCIATIONS = true; // The minimum memory growth threshold (in KB) for low RAM devices. private static final int MINIMUM_MEMORY_GROWTH_THRESHOLD = 10 * 1000; // 10 MB /** * The number of binder proxies we need to have before we start dumping debug info * and kill the offenders. Loading Loading @@ -8871,31 +8867,13 @@ public class ActivityManagerService extends IActivityManager.Stub mOomAdjuster.mCachedAppOptimizer.compactAllSystem(); } final long lowRamSinceLastIdle = mAppProfiler.getLowRamTimeSinceIdleLPr(now); mLastIdleTime = now; mAppProfiler.updateLowRamTimestampLPr(now); StringBuilder sb = new StringBuilder(128); sb.append("Idle maintenance over "); TimeUtils.formatDuration(timeSinceLastIdle, sb); sb.append(" low RAM for "); TimeUtils.formatDuration(lowRamSinceLastIdle, sb); Slog.i(TAG, sb.toString()); // If at least 1/3 of our time since the last idle period has been spent // with RAM low, then we want to kill processes. boolean doKilling = lowRamSinceLastIdle > (timeSinceLastIdle/3); // If the processes' memory has increased by more than 1% of the total memory, // or 10 MB, whichever is greater, then the processes' are eligible to be killed. final long totalMemoryInKb = getTotalMemory() / 1000; // This threshold should be applicable to both PSS and RSS because the value is absolute // and represents an increase in process memory relative to its own previous state. // // TODO(b/296454553): Tune this value during the flag rollout process if more processes // seem to be getting killed than before. final long memoryGrowthThreshold = Math.max(totalMemoryInKb / 100, MINIMUM_MEMORY_GROWTH_THRESHOLD); mProcessList.forEachLruProcessesLOSP(false, proc -> { if (proc.getThread() == null) { return; Loading @@ -8903,59 +8881,9 @@ public class ActivityManagerService extends IActivityManager.Stub final ProcessProfileRecord pr = proc.mProfile; final ProcessStateRecord state = proc.mState; final int setProcState = state.getSetProcState(); if (state.isNotCachedSinceIdle()) { if (setProcState >= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE && setProcState <= ActivityManager.PROCESS_STATE_SERVICE) { final long initialIdlePssOrRss, lastPssOrRss, lastSwapPss; synchronized (mAppProfiler.mProfilerLock) { initialIdlePssOrRss = pr.getInitialIdlePssOrRss(); lastPssOrRss = mAppProfiler.isProfilingPss() ? pr.getLastPss() : pr.getLastRss(); lastSwapPss = pr.getLastSwapPss(); } if (doKilling && initialIdlePssOrRss != 0 && lastPssOrRss > (initialIdlePssOrRss * 3 / 2) && lastPssOrRss > (initialIdlePssOrRss + memoryGrowthThreshold)) { final StringBuilder sb2 = new StringBuilder(128); sb2.append("Kill"); sb2.append(proc.processName); if (mAppProfiler.isProfilingPss()) { sb2.append(" in idle maint: pss="); } else { sb2.append(" in idle maint: rss="); } sb2.append(lastPssOrRss); if (mAppProfiler.isProfilingPss()) { sb2.append(", swapPss="); sb2.append(lastSwapPss); sb2.append(", initialPss="); } else { sb2.append(", initialRss="); } sb2.append(initialIdlePssOrRss); sb2.append(", period="); TimeUtils.formatDuration(timeSinceLastIdle, sb2); sb2.append(", lowRamPeriod="); TimeUtils.formatDuration(lowRamSinceLastIdle, sb2); Slog.wtfQuiet(TAG, sb2.toString()); mHandler.post(() -> { synchronized (ActivityManagerService.this) { proc.killLocked(mAppProfiler.isProfilingPss() ? "idle maint (pss " : "idle maint (rss " + lastPssOrRss + " from " + initialIdlePssOrRss + ")", ApplicationExitInfo.REASON_OTHER, ApplicationExitInfo.SUBREASON_MEMORY_PRESSURE, true); } }); } } } else if (setProcState < ActivityManager.PROCESS_STATE_HOME if (setProcState < ActivityManager.PROCESS_STATE_HOME && setProcState >= ActivityManager.PROCESS_STATE_PERSISTENT) { state.setNotCachedSinceIdle(true); synchronized (mAppProfiler.mProfilerLock) { pr.setInitialIdlePssOrRss(0); mAppProfiler.updateNextPssTimeLPf( state.getSetProcState(), proc.mProfile, now, true); } Loading Loading @@ -11509,9 +11437,6 @@ public class ActivityManagerService extends IActivityManager.Stub long now = SystemClock.uptimeMillis(); pw.print(" mLastIdleTime="); TimeUtils.formatDuration(now, mLastIdleTime, pw); pw.print(" mLowRamSinceLastIdle="); TimeUtils.formatDuration( mAppProfiler.getLowRamTimeSinceIdleLPr(now), pw); pw.println(); pw.println(); Loading Loading @@ -11674,8 +11599,6 @@ public class ActivityManagerService extends IActivityManager.Stub mAppProfiler.writeMemoryLevelsToProtoLocked(proto); long now = SystemClock.uptimeMillis(); ProtoUtils.toDuration(proto, ActivityManagerServiceDumpProcessesProto.LAST_IDLE_TIME, mLastIdleTime, now); proto.write(ActivityManagerServiceDumpProcessesProto.LOW_RAM_SINCE_LAST_IDLE_MS, mAppProfiler.getLowRamTimeSinceIdleLPr(now)); } } Loading
services/core/java/com/android/server/am/AppProfiler.java +0 −31 Original line number Diff line number Diff line Loading @@ -245,18 +245,6 @@ public class AppProfiler { @GuardedBy("mService") private int mLastNumProcesses; /** * Total time spent with RAM that has been added in the past since the last idle time. */ @GuardedBy("mProcLock") private long mLowRamTimeSinceLastIdle = 0; /** * If RAM is currently low, when that horrible situation started. */ @GuardedBy("mProcLock") private long mLowRamStartTime = 0; /** * Last time we report a memory usage. */ Loading Loading @@ -919,9 +907,6 @@ public class AppProfiler { + " lastPss=" + profile.getLastPss() + " state=" + ProcessList.makeProcStateString(procState)); } if (profile.getInitialIdlePssOrRss() == 0) { profile.setInitialIdlePssOrRss(pss); } profile.setLastPss(pss); profile.setLastSwapPss(swapPss); if (procState >= ActivityManager.PROCESS_STATE_HOME) { Loading Loading @@ -986,9 +971,6 @@ public class AppProfiler { + " lastRss=" + profile.getLastRss() + " state=" + ProcessList.makeProcStateString(procState)); } if (profile.getInitialIdlePssOrRss() == 0) { profile.setInitialIdlePssOrRss(rss); } profile.setLastRss(rss); if (procState >= ActivityManager.PROCESS_STATE_HOME) { profile.setLastCachedRss(rss); Loading Loading @@ -1334,14 +1316,6 @@ public class AppProfiler { return mLastMemoryLevel <= ADJ_MEM_FACTOR_NORMAL; } @GuardedBy("mProcLock") void updateLowRamTimestampLPr(long now) { mLowRamTimeSinceLastIdle = 0; if (mLowRamStartTime != 0) { mLowRamStartTime = now; } } @GuardedBy("mService") void setAllowLowerMemLevelLocked(boolean allowLowerMemLevel) { mAllowLowerMemLevel = allowLowerMemLevel; Loading Loading @@ -1482,11 +1456,6 @@ public class AppProfiler { } } @GuardedBy("mProcLock") long getLowRamTimeSinceIdleLPr(long now) { return mLowRamTimeSinceLastIdle + (mLowRamStartTime > 0 ? (now - mLowRamStartTime) : 0); } /** * Ask a given process to GC right now. */ Loading
services/core/java/com/android/server/am/OomAdjuster.java +0 −3 Original line number Diff line number Diff line Loading @@ -2201,9 +2201,6 @@ public abstract class OomAdjuster { maybeUpdateLastTopTime(state, now); state.setSetProcState(state.getCurProcState()); if (state.getSetProcState() >= ActivityManager.PROCESS_STATE_HOME) { state.setNotCachedSinceIdle(false); } if (!doingAll) { synchronized (mService.mProcessStats.mLock) { mService.setProcessTrackerStateLOSP(app, Loading
services/core/java/com/android/server/am/ProcessProfileRecord.java +0 −16 Original line number Diff line number Diff line Loading @@ -73,12 +73,6 @@ final class ProcessProfileRecord { @GuardedBy("mProfilerLock") private long mNextPssTime; /** * Initial memory pss of process for idle maintenance. */ @GuardedBy("mProfilerLock") private long mInitialIdlePssOrRss; /** * Last computed memory pss. */ Loading Loading @@ -355,16 +349,6 @@ final class ProcessProfileRecord { mNextPssTime = nextPssTime; } @GuardedBy("mProfilerLock") long getInitialIdlePssOrRss() { return mInitialIdlePssOrRss; } @GuardedBy("mProfilerLock") void setInitialIdlePssOrRss(long initialIdlePssOrRss) { mInitialIdlePssOrRss = initialIdlePssOrRss; } @GuardedBy("mProfilerLock") long getLastPss() { return mLastPss; Loading