diff options
| author | 2020-07-22 23:54:40 -0700 | |
|---|---|---|
| committer | 2020-07-23 11:34:37 -0700 | |
| commit | c68053a3c3aa34bd60d9277bd7165b421a06202c (patch) | |
| tree | b60faf4806292a24ee30726866d3633afeaa71bf | |
| parent | 0eae0b2abce318f3745374de9394ecf7967caf5f (diff) | |
Fix spurious undead process warning
Set the strict mode policy before Process.waitForProcessDeath.
Also eliminate some of the wtf warnings because we know it's
a legitimate case: a large process could get killed during
getProcessLocked(), and the caller would start a new process
right after that.
Bug: 161835160
Test: See b/161835160#comment3 for detailed test steps
Change-Id: I357b522943c88aa833dcf06013a9f8d2240c3967
| -rw-r--r-- | services/core/java/com/android/server/am/ProcessList.java | 28 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ProcessRecord.java | 3 |
2 files changed, 27 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java index b6ad1a526165..1038069f5d11 100644 --- a/services/core/java/com/android/server/am/ProcessList.java +++ b/services/core/java/com/android/server/am/ProcessList.java @@ -2050,7 +2050,9 @@ public final class ProcessList { final int pid = precedence.pid; long now = System.currentTimeMillis(); final long end = now + PROC_KILL_TIMEOUT; + final int oldPolicy = StrictMode.getThreadPolicyMask(); try { + StrictMode.setThreadPolicyMask(0); Process.waitForProcessDeath(pid, PROC_KILL_TIMEOUT); // It's killed successfully, but we'd make sure the cleanup work is done. synchronized (precedence) { @@ -2069,9 +2071,11 @@ public final class ProcessList { } } } catch (Exception e) { - // It's still alive... + // It's still alive... maybe blocked at uninterruptible sleep ? Slog.wtf(TAG, precedence.toString() + " refused to die, but we need to launch " - + app); + + app, e); + } finally { + StrictMode.setThreadPolicyMask(oldPolicy); } } try { @@ -2416,7 +2420,15 @@ public final class ProcessList { ProcessList.killProcessGroup(app.uid, app.pid); checkSlow(startTime, "startProcess: done killing old proc"); - Slog.wtf(TAG_PROCESSES, app.toString() + " is attached to a previous process"); + if (!app.killed || mService.mLastMemoryLevel <= ProcessStats.ADJ_MEM_FACTOR_NORMAL + || app.setProcState < ActivityManager.PROCESS_STATE_CACHED_EMPTY + || app.lastCachedPss < getCachedRestoreThresholdKb()) { + // Throw a wtf if it's not killed, or killed but not because the system was in + // memory pressure + the app was in "cch-empty" and used large amount of memory + Slog.wtf(TAG_PROCESSES, app.toString() + " is attached to a previous process"); + } else { + Slog.w(TAG_PROCESSES, app.toString() + " is attached to a previous process"); + } // We are not going to re-use the ProcessRecord, as we haven't dealt with the cleanup // routine of it yet, but we'd set it as the precedence of the new process. precedence = app; @@ -2819,7 +2831,15 @@ public final class ProcessList { // We are re-adding a persistent process. Whatevs! Just leave it there. Slog.w(TAG, "Re-adding persistent process " + proc); } else if (old != null) { - Slog.wtf(TAG, "Already have existing proc " + old + " when adding " + proc); + if (old.killed) { + // The old process has been killed, we probably haven't had + // a chance to clean up the old record, just log a warning + Slog.w(TAG, "Existing proc " + old + " was killed " + + (SystemClock.uptimeMillis() - old.mKillTime) + + "ms ago when adding " + proc); + } else { + Slog.wtf(TAG, "Already have existing proc " + old + " when adding " + proc); + } } UidRecord uidRec = mActiveUids.get(proc.uid); if (uidRec == null) { diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java index c5152c081e70..b228435e4dca 100644 --- a/services/core/java/com/android/server/am/ProcessRecord.java +++ b/services/core/java/com/android/server/am/ProcessRecord.java @@ -352,6 +352,8 @@ class ProcessRecord implements WindowProcessListener { boolean mReachable; // Whether or not this process is reachable from given process + long mKillTime; // The timestamp in uptime when this process was killed. + void setStartParams(int startUid, HostingRecord hostingRecord, String seInfo, long startTime) { this.startUid = startUid; @@ -925,6 +927,7 @@ class ProcessRecord implements WindowProcessListener { if (!mPersistent) { killed = true; killedByAm = true; + mKillTime = SystemClock.uptimeMillis(); } Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); } |