Resets the refill action/timing info after a pool fill event.

Bug: 132794985
Bug: 146614089
Test: m & flash & launch more apps than USAPs in the pool
Change-Id: I9ee74d76692fa8aeba9c70765b3e8f98ea9105bc
Merged-In: I9ee74d76692fa8aeba9c70765b3e8f98ea9105bc
This commit is contained in:
Chris Wailes
2019-05-23 17:41:48 -07:00
parent eabbf8720c
commit b28db4abbc

View File

@@ -143,6 +143,12 @@ class ZygoteServer {
*/
private int mUsapPoolRefillDelayMs = -1;
/**
* If and when we should refill the USAP pool.
*/
private UsapPoolRefillAction mUsapPoolRefillAction;
private long mUsapPoolRefillTriggerTimestamp;
private enum UsapPoolRefillAction {
DELAYED,
IMMEDIATE,
@@ -375,6 +381,8 @@ class ZygoteServer {
// are re-enabled in specializeAppProcess.
ZygoteHooks.postForkCommon();
resetUsapRefillState();
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
return null;
@@ -404,6 +412,11 @@ class ZygoteServer {
}
}
void resetUsapRefillState() {
mUsapPoolRefillAction = UsapPoolRefillAction.NONE;
mUsapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP;
}
/**
* Runs the zygote process's select loop. Accepts new connections as
* they happen, and reads commands from connections one spawn-request's
@@ -416,10 +429,11 @@ class ZygoteServer {
socketFDs.add(mZygoteSocket.getFileDescriptor());
peers.add(null);
long usapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP;
mUsapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP;
while (true) {
fetchUsapPoolPolicyPropsWithMinInterval();
mUsapPoolRefillAction = UsapPoolRefillAction.NONE;
int[] usapPipeFDs = null;
StructPollfd[] pollFDs;
@@ -473,11 +487,11 @@ class ZygoteServer {
int pollTimeoutMs;
if (usapPoolRefillTriggerTimestamp == INVALID_TIMESTAMP) {
if (mUsapPoolRefillTriggerTimestamp == INVALID_TIMESTAMP) {
pollTimeoutMs = -1;
} else {
int elapsedTimeMs =
(int) (System.currentTimeMillis() - usapPoolRefillTriggerTimestamp);
(int) (System.currentTimeMillis() - mUsapPoolRefillTriggerTimestamp);
if (elapsedTimeMs >= mUsapPoolRefillDelayMs) {
// Normalize the poll timeout value when the time between one poll event and the
@@ -496,13 +510,12 @@ class ZygoteServer {
throw new RuntimeException("poll failed", ex);
}
UsapPoolRefillAction usapPoolRefillAction = UsapPoolRefillAction.NONE;
if (pollReturnValue == 0) {
// The poll timeout has been exceeded. This only occurs when we have finished the
// USAP pool refill delay period.
usapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP;
usapPoolRefillAction = UsapPoolRefillAction.DELAYED;
mUsapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP;
mUsapPoolRefillAction = UsapPoolRefillAction.DELAYED;
} else {
boolean usapPoolFDRead = false;
@@ -632,15 +645,15 @@ class ZygoteServer {
if (usapPoolCount < mUsapPoolSizeMin) {
// Immediate refill
usapPoolRefillAction = UsapPoolRefillAction.IMMEDIATE;
mUsapPoolRefillAction = UsapPoolRefillAction.IMMEDIATE;
} else if (mUsapPoolSizeMax - usapPoolCount >= mUsapPoolRefillThreshold) {
// Delayed refill
usapPoolRefillTriggerTimestamp = System.currentTimeMillis();
mUsapPoolRefillTriggerTimestamp = System.currentTimeMillis();
}
}
}
if (usapPoolRefillAction != UsapPoolRefillAction.NONE) {
if (mUsapPoolRefillAction != UsapPoolRefillAction.NONE) {
int[] sessionSocketRawFDs =
socketFDs.subList(1, socketFDs.size())
.stream()
@@ -648,7 +661,7 @@ class ZygoteServer {
.toArray();
final boolean isPriorityRefill =
usapPoolRefillAction == UsapPoolRefillAction.IMMEDIATE;
mUsapPoolRefillAction == UsapPoolRefillAction.IMMEDIATE;
final Runnable command =
fillUsapPool(sessionSocketRawFDs, isPriorityRefill);
@@ -657,7 +670,7 @@ class ZygoteServer {
return command;
} else if (isPriorityRefill) {
// Schedule a delayed refill to finish refilling the pool.
usapPoolRefillTriggerTimestamp = System.currentTimeMillis();
mUsapPoolRefillTriggerTimestamp = System.currentTimeMillis();
}
}
}