Downgrade compactions after throttle checks

This fixes a spammy log issue that happens every time a compaction is
requested independently of whether it would end up being discarded due
to throttles. Further inspection showed that based on the current
throttles moving it to happen post-throttles does not change behavior
as throttles work the same way for some and full compactions

Bug: 232567934
Test: am compact <pid> <uid> full
Change-Id: Ic886f889c5b8670637b9786112d94c6ad666e8bf
This commit is contained in:
Edgar Arriaga
2022-05-11 13:03:50 -07:00
committed by Edgar Arriaga García
parent 7ab7a81845
commit 6b22279c9c

View File

@@ -1223,14 +1223,16 @@ public final class CachedAppOptimizer {
break;
}
// Downgrade compaction if facing swap memory pressure
// Downgrade compaction under swap memory pressure
if (resolvedAction == COMPACT_ACTION_FULL) {
double swapUsagePercent = getFreeSwapPercent();
if (swapUsagePercent < COMPACT_DOWNGRADE_FREE_SWAP_THRESHOLD) {
Slog.d(TAG_AM,
"Downgraded compaction to file only due to low swap."
+ " Swap Free% " + swapUsagePercent);
double swapFreePercent = getFreeSwapPercent();
if (swapFreePercent < COMPACT_DOWNGRADE_FREE_SWAP_THRESHOLD) {
resolvedAction = COMPACT_ACTION_FILE;
if (DEBUG_COMPACTION) {
Slog.d(TAG_AM,
"Downgraded compaction to file only due to low swap."
+ " Swap Free% " + swapFreePercent);
}
}
}
@@ -1445,7 +1447,6 @@ public final class CachedAppOptimizer {
lastCompactTime = opt.getLastCompactTime();
}
int resolvedAction = resolveCompactionAction(requestedAction);
long[] rssBefore;
if (pid == 0) {
// not a real process, either one being launched or one being killed
@@ -1456,17 +1457,17 @@ public final class CachedAppOptimizer {
}
if (!forceCompaction) {
if (shouldOomAdjThrottleCompaction(proc, resolvedAction)) {
if (shouldOomAdjThrottleCompaction(proc, requestedAction)) {
return;
}
if (shouldTimeThrottleCompaction(proc, start, requestedAction)) {
return;
}
if (shouldThrottleMiscCompaction(proc, procState, resolvedAction)) {
if (shouldThrottleMiscCompaction(proc, procState, requestedAction)) {
return;
}
rssBefore = mProcessDependencies.getRss(pid);
if (shouldRssThrottleCompaction(resolvedAction, pid, name, rssBefore)) {
if (shouldRssThrottleCompaction(requestedAction, pid, name, rssBefore)) {
return;
}
} else {
@@ -1494,6 +1495,8 @@ public final class CachedAppOptimizer {
default:
break;
}
int resolvedAction = resolveCompactionAction(requestedAction);
action = compactActionIntToString(resolvedAction);
try {