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

Commit 9acf12b3 authored by Edgar Arriaga's avatar Edgar Arriaga
Browse files

Improve compaction to abort when system changes to awake state

While the screen is off we sometimes issue compactions as they are not
disruptive to the user. However, it is possible to wake up and have
compactions running or scheduled so this may lead to jank. This patch
cancels any pending or running compactions that were scheduled to happen
during this non interactive type when the system becomes awake to avoid
jank.

Test: Manual
Bug: 214654755
Change-Id: Ie9b2cbaa7093d63e77f8666d1e6f050ab5610a1d
parent cbb6b2be
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6357,6 +6357,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                reportCurWakefulnessUsageEvent();
                mActivityTaskManager.onScreenAwakeChanged(isAwake);
                mOomAdjProfiler.onWakefulnessChanged(wakefulness);
                mOomAdjuster.onWakefulnessChanged(wakefulness);
            }
            updateOomAdjLocked(OomAdjuster.OOM_ADJ_REASON_UI_VISIBILITY);
        }
+10 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.net.Uri;
import android.os.Debug;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManagerInternal;
import android.os.Process;
import android.os.SystemClock;
import android.os.Trace;
@@ -1028,6 +1029,15 @@ public final class CachedAppOptimizer {
        }
    }

    void onWakefulnessChanged(int wakefulness) {
        if(wakefulness == PowerManagerInternal.WAKEFULNESS_AWAKE) {
            // Remove any pending compaction we may have scheduled to happen while screen was off
            Slog.e(TAG_AM, "Cancel pending or running compactions as system is awake");
            mPendingCompactionProcesses.clear();
            cancelCompaction();
        }
    }

    @GuardedBy({"mService", "mProcLock"})
    void onOomAdjustChanged(int oldAdj, int newAdj, ProcessRecord app) {
        // Cancel any currently executing compactions
+4 −0
Original line number Diff line number Diff line
@@ -2590,6 +2590,10 @@ public class OomAdjuster {
        }
    }

    void onWakefulnessChanged(int wakefulness) {
        mCachedAppOptimizer.onWakefulnessChanged(wakefulness);
    }

    /** Applies the computed oomadj, procstate and sched group values and freezes them in set* */
    @GuardedBy({"mService", "mProcLock"})
    private boolean applyOomAdjLSP(ProcessRecord app, boolean doingAll, long now,
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ static int64_t compactMemory(const std::vector<Vma>& vmas, int pid, int madviseT
                // There could be a significant delay between when a compaction
                // is requested and when it is handled during this time our
                // OOM adjust could have improved.
                LOG(DEBUG) << "Cancelled running compaction for " << pid;
                break;
            }