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

Commit 0233fba2 authored by Ioannis Ilkos's avatar Ioannis Ilkos Committed by Suren Baghdasaryan
Browse files

Add private gpu and total dmabuf size to SystemMemory atom

Changes:
- Transition to measuring dmabuf export size (ion
allocations are most recently implemented via dmabufs anyway, the total
ion size will be a subset of the total dmabuf exported memory)

- For supported kernels (5.4+) that have sysfs dmabuf accounting,
account for private GPU driver memory vs GPU driver dmabuf memory.

- Adjust the accounted memory calculations based on the above.

Bug: 149462065
Bug: 172201884
Test: build, statsd_testdrive
Change-Id: Ie4e4d0b4fc4495896374fbebc70e29e32469b5e3
parent ce0d6a33
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -2134,7 +2134,9 @@ public class StatsPullAtomService extends SystemService {
                        metrics.kernelStackKb,
                        metrics.totalIonKb,
                        metrics.unaccountedKb,
                        metrics.gpuTotalUsageKb));
                        metrics.gpuTotalUsageKb,
                        metrics.gpuPrivateAllocationsKb,
                        metrics.dmaBufTotalExportedKb));
        return StatsManager.PULL_SUCCESS;
    }

+30 −2
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ final class SystemMemoryUtil {
    static Metrics getMetrics() {
        int totalIonKb = (int) Debug.getIonHeapsSizeKb();
        int gpuTotalUsageKb = (int) Debug.getGpuTotalUsageKb();
        int gpuDmaBufUsageKb = (int) Debug.getGpuDmaBufUsageKb();
        int dmaBufTotalExportedKb = (int) Debug.getDmabufTotalExportedKb();

        long[] mInfos = new long[Debug.MEMINFO_COUNT];
        Debug.getMemInfo(mInfos);
@@ -49,14 +51,36 @@ final class SystemMemoryUtil {
                + mInfos[Debug.MEMINFO_SLAB_UNRECLAIMABLE]
                + kReclaimableKb
                + mInfos[Debug.MEMINFO_VM_ALLOC_USED]
                + mInfos[Debug.MEMINFO_PAGE_TABLES]
                + Math.max(totalIonKb, 0);
                + mInfos[Debug.MEMINFO_PAGE_TABLES];

        if (!Debug.isVmapStack()) {
            // See b/146088882
            accountedKb += mInfos[Debug.MEMINFO_KERNEL_STACK];
        }

        int gpuPrivateAllocationsKb = -1;
        if (gpuTotalUsageKb >= 0 && gpuDmaBufUsageKb >= 0) {
            gpuPrivateAllocationsKb = gpuTotalUsageKb - gpuDmaBufUsageKb;
        }
        // If we can distinguish gpu private allocs it means the dmabuf metrics
        // are supported already.
        if (dmaBufTotalExportedKb >= 0 && gpuPrivateAllocationsKb >= 0) {
            // If we can calculate the overlap between dma memory and gpu
            // drivers we can do more accurate tracking. But this is only
            // available on 5.4+ kernels.
            accountedKb += dmaBufTotalExportedKb + gpuPrivateAllocationsKb;
        } else {
            // If we cannot distinguish, accept that we will double count the
            // dma buffers also used by the gpu driver.
            accountedKb += Math.max(0, gpuTotalUsageKb);
            if (dmaBufTotalExportedKb >= 0) {
                accountedKb += dmaBufTotalExportedKb;
            } else if (totalIonKb >= 0) {
                // ION is a subset of total exported dmabuf memory.
                accountedKb += totalIonKb;
            }
        }

        Metrics result = new Metrics();
        result.unreclaimableSlabKb = (int) mInfos[Debug.MEMINFO_SLAB_UNRECLAIMABLE];
        result.vmallocUsedKb = (int) mInfos[Debug.MEMINFO_VM_ALLOC_USED];
@@ -64,6 +88,8 @@ final class SystemMemoryUtil {
        result.kernelStackKb = (int) mInfos[Debug.MEMINFO_KERNEL_STACK];
        result.totalIonKb = totalIonKb;
        result.gpuTotalUsageKb = gpuTotalUsageKb;
        result.gpuPrivateAllocationsKb = gpuPrivateAllocationsKb;
        result.dmaBufTotalExportedKb = dmaBufTotalExportedKb;
        result.unaccountedKb = (int) (mInfos[Debug.MEMINFO_TOTAL] - accountedKb);
        return result;
    }
@@ -75,6 +101,8 @@ final class SystemMemoryUtil {
        public int kernelStackKb;
        public int totalIonKb;
        public int gpuTotalUsageKb;
        public int gpuPrivateAllocationsKb;
        public int dmaBufTotalExportedKb;
        public int unaccountedKb;
    }
}