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

Commit b24e9896 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Don't hold WM lock while updating OOM adj

Holding the lock can cause quite the performance regression, up
to 9-10ms for app hot launch tests depending on thread
interleaving.

Since the original issue was fixed by
I160f951e103835401ccaaf7c732ba407e011c39b let's try again without
holding the lock since this can be quite a big performance hit.

Test: atest AppTransitionTests
Bug: 123502026
Bug: 124067004
Change-Id: If6bbe35139aeaa3a36d9d1ce5aad2b3503ac95f8
Fixes: 124019557
parent 683fe3ea
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2226,7 +2226,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mConstants = hasHandlerThread ? new ActivityManagerConstants(this, mHandler) : null;
        final ActiveUids activeUids = new ActiveUids(this, false /* postChangesToAtm */);
        mProcessList.init(this, activeUids);
        mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids, new Object());
        mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids);
        mIntentFirewall = hasHandlerThread
                ? new IntentFirewall(new IntentFirewallInterface(), mHandler) : null;
@@ -2274,7 +2274,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mConstants = new ActivityManagerConstants(this, mHandler);
        final ActiveUids activeUids = new ActiveUids(this, true /* postChangesToAtm */);
        mProcessList.init(this, activeUids);
        mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids, atm.getGlobalLock());
        mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids);
        // Broadcast policy parameters
        final BroadcastConstants foreConstants = new BroadcastConstants(
+1 −18
Original line number Diff line number Diff line
@@ -127,18 +127,8 @@ public final class OomAdjuster {
    private final ActivityManagerService mService;
    private final ProcessList mProcessList;

    /**
     * Used to lock {@link #updateOomAdjImpl} for state consistency. It also reduces frequency lock
     * and unlock when getting and setting value to {@link ProcessRecord#mWindowProcessController}.
     * Note it is declared as Object type so the locked-region-code-injection won't wrap the
     * unnecessary priority booster.
     */
    private final Object mAtmGlobalLock;

    OomAdjuster(ActivityManagerService service, ProcessList processList, ActiveUids activeUids,
            Object atmGlobalLock) {
    OomAdjuster(ActivityManagerService service, ProcessList processList, ActiveUids activeUids) {
        mService = service;
        mAtmGlobalLock = atmGlobalLock;
        mProcessList = processList;
        mActiveUids = activeUids;

@@ -196,13 +186,6 @@ public final class OomAdjuster {

    @GuardedBy("mService")
    final void updateOomAdjLocked() {
        synchronized (mAtmGlobalLock) {
            updateOomAdjImpl();
        }
    }

    @GuardedBy({"mService", "mAtmGlobalLock"})
    private void updateOomAdjImpl() {
        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "updateOomAdj");
        mService.mOomAdjProfiler.oomAdjStarted();
        final ProcessRecord TOP_APP = mService.getTopAppLocked();