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

Commit 7031a84e authored by Divyanand Rangu's avatar Divyanand Rangu Committed by Kalesh Singh
Browse files

Avoid subtracting shmem twice when calculating LOST RAM.

NR_SHMEM is included in both shmem and cached memory of /proc/meminfo.
To avoid double subtraction (since included in kernelUsed and getCachedSizeKb) add shmem to LOST RAM.

Bug: 371518137
Change-Id: I7bdac17c2c952fbb045c0eed9f38a44df2831204
parent da86eed6
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -87,6 +87,13 @@ public final class MemInfoReader {
        return mInfos[Debug.MEMINFO_FREE];
    }

    /**
     * Amount of RAM that used by shared memory (shmem) and tmpfs
     */
    public long getShmemSizeKb() {
        return mInfos[Debug.MEMINFO_SHMEM];
    }

    /**
     * Amount of RAM that the kernel is being used for caches, not counting caches
     * that are mapped in to processes.
+4 −0
Original line number Diff line number Diff line
@@ -13143,6 +13143,8 @@ public class ActivityManagerService extends IActivityManager.Stub
            final long lostRAM = memInfo.getTotalSizeKb()
                    - (ss[INDEX_TOTAL_PSS] - ss[INDEX_TOTAL_SWAP_PSS])
                    - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
                    // NR_SHMEM is subtracted twice (getCachedSizeKb() and getKernelUsedSizeKb())
                    + memInfo.getShmemSizeKb()
                    - kernelUsed - memInfo.getZramTotalSizeKb();
            if (!opts.isCompact) {
                pw.print(" Used RAM: "); pw.print(stringifyKBSize(ss[INDEX_TOTAL_PSS] - cachedPss
@@ -13656,6 +13658,8 @@ public class ActivityManagerService extends IActivityManager.Stub
            long lostRAM = memInfo.getTotalSizeKb()
                    - (ss[INDEX_TOTAL_PSS] - ss[INDEX_TOTAL_SWAP_PSS])
                    - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
                    // NR_SHMEM is subtracted twice (getCachedSizeKb() and getKernelUsedSizeKb())
                    + memInfo.getShmemSizeKb()
                    - memInfo.getKernelUsedSizeKb() - memInfo.getZramTotalSizeKb();
            proto.write(MemInfoDumpProto.USED_PSS_KB, ss[INDEX_TOTAL_PSS] - cachedPss);
            proto.write(MemInfoDumpProto.USED_KERNEL_KB, memInfo.getKernelUsedSizeKb());