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

Commit 9da0f3a6 authored by Hridya Valsaraju's avatar Hridya Valsaraju
Browse files

Add total size of DMA-BUFs exported to 'dumpsys meminfo'

When ION support is not detected, print the total size of DMA-BUFs
exported as part of dumpsys meminfo.

Bug: 167709539
Test: dumpsys meminfo
Change-Id: I3439a8f00cf1aef37e5043b505ed53d47a8a4756
Merged-In: I3439a8f00cf1aef37e5043b505ed53d47a8a4756
parent 61ac2089
Loading
Loading
Loading
Loading
+8 −0
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.
+13 −0
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;
@@ -922,6 +933,8 @@ 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 },
    { "getDmabufMappedSizeKb", "()J",
+17 −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.getDmabufMappedSizeKb();
                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,6 +10715,20 @@ 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)");
                    // TODO(b/167709539): also add pooled memory from DMA-BUF heaps
                    kernelUsed += totalExportedDmabuf;
                }
            }
            final long gpuUsage = Debug.getGpuTotalUsageKb();
            if (gpuUsage >= 0) {
+9 −2
Original line number Diff line number Diff line
@@ -1512,15 +1512,22 @@ public class AppProfiler {
        final long ionHeap = Debug.getIonHeapsSizeKb();
        final long ionPool = Debug.getIonPoolsSizeKb();
        if (ionHeap >= 0 && ionPool >= 0) {
            final long ionMapped = Debug.getDmabufMappedSizeKb();
            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 gpuUsage = Debug.getGpuTotalUsageKb();
        if (gpuUsage >= 0) {
            memInfoBuilder.append("       GPU: ");