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

Commit d0a13f84 authored by Kishore Srivenkata Ganesh Bolisetty's avatar Kishore Srivenkata Ganesh Bolisetty Committed by Gerrit - the friendly Code Review server
Browse files

Improve concurrency by propagating B services to higher adj

Depending on the inactivity of a service, move the services to
highest adj 1000. Under memory pressure, these services will
be killed first ahead of cached apps which results in better
concurrency numbers with bg apps. Inactivity time and minumum
no of services to be maintained are configurable as system properties.

Change-Id: Ied6cfcc3d11951f32f18de680b0e3483db8e163e
parent fbba25ce
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -18328,8 +18328,37 @@ public final class ActivityManagerService extends ActivityManagerNative
        int nextCachedAdj = curCachedAdj+1;
        int curEmptyAdj = ProcessList.CACHED_APP_MIN_ADJ;
        int nextEmptyAdj = curEmptyAdj+2;
        ProcessRecord selectedAppRecord = null;
        long serviceLastActivity = 0;
        int numBServices = 0;
        for (int i=N-1; i>=0; i--) {
            ProcessRecord app = mLruProcesses.get(i);
            if (ProcessList.ENABLE_B_SERVICE_PROPAGATION && app.serviceb) {
                numBServices++;
                for (int s=app.services.size()-1; s>=0; s--) {
                    ServiceRecord sr = app.services.valueAt(s);
                    if (DEBUG_OOM_ADJ) {
                        Slog.d(TAG,"app.processName = "+app.processName+ " serviceb = "+ app.serviceb+ " s = "+s+" sr.lastActivity = "+sr.lastActivity+
                                   " packageName = "+sr.packageName+" processName = "+sr.processName);
                    }
                    if (SystemClock.uptimeMillis()-sr.lastActivity < ProcessList.MIN_BSERVICE_AGING_TIME) {
                        if (DEBUG_OOM_ADJ) {
                            Slog.d(TAG,"Not aged enough!!!");
                        }
                        continue;
                    }
                    if (serviceLastActivity == 0) {
                        serviceLastActivity = sr.lastActivity;
                        selectedAppRecord = app;
                    } else if (sr.lastActivity < serviceLastActivity) {
                        serviceLastActivity = sr.lastActivity;
                        selectedAppRecord = app;
                    }
                }
            }
            if (DEBUG_OOM_ADJ && selectedAppRecord != null) {
                Slog.d(TAG,"Identified app.processName = "+selectedAppRecord.processName+" app.pid = "+selectedAppRecord.pid);
            }
            if (!app.killedByAm && app.thread != null) {
                app.procStateChanged = false;
                computeOomAdjLocked(app, ProcessList.UNKNOWN_ADJ, TOP_APP, true, now);
@@ -18432,6 +18461,13 @@ public final class ActivityManagerService extends ActivityManagerNative
                }
            }
        }
        if ((numBServices > ProcessList.BSERVICE_APP_THRESHOLD) && (true == mAllowLowerMemLevel) && (selectedAppRecord!=null)) {
            ProcessList.setOomAdj(selectedAppRecord.pid, selectedAppRecord.info.uid ,ProcessList.CACHED_APP_MAX_ADJ);
            selectedAppRecord.setAdj = selectedAppRecord.curAdj;
            if (DEBUG_OOM_ADJ) {
                Slog.d(TAG,"app.processName = "+ selectedAppRecord.processName + " app.pid = "+selectedAppRecord.pid + " is moved to higher adj");
            }
        }
        mNumServiceProcs = mNewNumServiceProcs;
+7 −0
Original line number Diff line number Diff line
@@ -120,6 +120,13 @@ final class ProcessList {
    // without empty apps being able to push them out of memory.
    static final int MIN_CACHED_APPS = 2;

    // Min aging threshold in milliseconds to consider a B services for propagation to higher adj
    static final int MIN_BSERVICE_AGING_TIME = SystemProperties.getInt("ro.sys.fw.bservice_age",5000);
    // Threshold for B Services when in memory pressure
    static final int BSERVICE_APP_THRESHOLD = SystemProperties.getInt("ro.sys.fw.bservice_limit",5);
    // Enable B service aging propagation on memory pressure.
    static final boolean ENABLE_B_SERVICE_PROPAGATION = SystemProperties.getBoolean("ro.sys.fw.bservice_enable",false);

    // The maximum number of cached processes we will keep around before killing them.
    // NOTE: this constant is *only* a control to not let us go too crazy with
    // keeping around processes on devices with large amounts of RAM.  For devices that