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

Commit 6d38ff78 authored by Jing Ji's avatar Jing Ji Committed by Android (Google) Code Review
Browse files

Merge "Revert^2: [1/n] OomAdjuster implementation correctness and efficiency overhaul" into main

parents f02bd1ff 67ed5f4b
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -6434,6 +6434,7 @@ public final class ActiveServices {
        }
        }
        updateServiceConnectionActivitiesLocked(psr);
        updateServiceConnectionActivitiesLocked(psr);
        psr.removeAllConnections();
        psr.removeAllConnections();
        psr.removeAllSdkSandboxConnections();


        psr.mAllowlistManager = false;
        psr.mAllowlistManager = false;


+30 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.os.PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_NONE;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_POWER_QUICK;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_POWER_QUICK;
import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_BACKGROUND_RESTRICTED_ONLY;
import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_BACKGROUND_RESTRICTED_ONLY;
import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_TARGET_T_ONLY;
import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_TARGET_T_ONLY;
import static com.android.server.am.BroadcastConstants.getDeviceConfigBoolean;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.app.ActivityThread;
import android.app.ActivityThread;
@@ -154,6 +155,11 @@ final class ActivityManagerConstants extends ContentObserver {
    static final String KEY_TIERED_CACHED_ADJ_DECAY_TIME = "tiered_cached_adj_decay_time";
    static final String KEY_TIERED_CACHED_ADJ_DECAY_TIME = "tiered_cached_adj_decay_time";
    static final String KEY_USE_MODERN_TRIM = "use_modern_trim";
    static final String KEY_USE_MODERN_TRIM = "use_modern_trim";


    /**
     * Whether or not to enable the new oom adjuster implementation.
     */
    static final String KEY_ENABLE_NEW_OOMADJ = "enable_new_oom_adj";

    private static final int DEFAULT_MAX_CACHED_PROCESSES = 1024;
    private static final int DEFAULT_MAX_CACHED_PROCESSES = 1024;
    private static final boolean DEFAULT_PRIORITIZE_ALARM_BROADCASTS = true;
    private static final boolean DEFAULT_PRIORITIZE_ALARM_BROADCASTS = true;
    private static final long DEFAULT_FGSERVICE_MIN_SHOWN_TIME = 2*1000;
    private static final long DEFAULT_FGSERVICE_MIN_SHOWN_TIME = 2*1000;
@@ -216,6 +222,11 @@ final class ActivityManagerConstants extends ContentObserver {


    private static final boolean DEFAULT_USE_MODERN_TRIM = true;
    private static final boolean DEFAULT_USE_MODERN_TRIM = true;


    /**
     * The default value to {@link #KEY_ENABLE_NEW_OOMADJ}.
     */
    private static final boolean DEFAULT_ENABLE_NEW_OOM_ADJ = false;

    /**
    /**
     * Same as {@link TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_NOT_ALLOWED}
     * Same as {@link TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_NOT_ALLOWED}
     */
     */
@@ -1052,6 +1063,9 @@ final class ActivityManagerConstants extends ContentObserver {
    /** @see #KEY_USE_MODERN_TRIM */
    /** @see #KEY_USE_MODERN_TRIM */
    public boolean USE_MODERN_TRIM = DEFAULT_USE_MODERN_TRIM;
    public boolean USE_MODERN_TRIM = DEFAULT_USE_MODERN_TRIM;


    /** @see #KEY_ENABLE_NEW_OOMADJ */
    public boolean ENABLE_NEW_OOMADJ = DEFAULT_ENABLE_NEW_OOM_ADJ;

    /**
    /**
     * Indicates whether PSS profiling in AppProfiler is disabled or not.
     * Indicates whether PSS profiling in AppProfiler is disabled or not.
     */
     */
@@ -1321,6 +1335,7 @@ final class ActivityManagerConstants extends ContentObserver {
        CUR_TRIM_EMPTY_PROCESSES = rawMaxEmptyProcesses / 2;
        CUR_TRIM_EMPTY_PROCESSES = rawMaxEmptyProcesses / 2;
        CUR_TRIM_CACHED_PROCESSES = (Integer.min(CUR_MAX_CACHED_PROCESSES, MAX_CACHED_PROCESSES)
        CUR_TRIM_CACHED_PROCESSES = (Integer.min(CUR_MAX_CACHED_PROCESSES, MAX_CACHED_PROCESSES)
                    - rawMaxEmptyProcesses) / 3;
                    - rawMaxEmptyProcesses) / 3;
        loadNativeBootDeviceConfigConstants();
        mDefaultDisableAppProfilerPssProfiling = context.getResources().getBoolean(
        mDefaultDisableAppProfilerPssProfiling = context.getResources().getBoolean(
                R.bool.config_am_disablePssProfiling);
                R.bool.config_am_disablePssProfiling);
        APP_PROFILER_PSS_PROFILING_DISABLED = mDefaultDisableAppProfilerPssProfiling;
        APP_PROFILER_PSS_PROFILING_DISABLED = mDefaultDisableAppProfilerPssProfiling;
@@ -1363,6 +1378,11 @@ final class ActivityManagerConstants extends ContentObserver {
                        DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS));
                        DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS));
    }
    }


    private void loadNativeBootDeviceConfigConstants() {
        ENABLE_NEW_OOMADJ = getDeviceConfigBoolean(KEY_ENABLE_NEW_OOMADJ,
                DEFAULT_ENABLE_NEW_OOM_ADJ);
    }

    public void setOverrideMaxCachedProcesses(int value) {
    public void setOverrideMaxCachedProcesses(int value) {
        mOverrideMaxCachedProcesses = value;
        mOverrideMaxCachedProcesses = value;
        updateMaxCachedProcesses();
        updateMaxCachedProcesses();
@@ -2013,6 +2033,13 @@ final class ActivityManagerConstants extends ContentObserver {
            DEFAULT_USE_MODERN_TRIM);
            DEFAULT_USE_MODERN_TRIM);
    }
    }


    private void updateEnableNewOomAdj() {
        ENABLE_NEW_OOMADJ = DeviceConfig.getBoolean(
            DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT,
            KEY_ENABLE_NEW_OOMADJ,
            DEFAULT_ENABLE_NEW_OOM_ADJ);
    }

    private void updateFGSPermissionEnforcementFlagsIfNecessary(@NonNull String name) {
    private void updateFGSPermissionEnforcementFlagsIfNecessary(@NonNull String name) {
        ForegroundServiceTypePolicy.getDefaultPolicy()
        ForegroundServiceTypePolicy.getDefaultPolicy()
            .updatePermissionEnforcementFlagIfNecessary(name);
            .updatePermissionEnforcementFlagIfNecessary(name);
@@ -2209,6 +2236,9 @@ final class ActivityManagerConstants extends ContentObserver {
        pw.print("  "); pw.print(KEY_TIERED_CACHED_ADJ_DECAY_TIME);
        pw.print("  "); pw.print(KEY_TIERED_CACHED_ADJ_DECAY_TIME);
        pw.print("="); pw.println(TIERED_CACHED_ADJ_DECAY_TIME);
        pw.print("="); pw.println(TIERED_CACHED_ADJ_DECAY_TIME);


        pw.print("  "); pw.print(KEY_ENABLE_NEW_OOMADJ);
        pw.print("="); pw.println(ENABLE_NEW_OOMADJ);

        pw.print("  "); pw.print(KEY_DISABLE_APP_PROFILER_PSS_PROFILING);
        pw.print("  "); pw.print(KEY_DISABLE_APP_PROFILER_PSS_PROFILING);
        pw.print("="); pw.println(APP_PROFILER_PSS_PROFILING_DISABLED);
        pw.print("="); pw.println(APP_PROFILER_PSS_PROFILING_DISABLED);


+9 −2
Original line number Original line Diff line number Diff line
@@ -2029,6 +2029,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                app.makeActive(mSystemThread.getApplicationThread(), mProcessStats);
                app.makeActive(mSystemThread.getApplicationThread(), mProcessStats);
                app.mProfile.addHostingComponentType(HOSTING_COMPONENT_TYPE_SYSTEM);
                app.mProfile.addHostingComponentType(HOSTING_COMPONENT_TYPE_SYSTEM);
                addPidLocked(app);
                addPidLocked(app);
                mOomAdjuster.onProcessBeginLocked(app);
                updateLruProcessLocked(app, false, null);
                updateLruProcessLocked(app, false, null);
                updateOomAdjLocked(OOM_ADJ_REASON_SYSTEM_INIT);
                updateOomAdjLocked(OOM_ADJ_REASON_SYSTEM_INIT);
            }
            }
@@ -2422,7 +2423,9 @@ public class ActivityManagerService extends IActivityManager.Stub
        mProcessList.init(this, activeUids, mPlatformCompat);
        mProcessList.init(this, activeUids, mPlatformCompat);
        mAppProfiler = new AppProfiler(this, BackgroundThread.getHandler().getLooper(), null);
        mAppProfiler = new AppProfiler(this, BackgroundThread.getHandler().getLooper(), null);
        mPhantomProcessList = new PhantomProcessList(this);
        mPhantomProcessList = new PhantomProcessList(this);
        mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids, handlerThread);
        mOomAdjuster = mConstants.ENABLE_NEW_OOMADJ
                ? new OomAdjusterModernImpl(this, mProcessList, activeUids, handlerThread)
                : new OomAdjuster(this, mProcessList, activeUids, handlerThread);
        mIntentFirewall = null;
        mIntentFirewall = null;
        mProcessStats = new ProcessStatsService(this, mContext.getCacheDir());
        mProcessStats = new ProcessStatsService(this, mContext.getCacheDir());
@@ -2483,7 +2486,9 @@ public class ActivityManagerService extends IActivityManager.Stub
        mAppProfiler = new AppProfiler(this, BackgroundThread.getHandler().getLooper(),
        mAppProfiler = new AppProfiler(this, BackgroundThread.getHandler().getLooper(),
                new LowMemDetector(this));
                new LowMemDetector(this));
        mPhantomProcessList = new PhantomProcessList(this);
        mPhantomProcessList = new PhantomProcessList(this);
        mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids);
        mOomAdjuster = mConstants.ENABLE_NEW_OOMADJ
                ? new OomAdjusterModernImpl(this, mProcessList, activeUids)
                : new OomAdjuster(this, mProcessList, activeUids);
        // Broadcast policy parameters
        // Broadcast policy parameters
        final BroadcastConstants foreConstants = new BroadcastConstants(
        final BroadcastConstants foreConstants = new BroadcastConstants(
@@ -4595,6 +4600,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        EventLogTags.writeAmProcBound(app.userId, pid, app.processName);
        EventLogTags.writeAmProcBound(app.userId, pid, app.processName);
        synchronized (mProcLock) {
        synchronized (mProcLock) {
            mOomAdjuster.onProcessBeginLocked(app);
            mOomAdjuster.setAttachingProcessStatesLSP(app);
            mOomAdjuster.setAttachingProcessStatesLSP(app);
            clearProcessForegroundLocked(app);
            clearProcessForegroundLocked(app);
            app.setDebugging(false);
            app.setDebugging(false);
@@ -6980,6 +6986,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    sdkSandboxClientAppPackage,
                    sdkSandboxClientAppPackage,
                    new HostingRecord(HostingRecord.HOSTING_TYPE_ADDED_APPLICATION,
                    new HostingRecord(HostingRecord.HOSTING_TYPE_ADDED_APPLICATION,
                            customProcess != null ? customProcess : info.processName));
                            customProcess != null ? customProcess : info.processName));
            mOomAdjuster.onProcessBeginLocked(app);
            updateLruProcessLocked(app, false, null);
            updateLruProcessLocked(app, false, null);
            updateOomAdjLocked(app, OOM_ADJ_REASON_PROCESS_BEGIN);
            updateOomAdjLocked(app, OOM_ADJ_REASON_PROCESS_BEGIN);
        }
        }
+3 −3
Original line number Original line Diff line number Diff line
@@ -373,7 +373,7 @@ public class BroadcastConstants {
     * Return the {@link SystemProperty} name for the given key in our
     * Return the {@link SystemProperty} name for the given key in our
     * {@link DeviceConfig} namespace.
     * {@link DeviceConfig} namespace.
     */
     */
    private @NonNull String propertyFor(@NonNull String key) {
    private static @NonNull String propertyFor(@NonNull String key) {
        return "persist.device_config." + NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT + "." + key;
        return "persist.device_config." + NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT + "." + key;
    }
    }


@@ -382,11 +382,11 @@ public class BroadcastConstants {
     * {@link DeviceConfig} namespace, but with a different prefix that can be
     * {@link DeviceConfig} namespace, but with a different prefix that can be
     * used to locally override the {@link DeviceConfig} value.
     * used to locally override the {@link DeviceConfig} value.
     */
     */
    private @NonNull String propertyOverrideFor(@NonNull String key) {
    private static @NonNull String propertyOverrideFor(@NonNull String key) {
        return "persist.sys." + NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT + "." + key;
        return "persist.sys." + NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT + "." + key;
    }
    }


    private boolean getDeviceConfigBoolean(@NonNull String key, boolean def) {
    static boolean getDeviceConfigBoolean(@NonNull String key, boolean def) {
        return SystemProperties.getBoolean(propertyOverrideFor(key),
        return SystemProperties.getBoolean(propertyOverrideFor(key),
                SystemProperties.getBoolean(propertyFor(key), def));
                SystemProperties.getBoolean(propertyFor(key), def));
    }
    }
+772 −500

File changed.

Preview size limit exceeded, changes collapsed.

Loading