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

Commit cbb6b2be authored by Edgar Arriaga's avatar Edgar Arriaga
Browse files

Improve compaction by skipping bad VMAs instead of fully bailing out

Previously when a VMA failed compaction for any reason the system would
stop trying to compact all the rest of the VMAs and bail out. However,
there are multiple reasons that a VMA can fail due to not being
reclaimable with -EINVAL, in such instances we will just skip the VMA
and keep going with the rest of the VMAs and any other error will still
cause compaction to bail out as it would likely be irrecoverable.

Test: Manual. Verified that once a VMA errors with -EINVAL, it continues
with the rest of the VMAs and other errors bail out.
Bug: 205658049

Change-Id: Ifc190e371c4dce0eaa6dbab104aa0b666e06027d
parent eb69f2ea
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -84,6 +84,9 @@ static inline void compactProcessProcfs(int pid, const std::string& compactionTy

// Compacts a set of VMAs for pid using an madviseType accepted by process_madvise syscall
// Returns the total bytes that where madvised.
//
// If any VMA fails compaction due to -EINVAL it will be skipped and continue.
// However, if it fails for any other reason, it will bail out and forward the error
static int64_t compactMemory(const std::vector<Vma>& vmas, int pid, int madviseType) {
    static struct iovec vmasToKernel[MAX_VMAS_PER_COMPACTION];

@@ -148,9 +151,16 @@ static int64_t compactMemory(const std::vector<Vma>& vmas, int pid, int madviseT
        auto bytesProcessed = process_madvise(pidfd, vmasToKernel, iVec, madviseType, 0);

        if (CC_UNLIKELY(bytesProcessed == -1)) {
            if (errno == EINVAL) {
                // This error is somewhat common due to an unevictable VMA if this is
                // the case silently skip the bad VMA and continue compacting the rest.
                continue;
            } else {
                // Forward irrecoverable errors and bail out compaction
                compactionInProgress = false;
                return -errno;
            }
        }

        totalBytesProcessed += bytesProcessed;
    }