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

Commit 075f9fe4 authored by Adam Bookatz's avatar Adam Bookatz
Browse files

Stop inactive bg user if memory pressure

Overhauls the previous scheduled stopping of background user mechanism
and replaces it with the following logic:
* We don't automatically schedule the background user for stopping right
  away.
* Instead, we schedule a later *judgement* of that user, which will
  hinge upon how long the user has been in the background and whether
  there has been evidence of memory pressure during that time.
* If the user remains inactive for a long (configurable) time, we will
  judge the user to be dispensable, meaning that it isn't important.
  Even then, we still don't necessarily stop the user yet.
* If the number of low memory kills (lmks) of better-than-cached apps
  has increased during this time (a sign of memory pressure and a sign
  that the user's apps have largely been killed anyway), then we will
  render judgement that this dispensable background user should be
  stopped.

Note that the old mechanism was never enabled, since its flag was never
turned on at all. We repurpose the flag for the updated mechanism.

Internal design doc: go/stopping-background-users-under-pressure

Bug: 425992644
Bug: 330351042
Test: atest FrameworksServicesTests:UserControllerTest
Flag: android.multiuser.schedule_stop_of_background_user_by_default
Change-Id: I3e73c572d6540a1cf5115a44ea22331501c3542f
parent 2ef30ecf
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -168,17 +168,16 @@ public abstract class ActivityManagerInternal {
     *
     * The automatic stopping is not guaranteed, and there are cases in which it won't be.
     * Similarly, there is no guarantee that the user will not be stopped prior to the given
     * duration.
     *
     * In the current implementation, this value simply replaces any default inactive stopping time
     * (from config_backgroundUserScheduledStopTimeSecs), but that is subject to change.
     * duration (such as if too many users are running, or the user has been in the background for
     * long enough that it is considered dispensable).
     *
     * Automatically stopping background users is not currently enabled for devices supporting
     * {@link android.os.UserManager#isVisibleBackgroundUsersEnabled() visible background users};
     * on such devices, the user will still be started but not stopped.
     *
     * @param userId ID of the user to start
     * @param durSecs in how many seconds we should attempt to stop the user
     * @param durSecs in how many seconds we should attempt to stop the user, typically something on
     *                the order of a few minutes
     * @return true if the user has been successfully started
     */
    public abstract boolean startUserInBackgroundTemporarily(@UserIdInt int userId, int durSecs);
+5 −3
Original line number Diff line number Diff line
@@ -3202,9 +3202,11 @@
    <!-- Maximum number of users we allow to be running at a time. -->
    <integer name="config_multiuserMaxRunningUsers">3</integer>

    <!-- Number of seconds of uptime after a full user enters the background before we attempt to
         stop it due to inactivity. Set to -1 to disable scheduling stopping background users. -->
    <integer name="config_backgroundUserScheduledStopTimeSecs">1800</integer> <!-- 30 minutes -->
    <!-- Number of seconds of uptime after a full user enters the background before we consider
         it as no longer important, and therefore can consider automatically stopping it.
         Set to -1 to disable this feature (i.e. don't auto-stop background users after some elapsed
         time). -->
    <integer name="config_backgroundUserConsideredDispensableTimeSecs">93600</integer> <!-- 26 hours -->

    <!-- Whether to delay user data locking for background user.
         If false, user switched-out from user switching will still be in running state until
+1 −1
Original line number Diff line number Diff line
@@ -500,7 +500,7 @@
  <java-symbol type="integer" name="config_lockSoundVolumeDb" />
  <java-symbol type="integer" name="config_multiuserMaximumUsers" />
  <java-symbol type="integer" name="config_multiuserMaxRunningUsers" />
  <java-symbol type="integer" name="config_backgroundUserScheduledStopTimeSecs" />
  <java-symbol type="integer" name="config_backgroundUserConsideredDispensableTimeSecs" />
  <java-symbol type="bool" name="config_multiuserDelayUserDataLocking" />
  <java-symbol type="bool" name="config_multiuserVisibleBackgroundUsers" />
  <java-symbol type="bool" name="config_multiuserVisibleBackgroundUsersOnDefaultDisplay" />
+4 −3
Original line number Diff line number Diff line
@@ -8947,10 +8947,11 @@ public class ActivityManagerService extends IActivityManager.Stub
                    com.android.internal.R.integer.config_multiuserMaxRunningUsers);
            final boolean delayUserDataLocking = res.getBoolean(
                    com.android.internal.R.bool.config_multiuserDelayUserDataLocking);
            final int backgroundUserScheduledStopTimeSecs = res.getInteger(
                    com.android.internal.R.integer.config_backgroundUserScheduledStopTimeSecs);
            final int backgroundUserConsideredDispensableTimeSecs = res.getInteger(
                    com.android.internal.R.integer
                            .config_backgroundUserConsideredDispensableTimeSecs);
            mUserController.setInitialConfig(userSwitchUiEnabled, maxRunningUsers,
                    delayUserDataLocking, backgroundUserScheduledStopTimeSecs);
                    delayUserDataLocking, backgroundUserConsideredDispensableTimeSecs);
        }
        mAppErrors.loadAppsNotReportingCrashesFromConfig(res.getString(
                com.android.internal.R.string.config_appsNotReportingCrashes));
+284 −64

File changed.

Preview size limit exceeded, changes collapsed.

Loading