Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2264f99 authored by Edgar Arriaga's avatar Edgar Arriaga Committed by Edgar Arriaga García
Browse files

Allow compaction non shared and non executable memory mappings

This patch will allow more private memory to be compacted especially
for those read only and read write file mappings that we were
disallowing reduced the restriction of vmas not compacted to only code
and shared pages.

Bug: 286597135
Test: am compact full <pid>
Test: Verify that showmap <pid> shows the swapped vmas after compaction
Change-Id: I223ed3268ce0bdced222b78c3bd08d3e464440ee
parent 81af34b1
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -234,7 +234,8 @@ public final class CachedAppOptimizer {
    private static final int FREEZE_BINDER_TIMEOUT_MS = 100;
    private static final int FREEZE_DEADLOCK_TIMEOUT_MS = 1000;

    @VisibleForTesting static final boolean ENABLE_FILE_COMPACT = false;
    // If enabled, any compaction issued will apply to code mappings and share memory mappings.
    @VisibleForTesting static final boolean ENABLE_SHARED_AND_CODE_COMPACT = false;

    // Defaults for phenotype flags.
    @VisibleForTesting static final Boolean DEFAULT_USE_COMPACTION = true;
@@ -1629,7 +1630,7 @@ public final class CachedAppOptimizer {
            }
        }

        if (!ENABLE_FILE_COMPACT) {
        if (!ENABLE_SHARED_AND_CODE_COMPACT) {
            if (profile == CompactProfile.SOME) {
                profile = CompactProfile.NONE;
            } else if (profile == CompactProfile.FULL) {
+7 −1
Original line number Diff line number Diff line
@@ -333,7 +333,10 @@ static int getFilePageAdvice(const Vma& vma) {
    return -1;
}
static int getAnonPageAdvice(const Vma& vma) {
    if (vma.inode == 0 && !vma.is_shared) {
    bool hasReadFlag = (vma.flags & PROT_READ) > 0;
    bool hasWriteFlag = (vma.flags & PROT_WRITE) > 0;
    bool hasExecuteFlag = (vma.flags & PROT_EXEC) > 0;
    if ((hasReadFlag || hasWriteFlag) && !hasExecuteFlag && !vma.is_shared) {
        return MADV_PAGEOUT;
    }
    return -1;
@@ -376,6 +379,9 @@ static int64_t compactProcess(int pid, VmaToAdviseFunc vmaToAdviseFunc) {
                ++coldVmaIndex;
                break;
            case MADV_PAGEOUT:
#ifdef DEBUG_COMPACTION
                ALOGE("Adding to compact vma=%s", vma.name.c_str());
#endif
                if (pageoutVmaIndex < pageoutVmas.size()) {
                    pageoutVmas[pageoutVmaIndex] = vma;
                } else {
+1 −1
Original line number Diff line number Diff line
@@ -969,7 +969,7 @@ public final class CachedAppOptimizerTest {

        mCachedAppOptimizerUnderTest.mLastCompactionStats.clear();

        if (CachedAppOptimizer.ENABLE_FILE_COMPACT) {
        if (CachedAppOptimizer.ENABLE_SHARED_AND_CODE_COMPACT) {
            // We force a some compaction
            mCachedAppOptimizerUnderTest.compactApp(processRecord,
                    CachedAppOptimizer.CompactProfile.SOME, CachedAppOptimizer.CompactSource.APP,