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

Commit 202d05a5 authored by Liam Mark's avatar Liam Mark
Browse files

ActivityManager: support new free memory estimate

Add support for a new free memory estimate which
instead of using the PSS of cached apps uses the
private dirty and private clean memory of cached
apps to estimate their size.

This new free memory estimate is more accurate
because it doesn't count the shared memory used by
cached apps which doesn't tend to be returned to
the system when cached apps are killed.

The new free memory estimate can be seen by using
the -f option with the dumpsys meminfo command.

Change-Id: I11d326f7937af79b7e909cbfa5eed568f26f7b34
parent 3e656914
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -11952,6 +11952,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        boolean oomOnly = false;
        boolean isCompact = false;
        boolean localOnly = false;
        boolean showFreeFormula2 = false;
        
        int opti = 0;
        while (opti < args.length) {
@@ -11966,6 +11967,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                dumpDalvik = true;
            } else if ("-d".equals(opt)) {
                dumpDalvik = true;
            } else if ("-f".equals(opt)) {
                showFreeFormula2 = true;
            } else if ("-c".equals(opt)) {
                isCompact = true;
            } else if ("--oom".equals(opt)) {
@@ -11975,6 +11978,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            } else if ("-h".equals(opt)) {
                pw.println("meminfo dump options: [-a] [-d] [-c] [--oom] [process]");
                pw.println("  -a: include all available information for each process.");
                pw.println("  -f: include alternative memory free estimate.");
                pw.println("  -d: include dalvik details when dumping process details.");
                pw.println("  -c: dump in a compact machine-parseable representation.");
                pw.println("  --oom: only show processes organized by oom adj.");
@@ -12067,6 +12071,8 @@ public final class ActivityManagerService extends ActivityManagerNative
        long totalPss = 0;
        long cachedPss = 0;
        long cachedPrivateDirty = 0;
        long cachedPrivateClean = 0;
        Debug.MemoryInfo mi = null;
        for (int i = procs.size() - 1 ; i >= 0 ; i--) {
@@ -12088,7 +12094,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                if (mi == null) {
                    mi = new Debug.MemoryInfo();
                }
                if (dumpDetails || (!brief && !oomOnly)) {
                if (dumpDetails || (!brief && !oomOnly) || showFreeFormula2) {
                    Debug.getMemoryInfo(pid, mi);
                } else {
                    mi.dalvikPss = (int)Debug.getPss(pid, tmpLong);
@@ -12117,6 +12123,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                final long myTotalPss = mi.getTotalPss();
                final long myTotalUss = mi.getTotalUss();
                final long myTotalPrivateDirty = mi.getTotalPrivateDirty();
                final long myTotalPrivateClean = mi.getTotalPrivateClean();
                synchronized (this) {
                    if (r.thread != null && oomAdj == r.getSetAdjWithServices()) {
@@ -12144,6 +12152,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                    if (oomAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
                        cachedPss += myTotalPss;
                        cachedPrivateDirty += myTotalPrivateDirty;
                        cachedPrivateClean += myTotalPrivateClean;
                    }
                    for (int oomIndex=0; oomIndex<oomPss.length; oomIndex++) {
@@ -12258,6 +12268,15 @@ public final class ActivityManagerService extends ActivityManagerNative
                            pw.print(cachedPss); pw.print(" cached pss + ");
                            pw.print(memInfo.getCachedSizeKb()); pw.print(" cached + ");
                            pw.print(memInfo.getFreeSizeKb()); pw.println(" free)");
                    if (showFreeFormula2) {
                        pw.print(" Free RAM v2: "); pw.print(cachedPrivateDirty
                                + cachedPrivateClean + memInfo.getCachedSizeKb()
                                + memInfo.getFreeSizeKb()); pw.print(" kB (");
                                pw.print(cachedPrivateDirty); pw.print(" cached private dirty + ");
                                pw.print(cachedPrivateClean); pw.print(" cached private clean + ");
                                pw.print(memInfo.getCachedSizeKb()); pw.print(" cached + ");
                                pw.print(memInfo.getFreeSizeKb()); pw.println(" free)");
                    }
                } else {
                    pw.print("ram,"); pw.print(memInfo.getTotalSizeKb()); pw.print(",");
                    pw.print(cachedPss + memInfo.getCachedSizeKb()