diff --git a/core/java/com/android/internal/os/ZygoteConfig.java b/core/java/com/android/internal/os/ZygoteConfig.java index c6af8c2f43164..6ebcae182b111 100644 --- a/core/java/com/android/internal/os/ZygoteConfig.java +++ b/core/java/com/android/internal/os/ZygoteConfig.java @@ -34,4 +34,7 @@ public class ZygoteConfig { /** The minimum number of processes to keep in the USAP pool */ public static final String USAP_POOL_SIZE_MIN = "usap_pool_size_min"; + + /** The number of milliseconds to delay before refilling the USAP pool */ + public static final String USAP_POOL_REFILL_DELAY_MS = "usap_pool_refill_delay_ms"; } diff --git a/core/java/com/android/internal/os/ZygoteServer.java b/core/java/com/android/internal/os/ZygoteServer.java index 7eed9b18486a9..492bc94804fed 100644 --- a/core/java/com/android/internal/os/ZygoteServer.java +++ b/core/java/com/android/internal/os/ZygoteServer.java @@ -66,11 +66,8 @@ class ZygoteServer { /** The default value used for the USAP_POOL_SIZE_MIN device property */ private static final String USAP_POOL_SIZE_MIN_DEFAULT = "1"; - /** - * Number of milliseconds to delay before refilling the pool if it hasn't reached its - * minimum value. - */ - private static final int USAP_REFILL_DELAY_MS = 3000; + /** The default value used for the USAP_REFILL_DELAY_MS device property */ + private static final String USAP_POOL_REFILL_DELAY_MS_DEFAULT = "3000"; /** The "not a timestamp" value for the refill delay timestamp mechanism. */ private static final int INVALID_TIMESTAMP = -1; @@ -140,6 +137,12 @@ class ZygoteServer { */ private int mUsapPoolRefillThreshold = 0; + /** + * Number of milliseconds to delay before refilling the pool if it hasn't reached its + * minimum value. + */ + private int mUsapPoolRefillDelayMs = -1; + private enum UsapPoolRefillAction { DELAYED, IMMEDIATE, @@ -282,6 +285,13 @@ class ZygoteServer { mUsapPoolSizeMax); } + final String usapPoolRefillDelayMsPropString = Zygote.getConfigurationProperty( + ZygoteConfig.USAP_POOL_REFILL_DELAY_MS, USAP_POOL_REFILL_DELAY_MS_DEFAULT); + + if (!usapPoolRefillDelayMsPropString.isEmpty()) { + mUsapPoolRefillDelayMs = Integer.parseInt(usapPoolRefillDelayMsPropString); + } + // Sanity check if (mUsapPoolSizeMin >= mUsapPoolSizeMax) { Log.w(TAG, "The max size of the USAP pool must be greater than the minimum size." @@ -467,13 +477,13 @@ class ZygoteServer { int elapsedTimeMs = (int) (System.currentTimeMillis() - usapPoolRefillTriggerTimestamp); - if (elapsedTimeMs >= USAP_REFILL_DELAY_MS) { + if (elapsedTimeMs >= mUsapPoolRefillDelayMs) { // Normalize the poll timeout value when the time between one poll event and the // next pushes us over the delay value. This prevents poll receiving a 0 // timeout value, which would result in it returning immediately. pollTimeoutMs = -1; } else { - pollTimeoutMs = USAP_REFILL_DELAY_MS - elapsedTimeMs; + pollTimeoutMs = mUsapPoolRefillDelayMs - elapsedTimeMs; } }