RESTRICT AUTOMERGE: Disable file compaction by default

At present time kernel does not support shared pages to be
swapped using file compaction which uses MADV_COLD and most
of the file pages in a process are actually shared mappings
causing us to waste a lot of cycles scanning through a lot
of unreclaimable pages, this patch disables file compaction
which will be reenabled until a solution is implemented on
upstream kernel that allows reclaiming shared pages, thus
making it worth to scan all of those pages again.

Test: am compact file <processname> <uid>
Bug: 265473345
Change-Id: I4c819058da229c00d1eafea636f89784718adc5f
(cherry picked from commit 30b069612a)
This commit is contained in:
Edgar Arriaga
2023-01-13 22:24:33 +00:00
parent 3ac452b39d
commit 854e613a67
2 changed files with 27 additions and 9 deletions

View File

@@ -110,6 +110,8 @@ public final class CachedAppOptimizer {
private static final String ATRACE_COMPACTION_TRACK = "Compaction";
@VisibleForTesting static final boolean ENABLE_FILE_COMPACT = false;
// Defaults for phenotype flags.
@VisibleForTesting static final Boolean DEFAULT_USE_COMPACTION = false;
@VisibleForTesting static final Boolean DEFAULT_USE_FREEZER = true;
@@ -515,9 +517,11 @@ public final class CachedAppOptimizer {
@GuardedBy("mProcLock")
void compactAppSome(ProcessRecord app, boolean force) {
app.mOptRecord.setReqCompactAction(COMPACT_PROCESS_SOME);
++mSomeCompactRequest;
compactApp(app, force, "some");
if (ENABLE_FILE_COMPACT) {
app.mOptRecord.setReqCompactAction(COMPACT_PROCESS_SOME);
++mSomeCompactRequest;
compactApp(app, force, "some");
}
}
// This method returns true only if requirements are met. Note, that requirements are different
@@ -1278,6 +1282,15 @@ public final class CachedAppOptimizer {
}
}
if (!ENABLE_FILE_COMPACT) {
// Turn off file compaction
if (resolvedAction == COMPACT_ACTION_FULL) {
resolvedAction = COMPACT_ACTION_ANON;
} else if (resolvedAction == COMPACT_ACTION_FILE) {
resolvedAction = COMPACT_ACTION_NONE;
}
}
return resolvedAction;
}
@@ -1545,6 +1558,9 @@ public final class CachedAppOptimizer {
}
int resolvedAction = resolveCompactionAction(requestedAction);
if (resolvedAction == COMPACT_ACTION_NONE) {
return;
}
action = compactActionIntToString(resolvedAction);
try {

View File

@@ -1079,14 +1079,16 @@ public final class CachedAppOptimizerTest {
mCachedAppOptimizerUnderTest.mLastCompactionStats.clear();
// We force a some compaction
mCachedAppOptimizerUnderTest.compactAppSome(processRecord, true);
waitForHandler();
// then process is compacted.
String executedCompactAction =
if (CachedAppOptimizer.ENABLE_FILE_COMPACT) {
// We force a some compaction
mCachedAppOptimizerUnderTest.compactAppSome(processRecord, true);
waitForHandler();
// then process is compacted.
String executedCompactAction =
compactActionIntToString(processRecord.mOptRecord.getLastCompactAction());
assertThat(executedCompactAction)
assertThat(executedCompactAction)
.isEqualTo(mCachedAppOptimizerUnderTest.mCompactActionSome);
}
}
private void setFlag(String key, String value, boolean defaultValue) throws Exception {