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

Commit a1baf11e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ifb61fe59,I3439a8f0,I5c19dc60 into sc-dev

* changes:
  Add total DMA-BUF heap pool size information to dumpsys meminfo
  Add total size of DMA-BUFs exported to 'dumpsys meminfo'
  Rename getIonMappedSizeKb to getDmabufMappedSizeKb
parents 2827f507 5d414d10
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -2556,6 +2556,14 @@ public final class Debug
     */
    public static native long getZramFreeKb();

    /**
     * Return total memory size in kilobytes for exported DMA-BUFs or -1 if
     * the DMA-BUF sysfs stats at /sys/kernel/dmabuf/buffers could not be read.
     *
     * @hide
     */
    public static native long getDmabufTotalExportedKb();

    /**
     * Return memory size in kilobytes allocated for ION heaps or -1 if
     * /sys/kernel/ion/total_heaps_kb could not be read.
@@ -2564,6 +2572,14 @@ public final class Debug
     */
    public static native long getIonHeapsSizeKb();

    /**
     * Return memory size in kilobytes allocated for DMA-BUF heap pools or -1 if
     * /sys/kernel/dma_heap/total_pools_kb could not be read.
     *
     * @hide
     */
    public static native long getDmabufHeapPoolsSizeKb();

    /**
     * Return memory size in kilobytes allocated for ION pools or -1 if
     * /sys/kernel/ion/total_pools_kb could not be read.
@@ -2573,13 +2589,13 @@ public final class Debug
    public static native long getIonPoolsSizeKb();

    /**
     * Return ION memory mapped by processes in kB.
     * Return DMA-BUF memory mapped by processes in kB.
     * Notes:
     *  * Warning: Might impact performance as it reads /proc/<pid>/maps files for each process.
     *
     * @hide
     */
    public static native long getIonMappedSizeKb();
    public static native long getDmabufMappedSizeKb();

    /**
     * Return memory size in kilobytes used by GPU.
+32 −6
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
#include <nativehelper/JNIPlatformHelp.h>
#include <nativehelper/ScopedUtfChars.h>
#include "jni.h"
#include <dmabufinfo/dmabuf_sysfs_stats.h>
#include <dmabufinfo/dmabufinfo.h>
#include <meminfo/procmeminfo.h>
#include <meminfo/sysmeminfo.h>
@@ -805,6 +806,16 @@ static jlong android_os_Debug_getIonHeapsSizeKb(JNIEnv* env, jobject clazz) {
    return heapsSizeKb;
}

static jlong android_os_Debug_getDmabufTotalExportedKb(JNIEnv* env, jobject clazz) {
    jlong dmabufTotalSizeKb = -1;
    uint64_t size;

    if (dmabufinfo::GetDmabufTotalExportedKb(&size)) {
        dmabufTotalSizeKb = size;
    }
    return dmabufTotalSizeKb;
}

static jlong android_os_Debug_getIonPoolsSizeKb(JNIEnv* env, jobject clazz) {
    jlong poolsSizeKb = -1;
    uint64_t size;
@@ -816,8 +827,19 @@ static jlong android_os_Debug_getIonPoolsSizeKb(JNIEnv* env, jobject clazz) {
    return poolsSizeKb;
}

static jlong android_os_Debug_getIonMappedSizeKb(JNIEnv* env, jobject clazz) {
    jlong ionPss = 0;
static jlong android_os_Debug_getDmabufHeapPoolsSizeKb(JNIEnv* env, jobject clazz) {
    jlong poolsSizeKb = -1;
    uint64_t size;

    if (meminfo::ReadDmabufHeapPoolsSizeKb(&size)) {
        poolsSizeKb = size;
    }

    return poolsSizeKb;
}

static jlong android_os_Debug_getDmabufMappedSizeKb(JNIEnv* env, jobject clazz) {
    jlong dmabufPss = 0;
    std::vector<dmabufinfo::DmaBuffer> dmabufs;

    std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir("/proc"), closedir);
@@ -841,10 +863,10 @@ static jlong android_os_Debug_getIonMappedSizeKb(JNIEnv* env, jobject clazz) {
    }

    for (const dmabufinfo::DmaBuffer& buf : dmabufs) {
        ionPss += buf.size() / 1024;
        dmabufPss += buf.size() / 1024;
    }

    return ionPss;
    return dmabufPss;
}

static jlong android_os_Debug_getGpuTotalUsageKb(JNIEnv* env, jobject clazz) {
@@ -922,10 +944,14 @@ static const JNINativeMethod gMethods[] = {
            (void*)android_os_Debug_getFreeZramKb },
    { "getIonHeapsSizeKb", "()J",
            (void*)android_os_Debug_getIonHeapsSizeKb },
    { "getDmabufTotalExportedKb", "()J",
            (void*)android_os_Debug_getDmabufTotalExportedKb },
    { "getIonPoolsSizeKb", "()J",
            (void*)android_os_Debug_getIonPoolsSizeKb },
    { "getIonMappedSizeKb", "()J",
            (void*)android_os_Debug_getIonMappedSizeKb },
    { "getDmabufMappedSizeKb", "()J",
            (void*)android_os_Debug_getDmabufMappedSizeKb },
    { "getDmabufHeapPoolsSizeKb", "()J",
            (void*)android_os_Debug_getDmabufHeapPoolsSizeKb },
    { "getGpuTotalUsageKb", "()J",
            (void*)android_os_Debug_getGpuTotalUsageKb },
    { "isVmapStack", "()Z",
+26 −3
Original line number Diff line number Diff line
@@ -10700,13 +10700,13 @@ public class ActivityManagerService extends IActivityManager.Stub
            long kernelUsed = memInfo.getKernelUsedSizeKb();
            final long ionHeap = Debug.getIonHeapsSizeKb();
            final long ionPool = Debug.getIonPoolsSizeKb();
            final long dmabufMapped = Debug.getDmabufMappedSizeKb();
            if (ionHeap >= 0 && ionPool >= 0) {
                final long ionMapped = Debug.getIonMappedSizeKb();
                final long ionUnmapped = ionHeap - ionMapped;
                final long ionUnmapped = ionHeap - dmabufMapped;
                pw.print("      ION: ");
                        pw.print(stringifyKBSize(ionHeap + ionPool));
                        pw.print(" (");
                        pw.print(stringifyKBSize(ionMapped));
                        pw.print(stringifyKBSize(dmabufMapped));
                        pw.print(" mapped + ");
                        pw.print(stringifyKBSize(ionUnmapped));
                        pw.print(" unmapped + ");
@@ -10715,11 +10715,34 @@ public class ActivityManagerService extends IActivityManager.Stub
                // Note: mapped ION memory is not accounted in PSS due to VM_PFNMAP flag being
                // set on ION VMAs, therefore consider the entire ION heap as used kernel memory
                kernelUsed += ionHeap;
            } else {
                final long totalExportedDmabuf = Debug.getDmabufTotalExportedKb();
                if (totalExportedDmabuf >= 0) {
                    final long dmabufUnmapped = totalExportedDmabuf - dmabufMapped;
                    pw.print("DMA-BUF: ");
                    pw.print(stringifyKBSize(totalExportedDmabuf));
                    pw.print(" (");
                    pw.print(stringifyKBSize(dmabufMapped));
                    pw.print(" mapped + ");
                    pw.print(stringifyKBSize(dmabufUnmapped));
                    pw.println(" unmapped)");
                    kernelUsed += totalExportedDmabuf;
                }
                final long totalDmabufHeapPool = Debug.getDmabufHeapPoolsSizeKb();
                if (totalDmabufHeapPool >= 0) {
                    pw.print("DMA-BUF Heaps pool: ");
                    pw.println(stringifyKBSize(totalDmabufHeapPool));
                }
            }
            final long gpuUsage = Debug.getGpuTotalUsageKb();
            if (gpuUsage >= 0) {
                pw.print("      GPU: "); pw.println(stringifyKBSize(gpuUsage));
            }
            /*
             * Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of
             * memInfo.getCachedSizeKb().
             */
            final long lostRAM = memInfo.getTotalSizeKb()
                    - (ss[INDEX_TOTAL_PSS] - ss[INDEX_TOTAL_SWAP_PSS])
                    - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
+21 −2
Original line number Diff line number Diff line
@@ -1512,15 +1512,29 @@ public class AppProfiler {
        final long ionHeap = Debug.getIonHeapsSizeKb();
        final long ionPool = Debug.getIonPoolsSizeKb();
        if (ionHeap >= 0 && ionPool >= 0) {
            final long ionMapped = Debug.getIonMappedSizeKb();
            final long ionUnmapped = ionHeap - ionMapped;
            memInfoBuilder.append("       ION: ");
            memInfoBuilder.append(stringifyKBSize(ionHeap + ionPool));
            memInfoBuilder.append("\n");
            // Note: mapped ION memory is not accounted in PSS due to VM_PFNMAP flag being
            // set on ION VMAs, therefore consider the entire ION heap as used kernel memory
            kernelUsed += ionHeap;
        } else {
            final long totalExportedDmabuf = Debug.getDmabufTotalExportedKb();
            if (totalExportedDmabuf >= 0) {
                memInfoBuilder.append("DMA-BUF: ");
                memInfoBuilder.append(stringifyKBSize(totalExportedDmabuf));
                memInfoBuilder.append("\n");
                kernelUsed += totalExportedDmabuf;
            }

            final long totalDmabufHeapPool = Debug.getDmabufHeapPoolsSizeKb();
            if (totalDmabufHeapPool >= 0) {
                memInfoBuilder.append("DMA-BUF Heaps pool: ");
                memInfoBuilder.append(stringifyKBSize(totalDmabufHeapPool));
                memInfoBuilder.append("\n");
            }
        }

        final long gpuUsage = Debug.getGpuTotalUsageKb();
        if (gpuUsage >= 0) {
            memInfoBuilder.append("       GPU: ");
@@ -1531,6 +1545,11 @@ public class AppProfiler {
        memInfoBuilder.append(stringifyKBSize(
                                  totalPss - cachedPss + kernelUsed));
        memInfoBuilder.append("\n");

        /*
         * Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of
         * memInfo.getCachedSizeKb().
         */
        memInfoBuilder.append("  Lost RAM: ");
        memInfoBuilder.append(stringifyKBSize(memInfo.getTotalSizeKb()
                - (totalPss - totalSwapPss) - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()