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

Commit 2ea2bf28 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android Git Automerger
Browse files

am ed512c81: Merge "Fix issue #17948288: Improve accuracy of memory use reporting" into lmp-mr1-dev

* commit 'ed512c81':
  Fix issue #17948288: Improve accuracy of memory use reporting
parents c97924f4 ed512c81
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -1093,7 +1093,15 @@ href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Lo
    /** @hide */
    /** @hide */
    public static final int MEMINFO_ZRAM_TOTAL = 8;
    public static final int MEMINFO_ZRAM_TOTAL = 8;
    /** @hide */
    /** @hide */
    public static final int MEMINFO_COUNT = 9;
    public static final int MEMINFO_MAPPED = 9;
    /** @hide */
    public static final int MEMINFO_VM_ALLOC_USED = 10;
    /** @hide */
    public static final int MEMINFO_PAGE_TABLES = 11;
    /** @hide */
    public static final int MEMINFO_KERNEL_STACK = 12;
    /** @hide */
    public static final int MEMINFO_COUNT = 13;


    /**
    /**
     * Retrieves /proc/meminfo.  outSizes is filled with fields
     * Retrieves /proc/meminfo.  outSizes is filled with fields
+37 −12
Original line number Original line Diff line number Diff line
@@ -34,40 +34,65 @@ public final class MemInfoReader {
        }
        }
    }
    }


    /**
     * Total amount of RAM available to the kernel.
     */
    public long getTotalSize() {
    public long getTotalSize() {
        return mInfos[Debug.MEMINFO_TOTAL] * 1024;
        return mInfos[Debug.MEMINFO_TOTAL] * 1024;
    }
    }


    /**
     * Amount of RAM that is not being used for anything.
     */
    public long getFreeSize() {
    public long getFreeSize() {
        return mInfos[Debug.MEMINFO_FREE] * 1024;
        return mInfos[Debug.MEMINFO_FREE] * 1024;
    }
    }


    /**
     * Amount of RAM that the kernel is being used for caches, not counting caches
     * that are mapped in to processes.
     */
    public long getCachedSize() {
    public long getCachedSize() {
        return mInfos[Debug.MEMINFO_CACHED] * 1024;
        return getCachedSizeKb() * 1024;
    }
    }


    /**
     * Amount of RAM that is in use by the kernel for actual allocations.
     */
    public long getKernelUsedSize() {
        return getKernelUsedSizeKb() * 1024;
    }

    /**
     * Total amount of RAM available to the kernel.
     */
    public long getTotalSizeKb() {
    public long getTotalSizeKb() {
        return mInfos[Debug.MEMINFO_TOTAL];
        return mInfos[Debug.MEMINFO_TOTAL];
    }
    }


    /**
     * Amount of RAM that is not being used for anything.
     */
    public long getFreeSizeKb() {
    public long getFreeSizeKb() {
        return mInfos[Debug.MEMINFO_FREE];
        return mInfos[Debug.MEMINFO_FREE];
    }
    }


    /**
     * Amount of RAM that the kernel is being used for caches, not counting caches
     * that are mapped in to processes.
     */
    public long getCachedSizeKb() {
    public long getCachedSizeKb() {
        return mInfos[Debug.MEMINFO_CACHED];
        return mInfos[Debug.MEMINFO_BUFFERS]
    }
                + mInfos[Debug.MEMINFO_CACHED] - mInfos[Debug.MEMINFO_MAPPED];

    public long getBuffersSizeKb() {
        return mInfos[Debug.MEMINFO_BUFFERS];
    }
    }


    public long getShmemSizeKb() {
    /**
        return mInfos[Debug.MEMINFO_SHMEM];
     * Amount of RAM that is in use by the kernel for actual allocations.
    }
     */

    public long getKernelUsedSizeKb() {
    public long getSlabSizeKb() {
        return mInfos[Debug.MEMINFO_SHMEM] + mInfos[Debug.MEMINFO_SLAB]
        return mInfos[Debug.MEMINFO_SLAB];
                + mInfos[Debug.MEMINFO_VM_ALLOC_USED] + mInfos[Debug.MEMINFO_PAGE_TABLES]
                + mInfos[Debug.MEMINFO_KERNEL_STACK];
    }
    }


    public long getSwapTotalSizeKb() {
    public long getSwapTotalSizeKb() {
+16 −2
Original line number Original line Diff line number Diff line
@@ -552,6 +552,10 @@ enum {
    MEMINFO_SWAP_TOTAL,
    MEMINFO_SWAP_TOTAL,
    MEMINFO_SWAP_FREE,
    MEMINFO_SWAP_FREE,
    MEMINFO_ZRAM_TOTAL,
    MEMINFO_ZRAM_TOTAL,
    MEMINFO_MAPPED,
    MEMINFO_VMALLOC_USED,
    MEMINFO_PAGE_TABLES,
    MEMINFO_KERNEL_STACK,
    MEMINFO_COUNT
    MEMINFO_COUNT
};
};


@@ -590,6 +594,11 @@ static void android_os_Debug_getMemInfo(JNIEnv *env, jobject clazz, jlongArray o
            "Slab:",
            "Slab:",
            "SwapTotal:",
            "SwapTotal:",
            "SwapFree:",
            "SwapFree:",
            "ZRam:",
            "Mapped:",
            "VmallocUsed:",
            "PageTables:",
            "KernelStack:",
            NULL
            NULL
    };
    };
    static const int tagsLen[] = {
    static const int tagsLen[] = {
@@ -601,12 +610,17 @@ static void android_os_Debug_getMemInfo(JNIEnv *env, jobject clazz, jlongArray o
            5,
            5,
            10,
            10,
            9,
            9,
            5,
            7,
            12,
            11,
            12,
            0
            0
    };
    };
    long mem[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    long mem[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };


    char* p = buffer;
    char* p = buffer;
    while (*p && numFound < 8) {
    while (*p && numFound < 13) {
        int i = 0;
        int i = 0;
        while (tags[i]) {
        while (tags[i]) {
            if (strncmp(p, tags[i], tagsLen[i]) == 0) {
            if (strncmp(p, tags[i], tagsLen[i]) == 0) {
+10 −12
Original line number Original line Diff line number Diff line
@@ -1734,8 +1734,13 @@ public final class ActivityManagerService extends ActivityManagerNative
                        logBuilder.append("  MemInfo: ");
                        logBuilder.append("  MemInfo: ");
                        logBuilder.append(infos[Debug.MEMINFO_SLAB]).append(" kB slab, ");
                        logBuilder.append(infos[Debug.MEMINFO_SLAB]).append(" kB slab, ");
                        logBuilder.append(infos[Debug.MEMINFO_SHMEM]).append(" kB shmem, ");
                        logBuilder.append(infos[Debug.MEMINFO_SHMEM]).append(" kB shmem, ");
                        logBuilder.append(infos[Debug.MEMINFO_VM_ALLOC_USED]).append(" kB vm alloc, ");
                        logBuilder.append(infos[Debug.MEMINFO_PAGE_TABLES]).append(" kB page tables ");
                        logBuilder.append(infos[Debug.MEMINFO_KERNEL_STACK]).append(" kB kernel stack\n");
                        logBuilder.append("           ");
                        logBuilder.append(infos[Debug.MEMINFO_BUFFERS]).append(" kB buffers, ");
                        logBuilder.append(infos[Debug.MEMINFO_BUFFERS]).append(" kB buffers, ");
                        logBuilder.append(infos[Debug.MEMINFO_CACHED]).append(" kB cached, ");
                        logBuilder.append(infos[Debug.MEMINFO_CACHED]).append(" kB cached, ");
                        logBuilder.append(infos[Debug.MEMINFO_MAPPED]).append(" kB mapped, ");
                        logBuilder.append(infos[Debug.MEMINFO_FREE]).append(" kB free\n");
                        logBuilder.append(infos[Debug.MEMINFO_FREE]).append(" kB free\n");
                        if (infos[Debug.MEMINFO_ZRAM_TOTAL] != 0) {
                        if (infos[Debug.MEMINFO_ZRAM_TOTAL] != 0) {
                            logBuilder.append("  ZRAM: ");
                            logBuilder.append("  ZRAM: ");
@@ -1952,9 +1957,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                                + (SystemClock.uptimeMillis()-start) + "ms");
                                + (SystemClock.uptimeMillis()-start) + "ms");
                        mProcessStats.addSysMemUsageLocked(memInfo.getCachedSizeKb(),
                        mProcessStats.addSysMemUsageLocked(memInfo.getCachedSizeKb(),
                                memInfo.getFreeSizeKb(), memInfo.getZramTotalSizeKb(),
                                memInfo.getFreeSizeKb(), memInfo.getZramTotalSizeKb(),
                                memInfo.getBuffersSizeKb()+memInfo.getShmemSizeKb()
                                memInfo.getKernelUsedSizeKb(), nativeTotalPss);
                                        +memInfo.getSlabSizeKb(),
                                nativeTotalPss);
                    }
                    }
                }
                }
@@ -14240,8 +14243,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                synchronized (this) {
                synchronized (this) {
                    mProcessStats.addSysMemUsageLocked(memInfo.getCachedSizeKb(),
                    mProcessStats.addSysMemUsageLocked(memInfo.getCachedSizeKb(),
                            memInfo.getFreeSizeKb(), memInfo.getZramTotalSizeKb(),
                            memInfo.getFreeSizeKb(), memInfo.getZramTotalSizeKb(),
                            memInfo.getBuffersSizeKb()+memInfo.getShmemSizeKb()+memInfo.getSlabSizeKb(),
                            memInfo.getKernelUsedSizeKb(), nativeProcTotalPss);
                            nativeProcTotalPss);
                }
                }
            }
            }
            if (!brief) {
            if (!brief) {
@@ -14280,16 +14282,12 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
            }
            if (!isCompact) {
            if (!isCompact) {
                pw.print(" Used RAM: "); pw.print(totalPss - cachedPss
                pw.print(" Used RAM: "); pw.print(totalPss - cachedPss
                        + memInfo.getBuffersSizeKb() + memInfo.getShmemSizeKb()
                        + memInfo.getKernelUsedSizeKb()); pw.print(" kB (");
                        + memInfo.getSlabSizeKb()); pw.print(" kB (");
                        pw.print(totalPss - cachedPss); pw.print(" used pss + ");
                        pw.print(totalPss - cachedPss); pw.print(" used pss + ");
                        pw.print(memInfo.getBuffersSizeKb()); pw.print(" buffers + ");
                        pw.print(memInfo.getKernelUsedSizeKb()); pw.print(" kernel)\n");
                        pw.print(memInfo.getShmemSizeKb()); pw.print(" shmem + ");
                        pw.print(memInfo.getSlabSizeKb()); pw.println(" slab)");
                pw.print(" Lost RAM: "); pw.print(memInfo.getTotalSizeKb()
                pw.print(" Lost RAM: "); pw.print(memInfo.getTotalSizeKb()
                        - totalPss - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
                        - totalPss - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
                        - memInfo.getBuffersSizeKb() - memInfo.getShmemSizeKb()
                        - memInfo.getKernelUsedSizeKb()); pw.println(" kB");
                        - memInfo.getSlabSizeKb()); pw.println(" kB");
            }
            }
            if (!brief) {
            if (!brief) {
                if (memInfo.getZramTotalSizeKb() != 0) {
                if (memInfo.getZramTotalSizeKb() != 0) {