summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nandana Dutt <nandana@google.com> 2018-07-05 10:06:18 +0100
committer Nandana Dutt <nandana@google.com> 2018-07-09 12:32:34 +0000
commit786d5453bfd73f9ee740f6ead12b0514f7e6023c (patch)
treebaba8175183e7df9fd8cb0b7b0d87d11131dcd6a
parentce77407144346c6fad679a4297910eea07d0d601 (diff)
Fix the lost RAM calculation
The formula used when reporting memory usage when device goes low on memory should exclude SwapPss, which was incorrectly being included as part of totalPss. BUG: 109762356 Test: Manually tested on a gobo device by making it go low on memory. Verified that the Lost RAM in adb logcat was negative before, and is positive with the change, and close to Lost RAM from "dumpsys meminfo". Change-Id: Ic54181b55fa03d3faebda4c0516c95c18ee39e41
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java11
-rw-r--r--services/core/java/com/android/server/am/ProcessMemInfo.java1
2 files changed, 9 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 64e3c108dbf0..b1abbf1279a6 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -16023,6 +16023,7 @@ public class ActivityManagerService extends IActivityManager.Stub
}
updateCpuStatsNow();
long[] memtrackTmp = new long[1];
+ long[] swaptrackTmp = new long[2];
final List<ProcessCpuTracker.Stats> stats;
// Get a list of Stats that have vsize > 0
synchronized (mProcessCpuTracker) {
@@ -16033,12 +16034,13 @@ public class ActivityManagerService extends IActivityManager.Stub
final int statsCount = stats.size();
for (int i = 0; i < statsCount; i++) {
ProcessCpuTracker.Stats st = stats.get(i);
- long pss = Debug.getPss(st.pid, null, memtrackTmp);
+ long pss = Debug.getPss(st.pid, swaptrackTmp, memtrackTmp);
if (pss > 0) {
if (infoMap.indexOfKey(st.pid) < 0) {
ProcessMemInfo mi = new ProcessMemInfo(st.name, st.pid,
ProcessList.NATIVE_ADJ, -1, "native", null);
mi.pss = pss;
+ mi.swapPss = swaptrackTmp[1];
mi.memtrack = memtrackTmp[0];
memInfos.add(mi);
}
@@ -16046,14 +16048,17 @@ public class ActivityManagerService extends IActivityManager.Stub
}
long totalPss = 0;
+ long totalSwapPss = 0;
long totalMemtrack = 0;
for (int i=0, N=memInfos.size(); i<N; i++) {
ProcessMemInfo mi = memInfos.get(i);
if (mi.pss == 0) {
- mi.pss = Debug.getPss(mi.pid, null, memtrackTmp);
+ mi.pss = Debug.getPss(mi.pid, swaptrackTmp, memtrackTmp);
+ mi.swapPss = swaptrackTmp[1];
mi.memtrack = memtrackTmp[0];
}
totalPss += mi.pss;
+ totalSwapPss += mi.swapPss;
totalMemtrack += mi.memtrack;
}
Collections.sort(memInfos, new Comparator<ProcessMemInfo>() {
@@ -16215,7 +16220,7 @@ public class ActivityManagerService extends IActivityManager.Stub
memInfoBuilder.append("\n");
memInfoBuilder.append(" Lost RAM: ");
memInfoBuilder.append(stringifyKBSize(memInfo.getTotalSizeKb()
- - totalPss - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
+ - (totalPss - totalSwapPss) - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
- memInfo.getKernelUsedSizeKb() - memInfo.getZramTotalSizeKb()));
memInfoBuilder.append("\n");
Slog.i(TAG, "Low on memory:");
diff --git a/services/core/java/com/android/server/am/ProcessMemInfo.java b/services/core/java/com/android/server/am/ProcessMemInfo.java
index 83d29e2bba68..6c10a2af9fe6 100644
--- a/services/core/java/com/android/server/am/ProcessMemInfo.java
+++ b/services/core/java/com/android/server/am/ProcessMemInfo.java
@@ -24,6 +24,7 @@ public class ProcessMemInfo {
final String adjType;
final String adjReason;
long pss;
+ long swapPss;
long memtrack;
public ProcessMemInfo(String _name, int _pid, int _oomAdj, int _procState,