For quite some time now, I've been trying to debug major bursts of lag/stuttering on my device, when playing heavy games. After analyzing my logcat a lot, I feel I've identified what is causing the spikes of unbearable lag. The following error shows in the logcat consistently whenever the lag spikes occur:
E/lowmemorykiller:
Error opening /dev/memcg/apps/uid_99032/pid_5430/memory.soft_limit_in_bytes; errno=2
It is shown repeatedly, as if it kept trying over and over to kill it. The UID and PID sometimes vary. Presumably, the main thread hangs for a short time every time it is trying to kill it but failing to do so. Why is this happening?
The following error is shown repeatedly as well, mixed among the occurrences of the above one. It is likely related to the problem:
E/ANDR-PERF-RESOURCEQS: Failed to apply optimization [4,0]
Sometimes it would be [2,0]
instead of [4,0]
. These messages are shown truly excessively in my logcat.
After checking my active processes, the UID and PID mentioned always match an instance of Android System Webview
. I found the source apps of these processes by going to Running Processes in Developer Options in Settings. There, the running process is listed as com.google.android.webview:sandboxed_process0
, and there are multiple instances of it, for each app that has a running webview presumably. By checking that process' information, it is mentioned what package started it. So, they originate from a large variety of apps on my phone, sometimes even the game I am playing itself. Consequently, this appears to be an issue with the kernel's lowmemorykiller (LMK) module, more likely than any particular app I have installed.
Anybody have any ideas of what is causing this, what the error really means, how to fix it or work around it, why the LMK is failing to kill webviews, or what is actually going on? I at the very least am looking for a way to control LMK to either ignore trying to kill webviews, to prevent it hanging the main thread when it fails, or a way to force it to be successful in killing them.
For some reason, there is no section for modding the parameters of LMK in Kernel Adiutor for me. My phone is trying to (presumably) kill these webviews even though there is still a substantial amount of free RAM left available, yet the min_free
parameter in Kernel Adiutor is nowhere near the amount of free RAM I have left at the time, so something is going on.
I did suspect at one point that it might be caused by having an obscene number of installed apps on my phone (800-900). I have since lowered it to ~600 apps and the problem persists. I don't think having too many apps is the issue anymore, though it definitely could be.
I'm running the official ResurrectionRemix 8.1 ROM on my OnePlus 3T, with the ROM's default kernel and firmware. This problem was present on the unofficial RR LuisROM, and persisted even after my full-wipe/clean flash to the official RR build that I am currently using. I've asked for help from them and others on XDA, but nobody was willing to assist. I can provide my full logcat if you think it is necessary, but tbh the only relevant messages are mentioned directly here.
EDIT: Here's a latest logcat, of errors and above. I don't think anything useful/new can be inferred from them, but feel free to give it a look.
EDIT 2: Thanks to this answer, which provides a temporary workaround, I've been experimenting and trying to find the root of the problem. It looks like for some reason, UID and PID folders are not being created in the dev/memcg/apps
folder for Webview processes only. This is really odd. They can be manually created (and deleted) in su terminal (though only creating, not deleting, in a root-privileged file manager like ES File Explorer Pro (it gives the same error of 'permission denied'), but I've noticed the following error in logcat preceding the other errors above:
Failed to make and chown /acct/uid_99007: Permission denied
This seems to be the same permission problem that the dev/memcg/apps
directory is having. I've already run chown 777 dev/memcg -R
to ensure all files and directories have RWX permissions, so I don't see how the error is still occurring. What could be holding it back?