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

Commit e080bb52 authored by Kishore Srivenkata Ganesh Bolisetty's avatar Kishore Srivenkata Ganesh Bolisetty Committed by Linux Build Service Account
Browse files

Performance: Propagate B-services to higher adj

Depending on the inactivity of a service, move the B-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.
Improves concurrency.

Change-Id: Ied6cfcc3d11951f32f18de680b0e3483db8e163e
parent 4734ae78
Loading
Loading
Loading
Loading
+49 −0
Original line number Original line Diff line number Diff line
@@ -1365,6 +1365,16 @@ public final class ActivityManagerService extends ActivityManagerNative
    CompatModeDialog mCompatModeDialog;
    CompatModeDialog mCompatModeDialog;
    long mLastMemUsageReportTime = 0;
    long mLastMemUsageReportTime = 0;
    // Min aging threshold in milliseconds to consider a B-service
    int mMinBServiceAgingTime =
            SystemProperties.getInt("ro.sys.fw.bservice_age", 5000);
    // Threshold for B-services when in memory pressure
    int mBServiceAppThreshold =
            SystemProperties.getInt("ro.sys.fw.bservice_limit", 5);
    // Enable B-service aging propagation on memory pressure.
    boolean mEnableBServicePropagation =
            SystemProperties.getBoolean("ro.sys.fw.bservice_enable", false);
    /**
    /**
     * Flag whether the current user is a "monkey", i.e. whether
     * Flag whether the current user is a "monkey", i.e. whether
     * the UI is driven by a UI automation tool.
     * the UI is driven by a UI automation tool.
@@ -19032,8 +19042,39 @@ public final class ActivityManagerService extends ActivityManagerNative
        int nextCachedAdj = curCachedAdj+1;
        int nextCachedAdj = curCachedAdj+1;
        int curEmptyAdj = ProcessList.CACHED_APP_MIN_ADJ;
        int curEmptyAdj = ProcessList.CACHED_APP_MIN_ADJ;
        int nextEmptyAdj = curEmptyAdj+2;
        int nextEmptyAdj = curEmptyAdj+2;
        ProcessRecord selectedAppRecord = null;
        long serviceLastActivity = 0;
        int numBServices = 0;
        for (int i=N-1; i>=0; i--) {
        for (int i=N-1; i>=0; i--) {
            ProcessRecord app = mLruProcesses.get(i);
            ProcessRecord app = mLruProcesses.get(i);
            if (mEnableBServicePropagation && app.serviceb
                    && (app.curAdj == ProcessList.SERVICE_B_ADJ)) {
                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
                            < mMinBServiceAgingTime) {
                        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) {
            if (!app.killedByAm && app.thread != null) {
                app.procStateChanged = false;
                app.procStateChanged = false;
                computeOomAdjLocked(app, ProcessList.UNKNOWN_ADJ, TOP_APP, true, now);
                computeOomAdjLocked(app, ProcessList.UNKNOWN_ADJ, TOP_APP, true, now);
@@ -19142,6 +19183,14 @@ public final class ActivityManagerService extends ActivityManagerNative
                }
                }
            }
            }
        }
        }
        if ((numBServices > mBServiceAppThreshold) && (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;
        mNumServiceProcs = mNewNumServiceProcs;