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

Commit a6a9eb44 authored by Kalesh Singh's avatar Kalesh Singh Committed by Automerger Merge Worker
Browse files

AMS: Proactive Kills - Minimal Implementation am: 8a2e9fbe

parents 5268ff63 8a2e9fbe
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -651,7 +651,7 @@ public final class CachedAppOptimizer {
    /**
     * Retrieves the free swap percentage.
     */
    static private native double getFreeSwapPercent();
    static native double getFreeSwapPercent();

    /**
     * Reads the flag value from DeviceConfig to determine whether app compaction
+29 −0
Original line number Diff line number Diff line
@@ -1034,6 +1034,12 @@ public class OomAdjuster {

    private long mNextNoKillDebugMessageTime;

    private double mLastFreeSwapPercent = 1.00;

    private static double getFreeSwapPercent() {
        return CachedAppOptimizer.getFreeSwapPercent();
    }

    @GuardedBy({"mService", "mProcLock"})
    private boolean updateAndTrimProcessLSP(final long now, final long nowElapsed,
            final long oldTime, final ActiveUids activeUids, String oomAdjReason) {
@@ -1058,6 +1064,11 @@ public class OomAdjuster {
        int numEmpty = 0;
        int numTrimming = 0;

        boolean proactiveKillsEnabled = false;  // TODO: Configure from phenotype
        double lowSwapThresholdPercent = 0.10;  // TODO: Configure from phenotype
        double freeSwapPercent =  proactiveKillsEnabled ? getFreeSwapPercent() : 1.00;
        ProcessRecord lruCachedApp = null;

        for (int i = numLru - 1; i >= 0; i--) {
            ProcessRecord app = lruList.get(i);
            final ProcessStateRecord state = app.mState;
@@ -1095,6 +1106,8 @@ public class OomAdjuster {
                                    ApplicationExitInfo.REASON_OTHER,
                                    ApplicationExitInfo.SUBREASON_TOO_MANY_CACHED,
                                    true);
                        } else if (proactiveKillsEnabled) {
                            lruCachedApp = app;
                        }
                        break;
                    case PROCESS_STATE_CACHED_EMPTY:
@@ -1114,6 +1127,8 @@ public class OomAdjuster {
                                        ApplicationExitInfo.REASON_OTHER,
                                        ApplicationExitInfo.SUBREASON_TOO_MANY_EMPTY,
                                        true);
                            } else if (proactiveKillsEnabled) {
                                lruCachedApp = app;
                            }
                        }
                        break;
@@ -1145,6 +1160,20 @@ public class OomAdjuster {
            }
        }

        if (proactiveKillsEnabled                               // Proactive kills enabled?
                && doKillExcessiveProcesses                     // Should kill excessive processes?
                && freeSwapPercent < lowSwapThresholdPercent    // Swap below threshold?
                && lruCachedApp != null                         // If no cached app, let LMKD decide
                // If swap is non-decreasing, give reclaim a chance to catch up
                && freeSwapPercent < mLastFreeSwapPercent) {
            lruCachedApp.killLocked("swap low and too many cached",
                    ApplicationExitInfo.REASON_OTHER,
                    ApplicationExitInfo.SUBREASON_TOO_MANY_CACHED,
                    true);
        }

        mLastFreeSwapPercent = freeSwapPercent;

        return mService.mAppProfiler.updateLowMemStateLSP(numCached, numEmpty, numTrimming);
    }