Look for phantom processes before setting the process group
Before this change, identification of phantom processes was done only lazily. AppProfiler, in a background thread (ProcessCpuThread) ran the identification periodically. At the moment, the period is longer than 3 min. The identification of phantom processes is a heavy-weight task as it iterates over "all" app processes in the system to read /sys/fs/cgroup/uid_<uid>/pid_<pid>/cgroup.procs files. So, not running it reactively makes much sense. However, a big downside of this approach is that phantom processes created in the last 3 min can escape from the adjustements made by OomAdjuster. Specifically, it can escape from the process group adj. introduced with I7115ce86d3363e83b1808fb2db5bd2c143bed885. An app can keep using all CPUs (top-app cpuset) almost indefinitely by creating some phantom processes while it is interacting with the user (top-app) and then switches to any other app *in 3 min*. This change fixes this issue in a somewhat conservative manner. Instead of making sure that the list of phantom processes are up-to-date all the time, it tries read the information only for the app process being considered. In addition, the information is not updated to the phantom process list, in order to avoid lock contention. We may revisit this in the future though. In other words, if we are going to change the process group of app A, we collect only the phantom processes that belong to A. This is much more lightweight compared to the full-scale update as it requires a single read of the cgroup file. Of course, a single file read is anyway an IO which should be avoided on hot paths if possible. This change satisfies that because the identification of the phantom processes and setting their process group is still done in the handler thread (mProcessGroupHandler in OomAdjuster). Bug: 375950473 Bug: 375058190 Flag: com.android.server.am.phantom_processes_fix Test: start the terminal app, move away from it (by going home for example), and then execute `cat /proc/$(pgrep crosvm_debian)/cgroup. Check that its cpuset is changed to FOREGROUND, not TOP-APP. (after enabling the flag) Change-Id: Ic333543b90102e112908446bad6c36a48876caa0
Loading
Please register or sign in to comment