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

Commit 4734ae78 authored by Shashi Shekar Shankar's avatar Shashi Shekar Shankar Committed by Linux Build Service Account
Browse files

Performance: Enable Aggressive trim settings

This change will enable aggressive trim settings for targets
up to 1GB. The change can be turned on/off from system properties.
By default, the properties are set for targets up to 1GB.

CRs-Fixed: 783020

Change-Id: I233dddbff07e7ec1fe2ee96402fe1d411903beb5
parent e3c2f235
Loading
Loading
Loading
Loading
+32 −3
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.server.wm.WindowManagerService;
import android.content.res.Resources;
import android.graphics.Point;
import android.os.SystemProperties;
import android.os.Process;
import android.net.LocalSocketAddress;
import android.net.LocalSocket;
import android.util.Slog;
@@ -134,6 +135,16 @@ final class ProcessList {
    // processes and the number of those processes does not count against the cached
    // process limit.
    static final int MAX_CACHED_APPS = SystemProperties.getInt("ro.sys.fw.bg_apps_limit",32);
    static final boolean USE_TRIM_SETTINGS =
            SystemProperties.getBoolean("ro.sys.fw.use_trim_settings",true);
    static final int EMPTY_APP_PERCENT = SystemProperties.getInt("ro.sys.fw.empty_app_percent",50);
    static final int TRIM_EMPTY_PERCENT =
            SystemProperties.getInt("ro.sys.fw.trim_empty_percent",100);
    static final int TRIM_CACHE_PERCENT =
            SystemProperties.getInt("ro.sys.fw.trim_cache_percent",100);
    static final long TRIM_ENABLE_MEMORY =
            SystemProperties.getLong("ro.sys.fw.trim_enable_memory",1073741824);
    public static boolean allowTrim() { return Process.getTotalMemory() < TRIM_ENABLE_MEMORY ; }

    // We allow empty processes to stick around for at most 30 minutes.
    static final long MAX_EMPTY_TIME = 30*60*1000;
@@ -143,11 +154,25 @@ final class ProcessList {

    // The number of empty apps at which we don't consider it necessary to do
    // memory trimming.
    static final int TRIM_EMPTY_APPS = MAX_EMPTY_APPS/2;
    public static int computeTrimEmptyApps() {
        if (USE_TRIM_SETTINGS && allowTrim()) {
            return MAX_EMPTY_APPS*TRIM_EMPTY_PERCENT/100;
        } else {
            return MAX_EMPTY_APPS/2;
        }
    }
    static final int TRIM_EMPTY_APPS = computeTrimEmptyApps();

    // The number of cached at which we don't consider it necessary to do
    // memory trimming.
    static final int TRIM_CACHED_APPS = (MAX_CACHED_APPS-MAX_EMPTY_APPS)/3;
    public static int computeTrimCachedApps() {
        if (USE_TRIM_SETTINGS && allowTrim()) {
            return MAX_CACHED_APPS*TRIM_CACHE_PERCENT/100;
        } else {
            return (MAX_CACHED_APPS-MAX_EMPTY_APPS)/3;
        }
    }
    static final int TRIM_CACHED_APPS = computeTrimCachedApps();

    // Threshold of number of cached+empty where we consider memory critical.
    static final int TRIM_CRITICAL_THRESHOLD = 3;
@@ -308,8 +333,12 @@ final class ProcessList {
    }

    public static int computeEmptyProcessLimit(int totalProcessLimit) {
        if(USE_TRIM_SETTINGS && allowTrim()) {
            return totalProcessLimit*EMPTY_APP_PERCENT/100;
        } else {
            return totalProcessLimit/2;
        }
    }

    private static String buildOomTag(String prefix, String space, int val, int base) {
        if (val == base) {