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

Commit b244fdfa authored by Amith Yamasani's avatar Amith Yamasani Committed by Jiyong Park
Browse files

Adjust the process group of the phantom processes as well

When an app process is assigned to a new process group, do the same for
all phantom processes created by the app. Otherwise, those phantom
processes can remain in the top-app cpuset even after the app process
goes to foreground or even background.

Bug: 375058190
Test: run Linux terminal, and then go to launcher. check the below
3:cpuset:/foreground
2:cpu:/
1:blkio:/
0::/uid_1010291/pid_9233

ensure that the cpuset is in foreground, not in top-app.

Flag: EXEMPT bugfix

Change-Id: I7115ce86d3363e83b1808fb2db5bd2c143bed885
parent 7c6f77f6
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -78,7 +78,6 @@ import static android.os.Process.THREAD_GROUP_RESTRICTED;
import static android.os.Process.THREAD_GROUP_TOP_APP;
import static android.os.Process.THREAD_PRIORITY_DISPLAY;
import static android.os.Process.THREAD_PRIORITY_TOP_APP_BOOST;
import static android.os.Process.setProcessGroup;

import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BACKUP;
@@ -526,7 +525,7 @@ public class OomAdjuster {
                        + msg.obj + " to " + group);
            }
            try {
                setProcessGroup(pid, group);
                android.os.Process.setProcessGroup(pid, group);
            } catch (Exception e) {
                if (DEBUG_ALL) {
                    Slog.w(TAG, "Failed setting process group of " + pid + " to " + group, e);
@@ -544,6 +543,11 @@ public class OomAdjuster {
                / CACHED_APP_IMPORTANCE_LEVELS;
    }

    void setProcessGroup(int pid, int group, String processName) {
        mProcessGroupHandler.sendMessage(mProcessGroupHandler.obtainMessage(
                0 /* unused */, pid, group, processName));
    }

    void initSettings() {
        mCachedAppOptimizer.init();
        mCacheOomRanker.init(ActivityThread.currentApplication().getMainExecutor());
@@ -3489,8 +3493,8 @@ public class OomAdjuster {
                    processGroup = THREAD_GROUP_DEFAULT;
                    break;
            }
            mProcessGroupHandler.sendMessage(mProcessGroupHandler.obtainMessage(
                    0 /* unused */, app.getPid(), processGroup, app.processName));
            setProcessGroup(app.getPid(), processGroup, app.processName);
            mService.mPhantomProcessList.setProcessGroupForPhantomProcessOfApp(app, processGroup);
            try {
                final int renderThreadTid = app.getRenderThreadTid();
                if (curSchedGroup == SCHED_GROUP_TOP_APP) {
+33 −9
Original line number Diff line number Diff line
@@ -514,6 +514,15 @@ public final class PhantomProcessList {
        app.killLocked("Caused by child process: " + msg, reasonCode, subReason, true);
    }

    @GuardedBy("mLock")
    private SparseArray<PhantomProcessRecord> getPhantomProcessOfAppLocked(ProcessRecord app) {
        int index = mAppPhantomProcessMap.indexOfKey(app.getPid());
        if (index >= 0) {
            return mAppPhantomProcessMap.valueAt(index);
        }
        return null;
    }

    /**
     * Iterate all phantom process belonging to the given app, and invokve callback
     * for each of them.
@@ -521,10 +530,10 @@ public final class PhantomProcessList {
    void forEachPhantomProcessOfApp(final ProcessRecord app,
            final Function<PhantomProcessRecord, Boolean> callback) {
        synchronized (mLock) {
            int index = mAppPhantomProcessMap.indexOfKey(app.getPid());
            if (index >= 0) {
                final SparseArray<PhantomProcessRecord> array =
                        mAppPhantomProcessMap.valueAt(index);
            final SparseArray<PhantomProcessRecord> array = getPhantomProcessOfAppLocked(app);
            if (array == null) {
                return;
            }
            for (int i = array.size() - 1; i >= 0; i--) {
                final PhantomProcessRecord r = array.valueAt(i);
                if (!callback.apply(r)) {
@@ -533,6 +542,21 @@ public final class PhantomProcessList {
            }
        }
    }

    /**
     * Set process group of phantom process belonging to the given app.
     */
    void setProcessGroupForPhantomProcessOfApp(final ProcessRecord app, final int group) {
        synchronized (mLock) {
            final SparseArray<PhantomProcessRecord> array = getPhantomProcessOfAppLocked(app);
            if (array == null) {
                return;
            }
            for (int i = array.size() - 1; i >= 0; i--) {
                final PhantomProcessRecord r = array.valueAt(i);
                mService.mOomAdjuster.setProcessGroup(r.mPid, group, r.mProcessName);
            }
        }
    }

    @GuardedBy("tracker")
+2 −0
Original line number Diff line number Diff line
@@ -227,6 +227,8 @@ public class MockingOomAdjusterTests {
                mock(BatteryStatsService.class));
        setFieldValue(ActivityManagerService.class, mService, "mInjector",
                new ActivityManagerService.Injector(mContext));
        setFieldValue(ActivityManagerService.class, mService, "mPhantomProcessList",
                new PhantomProcessList(mService));
        doReturn(mock(AppOpsManager.class)).when(mService).getAppOpsManager();
        doCallRealMethod().when(mService).enqueueOomAdjTargetLocked(any(ProcessRecord.class));
        doCallRealMethod().when(mService).updateOomAdjPendingTargetsLocked(OOM_ADJ_REASON_ACTIVITY);