From 8a054c32c2dc86a93efe19885fd1deea6f9933f4 Mon Sep 17 00:00:00 2001 From: Edgar Arriaga Date: Tue, 29 Mar 2022 11:53:57 -0700 Subject: [PATCH] Fix for new compactions skipped after cancelling pending compactions When new compactions are scheduled they are added to the pending compaction process list however, they also maintain a flag that indicates whether a compaction is pending on the record, previously, when cancelling compactions we would remove the process from the list but not clear the flag, leaving the process in an uncompactable state as it would be skipped from being scheduled thinking there was a compaction happening when there wasn't any. Bug: 227502250 Test: Manual. Logging and dumpsys activity Change-Id: Id9d712bd14ba83c4d647d3e9faa88e4ddbd1b697 --- .../android/server/am/CachedAppOptimizer.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/am/CachedAppOptimizer.java b/services/core/java/com/android/server/am/CachedAppOptimizer.java index e91b2b32f930e..2b16b1589288b 100644 --- a/services/core/java/com/android/server/am/CachedAppOptimizer.java +++ b/services/core/java/com/android/server/am/CachedAppOptimizer.java @@ -1146,13 +1146,26 @@ public final class CachedAppOptimizer { 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"); - synchronized(mProcLock) { - mPendingCompactionProcesses.clear(); - } - cancelCompaction(); + cancelAllCompactions(); } } + void cancelAllCompactions() { + synchronized (mProcLock) { + int size = mPendingCompactionProcesses.size(); + ProcessRecord record; + for (int i=0; i < size; ++i) { + record = mPendingCompactionProcesses.get(i); + // The process record is kept alive after compactions are cleared, + // so make sure to reset the compaction state to avoid skipping any future + // compactions due to a stale value here. + record.mOptRecord.setHasPendingCompact(false); + } + mPendingCompactionProcesses.clear(); + } + cancelCompaction(); + } + @GuardedBy({"mService", "mProcLock"}) void onOomAdjustChanged(int oldAdj, int newAdj, ProcessRecord app) { // Cancel any currently executing compactions