From 2bd413125ea86424f7901a18f82b9f8199adcc05 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 17 Dec 2021 09:36:42 +0800 Subject: [PATCH] Remove getProcessGroup usage in OomAdjuster The returned value may not be the same as it was set. The invocation was used to verify whether the schedule group is set by zygote. Since most of time it is success and it is no harm to ignore the result because the latest state can still be updated from oom-adj computation, the check of getProcessGroup can be simply removed. Bug: 211000005 Test: Record a trace during cold launching a top activity. The main thread priority should be 100 after attachApplication. And "adb shell cat /proc/$pid/task/$pid/cgroup" is top-app. Change-Id: I282e124d8dc603efdef9b845e8ee6bb61585a6df Merged-In: I282e124d8dc603efdef9b845e8ee6bb61585a6df --- .../com/android/server/am/OomAdjuster.java | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/services/core/java/com/android/server/am/OomAdjuster.java b/services/core/java/com/android/server/am/OomAdjuster.java index ff480d1f614ce..794b149bbde1c 100644 --- a/services/core/java/com/android/server/am/OomAdjuster.java +++ b/services/core/java/com/android/server/am/OomAdjuster.java @@ -2872,29 +2872,18 @@ public class OomAdjuster { void setAttachingSchedGroupLSP(ProcessRecord app) { int initialSchedGroup = ProcessList.SCHED_GROUP_DEFAULT; final ProcessStateRecord state = app.mState; - // If the process has been marked as foreground via Zygote.START_FLAG_USE_TOP_APP_PRIORITY, - // then verify that the top priority is actually is applied. + // If the process has been marked as foreground, it is starting as the top app (with + // Zygote#START_AS_TOP_APP_ARG), so boost the thread priority of its default UI thread. if (state.hasForegroundActivities()) { - String fallbackReason = null; try { // The priority must be the same as how does {@link #applyOomAdjLSP} set for // {@link ProcessList.SCHED_GROUP_TOP_APP}. We don't check render thread because it // is not ready when attaching. - if (Process.getProcessGroup(app.getPid()) == THREAD_GROUP_TOP_APP) { - app.getWindowProcessController().onTopProcChanged(); - setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST); - } else { - fallbackReason = "not expected top priority"; - } - } catch (Exception e) { - fallbackReason = e.toString(); - } - if (fallbackReason == null) { + app.getWindowProcessController().onTopProcChanged(); + setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST); initialSchedGroup = ProcessList.SCHED_GROUP_TOP_APP; - } else { - // The real scheduling group will depend on if there is any component of the process - // did something during attaching. - Slog.w(TAG, "Fallback pre-set sched group to default: " + fallbackReason); + } catch (Exception e) { + Slog.w(TAG, "Failed to pre-set top priority to " + app + " " + e); } }