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

Commit a05c7232 authored by Chitti Babu Theegala's avatar Chitti Babu Theegala Committed by Steve Kondik
Browse files

ActivityManagerService: Penalise large apps going to background

Large applications (PSS more than a given threshold) when closed are
penalised with higher ADJ. Now, they will be more prone to be killed by
lowmemorykiller during memory pressure levels. This ensures better app
concurrency and improved subsequent latencies as it leaves some more room
for other smaller bg apps to be alive

Change-Id: I448fa12f55370949b22075595cd75b9c29e5d4b5
parent 3bec6902
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -344,6 +344,16 @@ public final class ActivityManagerService extends ActivityManagerNative
    // devices.
    private boolean mShowDialogs = true;
    // Penalise Large applications going to background only for Low-RAM devices
    private boolean mPenaliseLargeApps = ActivityManager.isLowRamDeviceStatic();
    // ADJ to be set for new background app (if found to be large)
    private int mPenalisedAdj = SystemProperties.getInt("ro.am.penalise_large_apps.adj",
                                                   ProcessList.CACHED_APP_MAX_ADJ);
    // Threshold Pss to be compared against new background app's Pss
    private long mPenalisedThreshold;
    /**
     * Description of a request to start a new activity, which has been held
     * due to app switches being disabled.
@@ -2063,6 +2073,15 @@ public final class ActivityManagerService extends ActivityManagerNative
        mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
        if (mPenaliseLargeApps == true) {
            long cachedAppMaxMemLevel
                    = mProcessList.getMemLevel(ProcessList.CACHED_APP_MAX_ADJ)/1024;
            mPenalisedThreshold = SystemProperties.getLong(
                    "ro.am.penalise_large_apps.pss", cachedAppMaxMemLevel);
            Slog.i(TAG,"Large apps penalisation enabled. Threshold Pss = " + mPenalisedThreshold +
                        ", ADJ = " + mPenalisedAdj);
        }
        // User 0 is the first and only user that runs at boot.
        mStartedUsers.put(0, new UserStartedState(new UserHandle(0), true));
        mUserLru.add(Integer.valueOf(0));
@@ -15450,6 +15469,23 @@ public final class ActivityManagerService extends ActivityManagerNative
            app.setRawAdj = app.curRawAdj;
        }
        if ( (mPenaliseLargeApps == true) && ((app.curAdj == ProcessList.PREVIOUS_APP_ADJ)
                || ((app.curAdj >= ProcessList.CACHED_APP_MIN_ADJ)
                && (app.curAdj < ProcessList.CACHED_APP_MAX_ADJ))) ) {
            // Validate the PSS to be compared against for penalisation
            if (app.lastCachedPss == 0) {
                app.lastCachedPss = Debug.getPss(app.pid, null);
            }
            if (app.lastCachedPss > mPenalisedThreshold) {
                if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.i(
                    TAG,"New BG app : " + app.processName + " is heavy! (pss = " +
                    app.lastCachedPss + " kB). Forcing to ADJ " + mPenalisedAdj);
                app.curAdj = mPenalisedAdj;
            }
        }
        if (app.curAdj != app.setAdj) {
            if (Process.setOomAdj(app.pid, app.curAdj)) {
                if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(