Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 18 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 19 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 20 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 21 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 22 | import java.io.IOException; |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 23 | import java.io.OutputStream; |
| 24 | import java.nio.ByteBuffer; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 25 | |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 26 | import android.app.ActivityManager; |
Dianne Hackborn | 9d52f79 | 2014-09-11 17:46:06 -0700 | [diff] [blame] | 27 | import android.os.Build; |
Dianne Hackborn | ecf1cda | 2014-08-28 16:58:28 -0700 | [diff] [blame] | 28 | import android.os.SystemClock; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 29 | import com.android.internal.util.MemInfoReader; |
| 30 | import com.android.server.wm.WindowManagerService; |
| 31 | |
Colin Cross | fcdad6f | 2013-07-25 15:04:40 -0700 | [diff] [blame] | 32 | import android.content.res.Resources; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 33 | import android.graphics.Point; |
Colin Cross | 59d80a5 | 2013-07-25 10:45:05 -0700 | [diff] [blame] | 34 | import android.os.SystemProperties; |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 35 | import android.net.LocalSocketAddress; |
| 36 | import android.net.LocalSocket; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 37 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 38 | import android.view.Display; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Activity manager code dealing with processes. |
| 42 | */ |
Sudheer Shanka | 352dc57 | 2017-09-22 17:09:38 -0700 | [diff] [blame] | 43 | public final class ProcessList { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 44 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ProcessList" : TAG_AM; |
| 45 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 46 | // The minimum time we allow between crashes, for us to consider this |
| 47 | // application to be bad and stop and its services and reject broadcasts. |
| 48 | static final int MIN_CRASH_INTERVAL = 60*1000; |
| 49 | |
| 50 | // OOM adjustments for processes in various states: |
| 51 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 52 | // Uninitialized value for any major or minor adj fields |
| 53 | static final int INVALID_ADJ = -10000; |
| 54 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 55 | // Adjustment used in certain places where we don't know it yet. |
| 56 | // (Generally this is something that is going to be cached, but we |
| 57 | // don't know the exact value in the cached range to assign yet.) |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 58 | static final int UNKNOWN_ADJ = 1001; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 59 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 60 | // This is a process only hosting activities that are not visible, |
Dianne Hackborn | e02c88a | 2011-10-28 13:58:15 -0700 | [diff] [blame] | 61 | // so it can be killed without any disruption. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 62 | static final int CACHED_APP_MAX_ADJ = 906; |
| 63 | static final int CACHED_APP_MIN_ADJ = 900; |
Dianne Hackborn | e02c88a | 2011-10-28 13:58:15 -0700 | [diff] [blame] | 64 | |
| 65 | // The B list of SERVICE_ADJ -- these are the old and decrepit |
| 66 | // services that aren't as shiny and interesting as the ones in the A list. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 67 | static final int SERVICE_B_ADJ = 800; |
Dianne Hackborn | f35fe23 | 2011-11-01 19:25:20 -0700 | [diff] [blame] | 68 | |
| 69 | // This is the process of the previous application that the user was in. |
| 70 | // This process is kept above other things, because it is very common to |
| 71 | // switch back to the previous app. This is important both for recent |
| 72 | // task switch (toggling between the two top recent apps) as well as normal |
| 73 | // UI flow such as clicking on a URI in the e-mail app to view in the browser, |
| 74 | // and then pressing back to return to e-mail. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 75 | static final int PREVIOUS_APP_ADJ = 700; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 76 | |
| 77 | // This is a process holding the home application -- we want to try |
| 78 | // avoiding killing it, even if it would normally be in the background, |
| 79 | // because the user interacts with it so much. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 80 | static final int HOME_APP_ADJ = 600; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 81 | |
Dianne Hackborn | e02c88a | 2011-10-28 13:58:15 -0700 | [diff] [blame] | 82 | // This is a process holding an application service -- killing it will not |
| 83 | // have much of an impact as far as the user is concerned. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 84 | static final int SERVICE_ADJ = 500; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 85 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 86 | // This is a process with a heavy-weight application. It is in the |
| 87 | // background, but we want to try to avoid killing it. Value set in |
| 88 | // system/rootdir/init.rc on startup. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 89 | static final int HEAVY_WEIGHT_APP_ADJ = 400; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 90 | |
| 91 | // This is a process currently hosting a backup operation. Killing it |
| 92 | // is not entirely fatal but is generally a bad idea. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 93 | static final int BACKUP_APP_ADJ = 300; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 94 | |
| 95 | // This is a process only hosting components that are perceptible to the |
| 96 | // user, and we really want to avoid killing them, but they are not |
Dianne Hackborn | e02c88a | 2011-10-28 13:58:15 -0700 | [diff] [blame] | 97 | // immediately visible. An example is background music playback. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 98 | static final int PERCEPTIBLE_APP_ADJ = 200; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 99 | |
| 100 | // This is a process only hosting activities that are visible to the |
Dianne Hackborn | e02c88a | 2011-10-28 13:58:15 -0700 | [diff] [blame] | 101 | // user, so we'd prefer they don't disappear. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 102 | static final int VISIBLE_APP_ADJ = 100; |
| 103 | static final int VISIBLE_APP_LAYER_MAX = PERCEPTIBLE_APP_ADJ - VISIBLE_APP_ADJ - 1; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 104 | |
| 105 | // This is the process running the current foreground app. We'd really |
Dianne Hackborn | e02c88a | 2011-10-28 13:58:15 -0700 | [diff] [blame] | 106 | // rather not kill it! |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 107 | static final int FOREGROUND_APP_ADJ = 0; |
| 108 | |
Dianne Hackborn | ce09f5a | 2014-10-10 15:03:13 -0700 | [diff] [blame] | 109 | // This is a process that the system or a persistent process has bound to, |
| 110 | // and indicated it is important. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 111 | static final int PERSISTENT_SERVICE_ADJ = -700; |
Dianne Hackborn | ce09f5a | 2014-10-10 15:03:13 -0700 | [diff] [blame] | 112 | |
Dianne Hackborn | e02c88a | 2011-10-28 13:58:15 -0700 | [diff] [blame] | 113 | // This is a system persistent process, such as telephony. Definitely |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 114 | // don't want to kill it, but doing so is not completely fatal. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 115 | static final int PERSISTENT_PROC_ADJ = -800; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 116 | |
| 117 | // The system process runs at the default adjustment. |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 118 | static final int SYSTEM_ADJ = -900; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 119 | |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 120 | // Special code for native processes that are not being managed by the system (so |
| 121 | // don't have an oom adj assigned by the system). |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 122 | static final int NATIVE_ADJ = -1000; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 123 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 124 | // Memory pages are 4K. |
| 125 | static final int PAGE_SIZE = 4*1024; |
| 126 | |
Dianne Hackborn | a49ad09 | 2016-03-03 13:39:10 -0800 | [diff] [blame] | 127 | // Activity manager's version of Process.THREAD_GROUP_BG_NONINTERACTIVE |
| 128 | static final int SCHED_GROUP_BACKGROUND = 0; |
| 129 | // Activity manager's version of Process.THREAD_GROUP_DEFAULT |
| 130 | static final int SCHED_GROUP_DEFAULT = 1; |
| 131 | // Activity manager's version of Process.THREAD_GROUP_TOP_APP |
| 132 | static final int SCHED_GROUP_TOP_APP = 2; |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 133 | // Activity manager's version of Process.THREAD_GROUP_TOP_APP |
| 134 | // Disambiguate between actual top app and processes bound to the top app |
| 135 | static final int SCHED_GROUP_TOP_APP_BOUND = 3; |
Dianne Hackborn | a49ad09 | 2016-03-03 13:39:10 -0800 | [diff] [blame] | 136 | |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 137 | // The minimum number of cached apps we want to be able to keep around, |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 138 | // without empty apps being able to push them out of memory. |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 139 | static final int MIN_CACHED_APPS = 2; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 140 | |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 141 | // We allow empty processes to stick around for at most 30 minutes. |
| 142 | static final long MAX_EMPTY_TIME = 30*60*1000; |
| 143 | |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 144 | // Threshold of number of cached+empty where we consider memory critical. |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 145 | static final int TRIM_CRITICAL_THRESHOLD = 3; |
| 146 | |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 147 | // Threshold of number of cached+empty where we consider memory critical. |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 148 | static final int TRIM_LOW_THRESHOLD = 5; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 149 | |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 150 | // Low Memory Killer Daemon command codes. |
| 151 | // These must be kept in sync with the definitions in lmkd.c |
| 152 | // |
| 153 | // LMK_TARGET <minfree> <minkillprio> ... (up to 6 pairs) |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 154 | // LMK_PROCPRIO <pid> <uid> <prio> |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 155 | // LMK_PROCREMOVE <pid> |
| 156 | static final byte LMK_TARGET = 0; |
| 157 | static final byte LMK_PROCPRIO = 1; |
| 158 | static final byte LMK_PROCREMOVE = 2; |
| 159 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 160 | // These are the various interesting memory levels that we will give to |
| 161 | // the OOM killer. Note that the OOM killer only supports 6 slots, so we |
| 162 | // can't give it a different value for every possible kind of process. |
| 163 | private final int[] mOomAdj = new int[] { |
| 164 | FOREGROUND_APP_ADJ, VISIBLE_APP_ADJ, PERCEPTIBLE_APP_ADJ, |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 165 | BACKUP_APP_ADJ, CACHED_APP_MIN_ADJ, CACHED_APP_MAX_ADJ |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 166 | }; |
| 167 | // These are the low-end OOM level limits. This is appropriate for an |
| 168 | // HVGA or smaller phone with less than 512MB. Values are in KB. |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 169 | private final int[] mOomMinFreeLow = new int[] { |
Dianne Hackborn | 3f16dd4 | 2014-10-02 17:21:27 -0700 | [diff] [blame] | 170 | 12288, 18432, 24576, |
| 171 | 36864, 43008, 49152 |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 172 | }; |
| 173 | // These are the high-end OOM level limits. This is appropriate for a |
| 174 | // 1280x800 or larger screen with around 1GB RAM. Values are in KB. |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 175 | private final int[] mOomMinFreeHigh = new int[] { |
Dianne Hackborn | 3f16dd4 | 2014-10-02 17:21:27 -0700 | [diff] [blame] | 176 | 73728, 92160, 110592, |
Dianne Hackborn | 824aeab | 2014-11-25 17:26:36 -0800 | [diff] [blame] | 177 | 129024, 147456, 184320 |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 178 | }; |
| 179 | // The actual OOM killer memory levels we are using. |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 180 | private final int[] mOomMinFree = new int[mOomAdj.length]; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 181 | |
| 182 | private final long mTotalMemMb; |
| 183 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 184 | private long mCachedRestoreLevel; |
| 185 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 186 | private boolean mHaveDisplaySize; |
| 187 | |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 188 | private static LocalSocket sLmkdSocket; |
| 189 | private static OutputStream sLmkdOutputStream; |
| 190 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 191 | ProcessList() { |
| 192 | MemInfoReader minfo = new MemInfoReader(); |
| 193 | minfo.readMemInfo(); |
| 194 | mTotalMemMb = minfo.getTotalSize()/(1024*1024); |
| 195 | updateOomLevels(0, 0, false); |
| 196 | } |
| 197 | |
| 198 | void applyDisplaySize(WindowManagerService wm) { |
| 199 | if (!mHaveDisplaySize) { |
| 200 | Point p = new Point(); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 201 | // TODO(multi-display): Compute based on sum of all connected displays' resolutions. |
Colin Cross | 637dbfc | 2013-07-18 17:15:15 -0700 | [diff] [blame] | 202 | wm.getBaseDisplaySize(Display.DEFAULT_DISPLAY, p); |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 203 | if (p.x != 0 && p.y != 0) { |
| 204 | updateOomLevels(p.x, p.y, true); |
| 205 | mHaveDisplaySize = true; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | private void updateOomLevels(int displayWidth, int displayHeight, boolean write) { |
| 211 | // Scale buckets from avail memory: at 300MB we use the lowest values to |
| 212 | // 700MB or more for the top values. |
Dianne Hackborn | 824aeab | 2014-11-25 17:26:36 -0800 | [diff] [blame] | 213 | float scaleMem = ((float)(mTotalMemMb-350))/(700-350); |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 214 | |
| 215 | // Scale buckets from screen size. |
Dianne Hackborn | 635a6d5 | 2013-07-29 17:15:38 -0700 | [diff] [blame] | 216 | int minSize = 480*800; // 384000 |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 217 | int maxSize = 1280*800; // 1024000 230400 870400 .264 |
| 218 | float scaleDisp = ((float)(displayWidth*displayHeight)-minSize)/(maxSize-minSize); |
Dianne Hackborn | 635a6d5 | 2013-07-29 17:15:38 -0700 | [diff] [blame] | 219 | if (false) { |
| 220 | Slog.i("XXXXXX", "scaleMem=" + scaleMem); |
| 221 | Slog.i("XXXXXX", "scaleDisp=" + scaleDisp + " dw=" + displayWidth |
| 222 | + " dh=" + displayHeight); |
| 223 | } |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 224 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 225 | float scale = scaleMem > scaleDisp ? scaleMem : scaleDisp; |
| 226 | if (scale < 0) scale = 0; |
| 227 | else if (scale > 1) scale = 1; |
Dianne Hackborn | 635a6d5 | 2013-07-29 17:15:38 -0700 | [diff] [blame] | 228 | int minfree_adj = Resources.getSystem().getInteger( |
| 229 | com.android.internal.R.integer.config_lowMemoryKillerMinFreeKbytesAdjust); |
| 230 | int minfree_abs = Resources.getSystem().getInteger( |
| 231 | com.android.internal.R.integer.config_lowMemoryKillerMinFreeKbytesAbsolute); |
| 232 | if (false) { |
| 233 | Slog.i("XXXXXX", "minfree_adj=" + minfree_adj + " minfree_abs=" + minfree_abs); |
| 234 | } |
Colin Cross | fcdad6f | 2013-07-25 15:04:40 -0700 | [diff] [blame] | 235 | |
Dianne Hackborn | c478cf5 | 2015-01-05 16:05:05 -0800 | [diff] [blame] | 236 | final boolean is64bit = Build.SUPPORTED_64_BIT_ABIS.length > 0; |
Dianne Hackborn | 9d52f79 | 2014-09-11 17:46:06 -0700 | [diff] [blame] | 237 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 238 | for (int i=0; i<mOomAdj.length; i++) { |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 239 | int low = mOomMinFreeLow[i]; |
| 240 | int high = mOomMinFreeHigh[i]; |
Dianne Hackborn | c478cf5 | 2015-01-05 16:05:05 -0800 | [diff] [blame] | 241 | if (is64bit) { |
| 242 | // Increase the high min-free levels for cached processes for 64-bit |
| 243 | if (i == 4) high = (high*3)/2; |
| 244 | else if (i == 5) high = (high*7)/4; |
| 245 | } |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 246 | mOomMinFree[i] = (int)(low + ((high-low)*scale)); |
Colin Cross | fcdad6f | 2013-07-25 15:04:40 -0700 | [diff] [blame] | 247 | } |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 248 | |
Colin Cross | fcdad6f | 2013-07-25 15:04:40 -0700 | [diff] [blame] | 249 | if (minfree_abs >= 0) { |
| 250 | for (int i=0; i<mOomAdj.length; i++) { |
Dianne Hackborn | 9d52f79 | 2014-09-11 17:46:06 -0700 | [diff] [blame] | 251 | mOomMinFree[i] = (int)((float)minfree_abs * mOomMinFree[i] |
| 252 | / mOomMinFree[mOomAdj.length - 1]); |
Colin Cross | fcdad6f | 2013-07-25 15:04:40 -0700 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | if (minfree_adj != 0) { |
| 257 | for (int i=0; i<mOomAdj.length; i++) { |
Dianne Hackborn | 9d52f79 | 2014-09-11 17:46:06 -0700 | [diff] [blame] | 258 | mOomMinFree[i] += (int)((float)minfree_adj * mOomMinFree[i] |
| 259 | / mOomMinFree[mOomAdj.length - 1]); |
Colin Cross | fcdad6f | 2013-07-25 15:04:40 -0700 | [diff] [blame] | 260 | if (mOomMinFree[i] < 0) { |
| 261 | mOomMinFree[i] = 0; |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 266 | // The maximum size we will restore a process from cached to background, when under |
| 267 | // memory duress, is 1/3 the size we have reserved for kernel caches and other overhead |
| 268 | // before killing background processes. |
| 269 | mCachedRestoreLevel = (getMemLevel(ProcessList.CACHED_APP_MAX_ADJ)/1024) / 3; |
| 270 | |
Colin Cross | 59d80a5 | 2013-07-25 10:45:05 -0700 | [diff] [blame] | 271 | // Ask the kernel to try to keep enough memory free to allocate 3 full |
| 272 | // screen 32bpp buffers without entering direct reclaim. |
| 273 | int reserve = displayWidth * displayHeight * 4 * 3 / 1024; |
| 274 | int reserve_adj = Resources.getSystem().getInteger(com.android.internal.R.integer.config_extraFreeKbytesAdjust); |
| 275 | int reserve_abs = Resources.getSystem().getInteger(com.android.internal.R.integer.config_extraFreeKbytesAbsolute); |
| 276 | |
| 277 | if (reserve_abs >= 0) { |
| 278 | reserve = reserve_abs; |
| 279 | } |
| 280 | |
| 281 | if (reserve_adj != 0) { |
| 282 | reserve += reserve_adj; |
| 283 | if (reserve < 0) { |
| 284 | reserve = 0; |
| 285 | } |
| 286 | } |
| 287 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 288 | if (write) { |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 289 | ByteBuffer buf = ByteBuffer.allocate(4 * (2*mOomAdj.length + 1)); |
| 290 | buf.putInt(LMK_TARGET); |
| 291 | for (int i=0; i<mOomAdj.length; i++) { |
| 292 | buf.putInt((mOomMinFree[i]*1024)/PAGE_SIZE); |
| 293 | buf.putInt(mOomAdj[i]); |
| 294 | } |
| 295 | |
| 296 | writeLmkd(buf); |
Colin Cross | 59d80a5 | 2013-07-25 10:45:05 -0700 | [diff] [blame] | 297 | SystemProperties.set("sys.sysctl.extra_free_kbytes", Integer.toString(reserve)); |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 298 | } |
| 299 | // GB: 2048,3072,4096,6144,7168,8192 |
| 300 | // HC: 8192,10240,12288,14336,16384,20480 |
| 301 | } |
| 302 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 303 | public static int computeEmptyProcessLimit(int totalProcessLimit) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 304 | return totalProcessLimit/2; |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 307 | private static String buildOomTag(String prefix, String space, int val, int base) { |
| 308 | if (val == base) { |
| 309 | if (space == null) return prefix; |
| 310 | return prefix + " "; |
| 311 | } |
| 312 | return prefix + "+" + Integer.toString(val-base); |
| 313 | } |
| 314 | |
| 315 | public static String makeOomAdjString(int setAdj) { |
| 316 | if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) { |
| 317 | return buildOomTag("cch", " ", setAdj, ProcessList.CACHED_APP_MIN_ADJ); |
| 318 | } else if (setAdj >= ProcessList.SERVICE_B_ADJ) { |
| 319 | return buildOomTag("svcb ", null, setAdj, ProcessList.SERVICE_B_ADJ); |
| 320 | } else if (setAdj >= ProcessList.PREVIOUS_APP_ADJ) { |
| 321 | return buildOomTag("prev ", null, setAdj, ProcessList.PREVIOUS_APP_ADJ); |
| 322 | } else if (setAdj >= ProcessList.HOME_APP_ADJ) { |
| 323 | return buildOomTag("home ", null, setAdj, ProcessList.HOME_APP_ADJ); |
| 324 | } else if (setAdj >= ProcessList.SERVICE_ADJ) { |
| 325 | return buildOomTag("svc ", null, setAdj, ProcessList.SERVICE_ADJ); |
| 326 | } else if (setAdj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) { |
| 327 | return buildOomTag("hvy ", null, setAdj, ProcessList.HEAVY_WEIGHT_APP_ADJ); |
| 328 | } else if (setAdj >= ProcessList.BACKUP_APP_ADJ) { |
| 329 | return buildOomTag("bkup ", null, setAdj, ProcessList.BACKUP_APP_ADJ); |
| 330 | } else if (setAdj >= ProcessList.PERCEPTIBLE_APP_ADJ) { |
| 331 | return buildOomTag("prcp ", null, setAdj, ProcessList.PERCEPTIBLE_APP_ADJ); |
| 332 | } else if (setAdj >= ProcessList.VISIBLE_APP_ADJ) { |
| 333 | return buildOomTag("vis ", null, setAdj, ProcessList.VISIBLE_APP_ADJ); |
| 334 | } else if (setAdj >= ProcessList.FOREGROUND_APP_ADJ) { |
| 335 | return buildOomTag("fore ", null, setAdj, ProcessList.FOREGROUND_APP_ADJ); |
Dianne Hackborn | ce09f5a | 2014-10-10 15:03:13 -0700 | [diff] [blame] | 336 | } else if (setAdj >= ProcessList.PERSISTENT_SERVICE_ADJ) { |
| 337 | return buildOomTag("psvc ", null, setAdj, ProcessList.PERSISTENT_SERVICE_ADJ); |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 338 | } else if (setAdj >= ProcessList.PERSISTENT_PROC_ADJ) { |
| 339 | return buildOomTag("pers ", null, setAdj, ProcessList.PERSISTENT_PROC_ADJ); |
| 340 | } else if (setAdj >= ProcessList.SYSTEM_ADJ) { |
| 341 | return buildOomTag("sys ", null, setAdj, ProcessList.SYSTEM_ADJ); |
| 342 | } else if (setAdj >= ProcessList.NATIVE_ADJ) { |
| 343 | return buildOomTag("ntv ", null, setAdj, ProcessList.NATIVE_ADJ); |
| 344 | } else { |
| 345 | return Integer.toString(setAdj); |
| 346 | } |
| 347 | } |
| 348 | |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 349 | public static String makeProcStateString(int curProcState) { |
| 350 | String procState; |
| 351 | switch (curProcState) { |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 352 | case ActivityManager.PROCESS_STATE_PERSISTENT: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 353 | procState = "PER "; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 354 | break; |
| 355 | case ActivityManager.PROCESS_STATE_PERSISTENT_UI: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 356 | procState = "PERU"; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 357 | break; |
| 358 | case ActivityManager.PROCESS_STATE_TOP: |
Dianne Hackborn | f4dd371 | 2017-05-11 17:25:23 -0700 | [diff] [blame] | 359 | procState = "TOP "; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 360 | break; |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 361 | case ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 362 | procState = "BFGS"; |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 363 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 364 | case ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 365 | procState = "FGS "; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 366 | break; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 367 | case ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 368 | procState = "IMPF"; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 369 | break; |
| 370 | case ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 371 | procState = "IMPB"; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 372 | break; |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 373 | case ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND: |
| 374 | procState = "TRNB"; |
| 375 | break; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 376 | case ActivityManager.PROCESS_STATE_BACKUP: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 377 | procState = "BKUP"; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 378 | break; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 379 | case ActivityManager.PROCESS_STATE_SERVICE: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 380 | procState = "SVC "; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 381 | break; |
| 382 | case ActivityManager.PROCESS_STATE_RECEIVER: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 383 | procState = "RCVR"; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 384 | break; |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 385 | case ActivityManager.PROCESS_STATE_TOP_SLEEPING: |
| 386 | procState = "TPSL"; |
| 387 | break; |
Dianne Hackborn | f097d42 | 2017-12-15 16:32:19 -0800 | [diff] [blame] | 388 | case ActivityManager.PROCESS_STATE_HEAVY_WEIGHT: |
| 389 | procState = "HVY "; |
| 390 | break; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 391 | case ActivityManager.PROCESS_STATE_HOME: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 392 | procState = "HOME"; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 393 | break; |
| 394 | case ActivityManager.PROCESS_STATE_LAST_ACTIVITY: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 395 | procState = "LAST"; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 396 | break; |
| 397 | case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 398 | procState = "CAC "; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 399 | break; |
| 400 | case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 401 | procState = "CACC"; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 402 | break; |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 403 | case ActivityManager.PROCESS_STATE_CACHED_RECENT: |
| 404 | procState = "CRE "; |
| 405 | break; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 406 | case ActivityManager.PROCESS_STATE_CACHED_EMPTY: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 407 | procState = "CEM "; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 408 | break; |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 409 | case ActivityManager.PROCESS_STATE_NONEXISTENT: |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 410 | procState = "NONE"; |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 411 | break; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 412 | default: |
| 413 | procState = "??"; |
| 414 | break; |
| 415 | } |
| 416 | return procState; |
| 417 | } |
| 418 | |
| 419 | public static void appendRamKb(StringBuilder sb, long ramKb) { |
| 420 | for (int j=0, fact=10; j<6; j++, fact*=10) { |
| 421 | if (ramKb < fact) { |
| 422 | sb.append(' '); |
| 423 | } |
| 424 | } |
| 425 | sb.append(ramKb); |
| 426 | } |
| 427 | |
Dianne Hackborn | ae6cc8a | 2014-12-10 10:33:27 -0800 | [diff] [blame] | 428 | // How long after a state change that it is safe to collect PSS without it being dirty. |
| 429 | public static final int PSS_SAFE_TIME_FROM_STATE_CHANGE = 1000; |
| 430 | |
| 431 | // The minimum time interval after a state change it is safe to collect PSS. |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 432 | public static final int PSS_MIN_TIME_FROM_STATE_CHANGE = 15*1000; |
| 433 | |
| 434 | // The maximum amount of time we want to go between PSS collections. |
| 435 | public static final int PSS_MAX_INTERVAL = 30*60*1000; |
| 436 | |
| 437 | // The minimum amount of time between successive PSS requests for *all* processes. |
| 438 | public static final int PSS_ALL_INTERVAL = 10*60*1000; |
| 439 | |
| 440 | // The minimum amount of time between successive PSS requests for a process. |
| 441 | private static final int PSS_SHORT_INTERVAL = 2*60*1000; |
| 442 | |
| 443 | // The amount of time until PSS when a process first becomes top. |
| 444 | private static final int PSS_FIRST_TOP_INTERVAL = 10*1000; |
| 445 | |
| 446 | // The amount of time until PSS when a process first goes into the background. |
| 447 | private static final int PSS_FIRST_BACKGROUND_INTERVAL = 20*1000; |
| 448 | |
| 449 | // The amount of time until PSS when a process first becomes cached. |
| 450 | private static final int PSS_FIRST_CACHED_INTERVAL = 30*1000; |
| 451 | |
| 452 | // The amount of time until PSS when an important process stays in the same state. |
| 453 | private static final int PSS_SAME_IMPORTANT_INTERVAL = 15*60*1000; |
| 454 | |
| 455 | // The amount of time until PSS when a service process stays in the same state. |
| 456 | private static final int PSS_SAME_SERVICE_INTERVAL = 20*60*1000; |
| 457 | |
| 458 | // The amount of time until PSS when a cached process stays in the same state. |
| 459 | private static final int PSS_SAME_CACHED_INTERVAL = 30*60*1000; |
| 460 | |
Dianne Hackborn | ae6cc8a | 2014-12-10 10:33:27 -0800 | [diff] [blame] | 461 | // The minimum time interval after a state change it is safe to collect PSS. |
| 462 | public static final int PSS_TEST_MIN_TIME_FROM_STATE_CHANGE = 10*1000; |
| 463 | |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 464 | // The amount of time during testing until PSS when a process first becomes top. |
| 465 | private static final int PSS_TEST_FIRST_TOP_INTERVAL = 3*1000; |
| 466 | |
| 467 | // The amount of time during testing until PSS when a process first goes into the background. |
| 468 | private static final int PSS_TEST_FIRST_BACKGROUND_INTERVAL = 5*1000; |
| 469 | |
| 470 | // The amount of time during testing until PSS when an important process stays in same state. |
| 471 | private static final int PSS_TEST_SAME_IMPORTANT_INTERVAL = 10*1000; |
| 472 | |
| 473 | // The amount of time during testing until PSS when a background process stays in same state. |
| 474 | private static final int PSS_TEST_SAME_BACKGROUND_INTERVAL = 15*1000; |
| 475 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 476 | public static final int PROC_MEM_PERSISTENT = 0; |
| 477 | public static final int PROC_MEM_TOP = 1; |
| 478 | public static final int PROC_MEM_IMPORTANT = 2; |
| 479 | public static final int PROC_MEM_SERVICE = 3; |
| 480 | public static final int PROC_MEM_CACHED = 4; |
| 481 | |
| 482 | private static final int[] sProcStateToProcMem = new int[] { |
| 483 | PROC_MEM_PERSISTENT, // ActivityManager.PROCESS_STATE_PERSISTENT |
| 484 | PROC_MEM_PERSISTENT, // ActivityManager.PROCESS_STATE_PERSISTENT_UI |
| 485 | PROC_MEM_TOP, // ActivityManager.PROCESS_STATE_TOP |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 486 | PROC_MEM_IMPORTANT, // ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 487 | PROC_MEM_IMPORTANT, // ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 488 | PROC_MEM_IMPORTANT, // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND |
| 489 | PROC_MEM_IMPORTANT, // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 490 | PROC_MEM_IMPORTANT, // ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 491 | PROC_MEM_IMPORTANT, // ActivityManager.PROCESS_STATE_BACKUP |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 492 | PROC_MEM_SERVICE, // ActivityManager.PROCESS_STATE_SERVICE |
| 493 | PROC_MEM_CACHED, // ActivityManager.PROCESS_STATE_RECEIVER |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 494 | PROC_MEM_TOP, // ActivityManager.PROCESS_STATE_TOP_SLEEPING |
Dianne Hackborn | f097d42 | 2017-12-15 16:32:19 -0800 | [diff] [blame] | 495 | PROC_MEM_IMPORTANT, // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 496 | PROC_MEM_CACHED, // ActivityManager.PROCESS_STATE_HOME |
| 497 | PROC_MEM_CACHED, // ActivityManager.PROCESS_STATE_LAST_ACTIVITY |
| 498 | PROC_MEM_CACHED, // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY |
| 499 | PROC_MEM_CACHED, // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 500 | PROC_MEM_CACHED, // ActivityManager.PROCESS_STATE_CACHED_RECENT |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 501 | PROC_MEM_CACHED, // ActivityManager.PROCESS_STATE_CACHED_EMPTY |
| 502 | }; |
| 503 | |
| 504 | private static final long[] sFirstAwakePssTimes = new long[] { |
| 505 | PSS_SHORT_INTERVAL, // ActivityManager.PROCESS_STATE_PERSISTENT |
| 506 | PSS_SHORT_INTERVAL, // ActivityManager.PROCESS_STATE_PERSISTENT_UI |
| 507 | PSS_FIRST_TOP_INTERVAL, // ActivityManager.PROCESS_STATE_TOP |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 508 | PSS_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 509 | PSS_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 510 | PSS_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND |
| 511 | PSS_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 512 | PSS_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 513 | PSS_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_BACKUP |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 514 | PSS_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_SERVICE |
| 515 | PSS_FIRST_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_RECEIVER |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 516 | PSS_FIRST_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_TOP_SLEEPING |
| 517 | PSS_FIRST_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 518 | PSS_FIRST_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_HOME |
| 519 | PSS_FIRST_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_LAST_ACTIVITY |
| 520 | PSS_FIRST_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY |
| 521 | PSS_FIRST_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 522 | PSS_FIRST_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_RECENT |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 523 | PSS_FIRST_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_EMPTY |
| 524 | }; |
| 525 | |
| 526 | private static final long[] sSameAwakePssTimes = new long[] { |
| 527 | PSS_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_PERSISTENT |
| 528 | PSS_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_PERSISTENT_UI |
| 529 | PSS_SHORT_INTERVAL, // ActivityManager.PROCESS_STATE_TOP |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 530 | PSS_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 531 | PSS_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 532 | PSS_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND |
| 533 | PSS_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 534 | PSS_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 535 | PSS_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_BACKUP |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 536 | PSS_SAME_SERVICE_INTERVAL, // ActivityManager.PROCESS_STATE_SERVICE |
| 537 | PSS_SAME_SERVICE_INTERVAL, // ActivityManager.PROCESS_STATE_RECEIVER |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 538 | PSS_SAME_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_TOP_SLEEPING |
| 539 | PSS_SAME_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 540 | PSS_SAME_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_HOME |
| 541 | PSS_SAME_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_LAST_ACTIVITY |
| 542 | PSS_SAME_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY |
| 543 | PSS_SAME_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 544 | PSS_SAME_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_RECENT |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 545 | PSS_SAME_CACHED_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_EMPTY |
| 546 | }; |
| 547 | |
Dianne Hackborn | f097d42 | 2017-12-15 16:32:19 -0800 | [diff] [blame] | 548 | private static final long[] sTestFirstPssTimes = new long[] { |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 549 | PSS_TEST_FIRST_TOP_INTERVAL, // ActivityManager.PROCESS_STATE_PERSISTENT |
| 550 | PSS_TEST_FIRST_TOP_INTERVAL, // ActivityManager.PROCESS_STATE_PERSISTENT_UI |
| 551 | PSS_TEST_FIRST_TOP_INTERVAL, // ActivityManager.PROCESS_STATE_TOP |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 552 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE |
| 553 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 554 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND |
| 555 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 556 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 557 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_BACKUP |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 558 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_SERVICE |
| 559 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_RECEIVER |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 560 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_TOP_SLEEPING |
Dianne Hackborn | f097d42 | 2017-12-15 16:32:19 -0800 | [diff] [blame] | 561 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 562 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_HOME |
| 563 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_LAST_ACTIVITY |
| 564 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY |
| 565 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 566 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_RECENT |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 567 | PSS_TEST_FIRST_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_EMPTY |
| 568 | }; |
| 569 | |
Dianne Hackborn | f097d42 | 2017-12-15 16:32:19 -0800 | [diff] [blame] | 570 | private static final long[] sTestSamePssTimes = new long[] { |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 571 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_PERSISTENT |
| 572 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_PERSISTENT_UI |
| 573 | PSS_TEST_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_TOP |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 574 | PSS_TEST_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 575 | PSS_TEST_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 576 | PSS_TEST_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND |
| 577 | PSS_TEST_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 578 | PSS_TEST_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 579 | PSS_TEST_SAME_IMPORTANT_INTERVAL, // ActivityManager.PROCESS_STATE_BACKUP |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 580 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_SERVICE |
| 581 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_RECEIVER |
Dianne Hackborn | bad8d91 | 2017-12-18 16:45:52 -0800 | [diff] [blame] | 582 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_TOP_SLEEPING |
| 583 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 584 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_HOME |
| 585 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_LAST_ACTIVITY |
| 586 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY |
| 587 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 588 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_RECENT |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 589 | PSS_TEST_SAME_BACKGROUND_INTERVAL, // ActivityManager.PROCESS_STATE_CACHED_EMPTY |
| 590 | }; |
| 591 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 592 | public static boolean procStatesDifferForMem(int procState1, int procState2) { |
| 593 | return sProcStateToProcMem[procState1] != sProcStateToProcMem[procState2]; |
| 594 | } |
| 595 | |
Dianne Hackborn | ae6cc8a | 2014-12-10 10:33:27 -0800 | [diff] [blame] | 596 | public static long minTimeFromStateChange(boolean test) { |
| 597 | return test ? PSS_TEST_MIN_TIME_FROM_STATE_CHANGE : PSS_MIN_TIME_FROM_STATE_CHANGE; |
| 598 | } |
| 599 | |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 600 | public static long computeNextPssTime(int procState, boolean first, boolean test, |
| 601 | boolean sleeping, long now) { |
| 602 | final long[] table = test |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 603 | ? (first |
Dianne Hackborn | f097d42 | 2017-12-15 16:32:19 -0800 | [diff] [blame] | 604 | ? sTestFirstPssTimes |
| 605 | : sTestSamePssTimes) |
Dianne Hackborn | f1cca18 | 2013-08-01 10:50:28 -0700 | [diff] [blame] | 606 | : (first |
| 607 | ? sFirstAwakePssTimes |
| 608 | : sSameAwakePssTimes); |
| 609 | return now + table[procState]; |
| 610 | } |
| 611 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 612 | long getMemLevel(int adjustment) { |
| 613 | for (int i=0; i<mOomAdj.length; i++) { |
| 614 | if (adjustment <= mOomAdj[i]) { |
| 615 | return mOomMinFree[i] * 1024; |
| 616 | } |
| 617 | } |
| 618 | return mOomMinFree[mOomAdj.length-1] * 1024; |
| 619 | } |
| 620 | |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 621 | /** |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 622 | * Return the maximum pss size in kb that we consider a process acceptable to |
| 623 | * restore from its cached state for running in the background when RAM is low. |
| 624 | */ |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 625 | long getCachedRestoreThresholdKb() { |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 626 | return mCachedRestoreLevel; |
| 627 | } |
| 628 | |
Dianne Hackborn | 9bef5b6 | 2013-09-20 10:40:34 -0700 | [diff] [blame] | 629 | /** |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 630 | * Set the out-of-memory badness adjustment for a process. |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 631 | * If {@code pid <= 0}, this method will be a no-op. |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 632 | * |
| 633 | * @param pid The process identifier to set. |
Colin Cross | d908edd | 2014-06-13 14:56:04 -0700 | [diff] [blame] | 634 | * @param uid The uid of the app |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 635 | * @param amt Adjustment value -- lmkd allows -16 to +15. |
| 636 | * |
| 637 | * {@hide} |
| 638 | */ |
Colin Cross | d908edd | 2014-06-13 14:56:04 -0700 | [diff] [blame] | 639 | public static final void setOomAdj(int pid, int uid, int amt) { |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 640 | // This indicates that the process is not started yet and so no need to proceed further. |
| 641 | if (pid <= 0) { |
| 642 | return; |
| 643 | } |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 644 | if (amt == UNKNOWN_ADJ) |
| 645 | return; |
| 646 | |
Dianne Hackborn | ecf1cda | 2014-08-28 16:58:28 -0700 | [diff] [blame] | 647 | long start = SystemClock.elapsedRealtime(); |
Colin Cross | d908edd | 2014-06-13 14:56:04 -0700 | [diff] [blame] | 648 | ByteBuffer buf = ByteBuffer.allocate(4 * 4); |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 649 | buf.putInt(LMK_PROCPRIO); |
| 650 | buf.putInt(pid); |
Colin Cross | d908edd | 2014-06-13 14:56:04 -0700 | [diff] [blame] | 651 | buf.putInt(uid); |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 652 | buf.putInt(amt); |
| 653 | writeLmkd(buf); |
Dianne Hackborn | ecf1cda | 2014-08-28 16:58:28 -0700 | [diff] [blame] | 654 | long now = SystemClock.elapsedRealtime(); |
| 655 | if ((now-start) > 250) { |
| 656 | Slog.w("ActivityManager", "SLOW OOM ADJ: " + (now-start) + "ms for pid " + pid |
| 657 | + " = " + amt); |
| 658 | } |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | /* |
| 662 | * {@hide} |
| 663 | */ |
| 664 | public static final void remove(int pid) { |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 665 | // This indicates that the process is not started yet and so no need to proceed further. |
| 666 | if (pid <= 0) { |
| 667 | return; |
| 668 | } |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 669 | ByteBuffer buf = ByteBuffer.allocate(4 * 2); |
| 670 | buf.putInt(LMK_PROCREMOVE); |
| 671 | buf.putInt(pid); |
| 672 | writeLmkd(buf); |
| 673 | } |
| 674 | |
| 675 | private static boolean openLmkdSocket() { |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 676 | try { |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 677 | sLmkdSocket = new LocalSocket(LocalSocket.SOCKET_SEQPACKET); |
| 678 | sLmkdSocket.connect( |
| 679 | new LocalSocketAddress("lmkd", |
| 680 | LocalSocketAddress.Namespace.RESERVED)); |
| 681 | sLmkdOutputStream = sLmkdSocket.getOutputStream(); |
| 682 | } catch (IOException ex) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 683 | Slog.w(TAG, "lowmemorykiller daemon socket open failed"); |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 684 | sLmkdSocket = null; |
| 685 | return false; |
| 686 | } |
| 687 | |
| 688 | return true; |
| 689 | } |
| 690 | |
| 691 | private static void writeLmkd(ByteBuffer buf) { |
| 692 | |
| 693 | for (int i = 0; i < 3; i++) { |
| 694 | if (sLmkdSocket == null) { |
| 695 | if (openLmkdSocket() == false) { |
| 696 | try { |
| 697 | Thread.sleep(1000); |
| 698 | } catch (InterruptedException ie) { |
| 699 | } |
| 700 | continue; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | try { |
| 705 | sLmkdOutputStream.write(buf.array(), 0, buf.position()); |
| 706 | return; |
| 707 | } catch (IOException ex) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 708 | Slog.w(TAG, "Error writing to lowmemorykiller socket"); |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 709 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 710 | try { |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 711 | sLmkdSocket.close(); |
| 712 | } catch (IOException ex2) { |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 713 | } |
Todd Poynor | bfdd623 | 2013-07-10 19:15:07 -0700 | [diff] [blame] | 714 | |
| 715 | sLmkdSocket = null; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | } |
| 719 | } |