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

Commit 4f0c1eff authored by David Stevens's avatar David Stevens
Browse files

Remove now-unused idle killing code

Now that the legacy trim code is gone (ag/26563712), mLowRamStartTime is
never set to a non-zero value and mLowRamTimeSinceLastIdle is never
updated. This means that doKilling in performIdleMaintenance is always
false, so the code guarded by that is all dead code.

Furthermore, the dead code was the only place that consumed
ProcessProfileRecord.mInitialIdlePssOrRss or
ProcessStateRecord.mNotCachedSinceIdle, so these can be removed as well.

Bug: 253914117
Test: build
Flag: EXEMPT refactor
Change-Id: Ib938d2cfe7fbb254a9fef3be11d0c3bcc20df15a
parent b2074751
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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 {
+1 −78
Original line number Diff line number Diff line
@@ -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;
@@ -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.
@@ -8866,31 +8862,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;
@@ -8898,59 +8876,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);
                    }
@@ -11504,9 +11432,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();
@@ -11669,8 +11594,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));
        }
    }
+0 −31
Original line number Diff line number Diff line
@@ -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.
     */
@@ -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) {
@@ -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);
@@ -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;
@@ -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.
     */
+0 −3
Original line number Diff line number Diff line
@@ -2114,9 +2114,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,
+0 −16
Original line number Diff line number Diff line
@@ -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.
     */
@@ -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