From b55e856e592ab5eb703f42b4fd6c6144717acc0d Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Tue, 12 May 2020 14:24:12 -0700 Subject: [PATCH] Fix Lost RAM calculation by accounting for ION mapped heaps ION mapped heaps are not reflected in process PSS because ION driver maps them using remap_pfn_range that sets VM_PFNMAP flag for each mapped ION heap VMA and consequently excludes these VMAs from PSS calculation. Change memory accounting to consider ION mapped heaps as part of kernel used memory which fixes the Lost RAM calculation that currently includes mapped ION heaps. Bug: 155409819 Test: verify Lost RAM after opening camera app Signed-off-by: Suren Baghdasaryan Change-Id: I2bad40bbe7d14b1c61534d661b612200ef1084e4 --- .../com/android/server/am/ActivityManagerService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index d914bda3eff44..930f124cd687b 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -13597,7 +13597,9 @@ public class ActivityManagerService extends IActivityManager.Stub pw.print(" unmapped + "); pw.print(stringifyKBSize(ionPool)); pw.println(" pools)"); - kernelUsed += ionUnmapped; + // 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; } final long lostRAM = memInfo.getTotalSizeKb() - (totalPss - totalSwapPss) - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb() @@ -14403,7 +14405,9 @@ public class ActivityManagerService extends IActivityManager.Stub memInfoBuilder.append(" ION: "); memInfoBuilder.append(stringifyKBSize(ionHeap + ionPool)); memInfoBuilder.append("\n"); - kernelUsed += ionUnmapped; + // 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; } memInfoBuilder.append(" Used RAM: "); memInfoBuilder.append(stringifyKBSize(