5

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?

Koolstr
  • 464
  • 1
  • 10
  • 20

4 Answers4

1

I read the whole problem. I think while playing heavy games or using any app that requires higher RAM memory, some other process is restricting it from doing so, just like a semaphore. Because your error says that it is unable to open

/dev/memcg/apps/uid_99032/pid_5430/memory.soft_limit_in_bytes

for increasing the usage memory.

See this documentation on kernels for more information about memory.soft_limit_in_bytes

https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt

Can you give me the logcat so I can further analyze this problem?

Koolstr
  • 464
  • 1
  • 10
  • 20
Akash Badam
  • 476
  • 2
  • 9
  • Your intuition is likely right. I've already approached the problem that way, but haven't gotten anywhere yet. Thanks for the documentation link, it was an informative read, but did not help me progress any closer to a solution. – Koolstr Sep 03 '18 at 05:24
  • @Koolstr Is your mobile rooted. – Akash Badam Sep 06 '18 at 05:26
  • Of course! How else could I be running a custom ROM? – Koolstr Sep 06 '18 at 06:00
  • Ok then install a good terminal emulator like termux and gain root access by **su** command.Then give us information of all the running apps that are using memory space by command `ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem `. For more information [https://www.tecmint.com/find-linux-processes-memory-ram-cpu-usage/](https://www.tecmint.com/find-linux-processes-memory-ram-cpu-usage/) – Akash Badam Sep 06 '18 at 06:12
  • I tried it and that's a decent way to see the info. I'd recommend using a GUI for things like this, and Simple System Monitor (https://play.google.com/store/apps/details?id=com.dp.sysmonitor.app&hl=en_US) works for me really well. – Koolstr Sep 06 '18 at 23:21
1

It looks like the most troubling aspect of the problem might have been natively resolved. After updating to the newest version of Webview (v68.0.3440.91, finally found the changelog here), it no longer hangs the main thread when attempting to be killed, and it seems to be less prone to producing the error entirely.

I don't see any relevant changes they made that might have fixed it, but it works now, so I'm happy. I just wish they would provide a real changelog for Webview, instead of the generic 'bug fixes and performance improvements' statement.

I'm gonna give this a few days to see how consistent it is, and report back.

EDIT: The problem returned, unfortunately. The fix was temporary until I rebooted my phone. I have no idea what occurred in that singular boot that made it work as intended for once...

Running the latest version of Webview (v69.0.3497.91) doesn't fix the problem either, and I find it hard to believe that they would revert whatever change it was that seemed to fix it before. Although, notably, the hard lags seem to be occurring with less frequency. Nonetheless, I'm practically ready to give up hope on ever solving this... :/

Koolstr
  • 464
  • 1
  • 10
  • 20
1

i hat the same issue with the following pid:

lowmemorykiller: Error opening /dev/memcg/apps/uid_10019/pid_25083/memory.soft_limit_in_bytes; errno=2

What I tried to do is checking if the file is really there and accessable. This was not the case for me. The whole folder pid_25083 was missing. So I created it with the intension to create the file after this. But creating the folder did solved the issue for me already. I did the following as SU (remember to change your pid):

serranoltexx:/ # cd /dev/memcg/apps/uid_10019
serranoltexx:/dev/memcg/apps/uid_10019 # mkdir pid_25083
serranoltexx:/dev/memcg/apps/uid_10019 # cd pid_25083
serranoltexx:/dev/memcg/apps/uid_10019/pid_25083 # ls
cgroup.clone_children           memory.move_charge_at_immigrate
cgroup.event_control            memory.oom_control
cgroup.procs                    memory.pressure_level
memory.failcnt                  memory.soft_limit_in_bytes
memory.force_empty              memory.stat
memory.limit_in_bytes           memory.swappiness
memory.max_usage_in_bytes       memory.usage_in_bytes
memory.memsw.failcnt            memory.use_hierarchy
memory.memsw.limit_in_bytes     notify_on_release
memory.memsw.max_usage_in_bytes tasks
memory.memsw.usage_in_bytes
serranoltexx:/dev/memcg/apps/uid_10019/pid_25083 #

And finally the issue was gone. Its not a good solution but a workaround.

  • Finally, a suitable workaround. Thank you for sharing. Obviously not the most elegant or ideal, but it does seem to temporarily work, while the apps are open. With this, I've been able to narrow down the problem more precisely, and will update the original question with the new details. – Koolstr Sep 20 '18 at 23:22
-1

Its probably the kernel version that ROM is using...its something that the ROM builder would have to address as far as I know..hence going back to XDA forums to see if you can get a hold of that particular ROM's contributors

Fred Grott
  • 3,505
  • 1
  • 23
  • 18
  • I've done my best to reach out to the contributors. Unless you can think of an effective way to get their attention, this doesn't help... – Koolstr Aug 31 '18 at 19:28