Loading services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +3 −1 Original line number Diff line number Diff line Loading @@ -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; } Loading services/core/java/com/android/server/stats/pull/SystemMemoryUtil.java +30 −2 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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]; Loading @@ -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; } Loading @@ -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; } } Loading
services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +3 −1 Original line number Diff line number Diff line Loading @@ -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; } Loading
services/core/java/com/android/server/stats/pull/SystemMemoryUtil.java +30 −2 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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]; Loading @@ -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; } Loading @@ -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; } }