diff options
| author | 2018-10-10 14:22:20 -0700 | |
|---|---|---|
| committer | 2018-10-12 16:15:09 +0000 | |
| commit | 2b2011a80529e72334a8fead2d2706e47cfa64b9 (patch) | |
| tree | 26d371f2402fbef044ef3052be6c259de8affb76 | |
| parent | 58d1ac473e0cd87886fe8ed666b6245097729927 (diff) | |
Request lmkd to purge its list of pids after establishing connection
lmkd keeps a list of pids registered by ActivityManager, however on rare
occasions when framework restarts and lmkd survives that list has to be
purged. Request lmkd to clear its pid list immediately after establishing
connection to it.
Bug: 116801366
Test: locally by killing zygote process
Change-Id: Id8c81e0cb0c4cf03b8faa0add5a9514fd3cd0c0c
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
| -rw-r--r-- | services/core/java/com/android/server/am/ProcessList.java | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java index 3ac7885eba37..9e7ce3204444 100644 --- a/services/core/java/com/android/server/am/ProcessList.java +++ b/services/core/java/com/android/server/am/ProcessList.java @@ -162,9 +162,11 @@ public final class ProcessList { // LMK_TARGET <minfree> <minkillprio> ... (up to 6 pairs) // LMK_PROCPRIO <pid> <uid> <prio> // LMK_PROCREMOVE <pid> + // LMK_PROCPURGE static final byte LMK_TARGET = 0; static final byte LMK_PROCPRIO = 1; static final byte LMK_PROCREMOVE = 2; + static final byte LMK_PROCPURGE = 3; // These are the various interesting memory levels that we will give to // the OOM killer. Note that the OOM killer only supports 6 slots, so we @@ -813,31 +815,46 @@ public final class ProcessList { return true; } + // Never call directly, use writeLmkd() instead + private static boolean writeLmkdCommand(ByteBuffer buf) { + try { + sLmkdOutputStream.write(buf.array(), 0, buf.position()); + } catch (IOException ex) { + Slog.w(TAG, "Error writing to lowmemorykiller socket"); + + try { + sLmkdSocket.close(); + } catch (IOException ex2) { + } + + sLmkdSocket = null; + return false; + } + return true; + } + private static void writeLmkd(ByteBuffer buf) { for (int i = 0; i < 3; i++) { if (sLmkdSocket == null) { - if (openLmkdSocket() == false) { - try { - Thread.sleep(1000); - } catch (InterruptedException ie) { - } - continue; + if (openLmkdSocket() == false) { + try { + Thread.sleep(1000); + } catch (InterruptedException ie) { } - } - - try { - sLmkdOutputStream.write(buf.array(), 0, buf.position()); - return; - } catch (IOException ex) { - Slog.w(TAG, "Error writing to lowmemorykiller socket"); - - try { - sLmkdSocket.close(); - } catch (IOException ex2) { + continue; } - sLmkdSocket = null; + // Purge any previously registered pids + ByteBuffer purge_buf = ByteBuffer.allocate(4); + purge_buf.putInt(LMK_PROCPURGE); + if (writeLmkdCommand(purge_buf) == false) { + // Write failed, skip the rest and retry + continue; + } + } + if (writeLmkdCommand(buf)) { + return; } } } |