skittles9823 / QuickSwitch

831 stars 40 forks source link

This module surprisingly makes duplicate classes and hurts phone performance #7

Open Mygod opened 4 years ago

Mygod commented 4 years ago

To reproduce this, enable this module in Magisk Manager, and run logcat | grep RAM:

11-19 15:46:45.080  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:46.052  4175  7838 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:46.888  8900  8900 W m.spotify.musi: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:47.047  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:48.020  4175  7838 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:48.651  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:49.045  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:49.680  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:50.063  4175  7838 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:50.728  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:51.116  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:51.873  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:51.943  9793  9817 W roid.apps.turb: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:52.152  9826  9851 W .apps.turbo:aa: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:52.216  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:52.754  9866  9893 W .apps.turbo:ss: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:53.048  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:53.375  4175  7838 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:54.411  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:54.508  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:55.553  4175  7838 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:56.424  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:56.575  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:57.512  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:57.564  4175  7838 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:58.523  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:58.534  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:59.515  4175  7838 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:46:59.578  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:00.481  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:00.566  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:01.352  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:01.446  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:02.221  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:02.422  3047  3047 W .gms.persisten: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:03.122  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:03.553  4175  6377 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:04.406  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:05.341  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.
11-19 15:47:05.564  4175  4175 W gle.android.gm: NOTE: This wastes RAM and hurts startup performance.

Running top and it can be noted that gms takes up >100% of memory. After disabling this module in Magisk, there are still warnings like this but for other apps only (not gms) and the memory leak seems to have gone away.

Running OxygenOS 10.0 (based on Android 10) on OnePlus 6, Magisk 20.1, QuickSwitch v2.1.0 (which provider I choose does not seem to have an impact on this issue).

Mygod commented 4 years ago

Related code in AOSP: https://android.googlesource.com/platform/art/+/master/runtime/oat_file_manager.cc#511

skittles9823 commented 4 years ago

Yea I'm aware of this issue, but honestly I've no idea why QuickSwitch is causing it. The overlay has no code, it only overlays a single value and grants permissions to the launcher.

I'm waiting on Paphonb to have a look at the issue and see if he has any insights.

Mygod commented 4 years ago

From my observation, if the module is disabled, this warning is fired only once per process (and only for certain apps). Here are some examples fired by Google apps:

11-19 16:07:39.663 26873 26897 W roid.apps.turb: Found duplicated class when checking oat files: 'La;' in /data/user_de/0/com.google.android.gms/app_chimera/m/00000004/DynamiteModulesC.apk and /data/app/com.google.android.apps.turbo-kGCE77wOqePkVcL4ueMMwA==/base.apk
11-19 16:10:52.714  5442  5466 W android.vendin: Found duplicated class when checking oat files: 'La;' in /data/app/com.android.vending-xlz8xYLCQYNgsQPrMOfZRA==/base.apk and /data/user_de/0/com.google.android.gms/app_chimera/m/00000005/GoogleCertificates.apk
11-19 16:10:53.136 29480 29515 W .apps.nbu.file: Found duplicated class when checking oat files: 'La;' in /data/app/com.google.android.apps.nbu.files-Rmsgl9ijVDYstdFLcc4K3g==/base.apk and /data/user_de/0/com.google.android.gms/app_chimera/m/0000000a/dl-VisionOcr.optional_19629000400.apk
11-19 16:11:04.842 29751 29781 W .android.chrom: Found duplicated class when checking oat files: 'Laa;' in /data/app/com.android.chrome-mCjRNcvDLqiC4Xriijc-JQ==/base.apk and /data/user_de/0/com.google.android.gms/app_chimera/m/00000005/GoogleCertificates.apk

Maybe somehow QuickSwitch is causing GMS to crash partially and restart itself constantly? (one can note that it is extremely slow to use GMS related functionalities when quickswitch is enabled)

P.S. QuickSwitch also seems to cause a similar (repeated dup classes warning) issue with this non-system non-Google app.

skittles9823 commented 4 years ago

Yea it's weird though, it only happens on some devices and I can't reproduce the issue on my own devices.

I think Paphon has a OP6 though so he may be able to debug it himself.

ch0rus commented 4 years ago

QuickSwitch is not the issue here, I'm having the same problem with Magisk on my Xiaomi phone

11-20 11:23:03.098 31365 31365 W gle.android.gm: Found duplicate classes, falling back to extracting from APK : /system/product/priv-app/GmsCore/GmsCore.apk 11-20 11:23:03.098 31365 31365 W gle.android.gm: Found duplicated class when checking oat files: 'La;' in /system/product/priv-app/GmsCore/GmsCore.apk and /system/product/priv-app/GmsCore/GmsCore.apk

Note that it's checking for duplicates between an APK and the same APK

alvinhochun commented 4 years ago

I think the logcat log items mentioned are red herrings.

I just created an issue over at Magisk repo, which I think is probably what this issue is about: https://github.com/topjohnwu/Magisk/issues/2107

alvinhochun commented 4 years ago

I've been running Magisk with the fix topjohnwu/Magisk#2110 for a few days, and while the specific issue regarding /product/overlay was fixed, it appears that there are other issues causing com.google.android.gms to occasionally come out to eat CPU cycles. The situation is not as bad as before the fix though. I also have no clue whether it is related to Magisk or not as I don't have a spare locked device for comparison. It happens regardless of QuickSwitch.

skittles9823 commented 4 years ago

@alvinhochun thanks for a further update.

I'm honestly so confused by this issue tbh.

androidacy-user commented 4 years ago

Looking like an issue with any module replacing files in /product not just quickswitch Damn pixel devices lol

alvinhochun commented 4 years ago

Well, 8 hours of uptime and only 83 minutes of CPU time used, not too bad?

  PID USER         PR  NI VIRT  RES  SHR S %CPU  %MEM    [TIME+]ARGS
 2525 u0_a27       16  -4  80G  74G  74G R 97.0  2098  83:07.21 com.google.android.gms

Just throwing in my thoughts:

This line that I keep seeing repeatedly:

12-06 22:27:31.042  2525  2525 W gle.android.gm: Found duplicated class when checking oat files: 'La;' in /data/app/com.google.android.gms-piffaV1U2S7R9M-72_owuw==/base.apk and /data/app/com.google.android.gms-piffaV1U2S7R9M-72_owuw==/base.apk

It is actually comparing the same file with each other. And this line apparently doesn't appear when QuickSwitch is disabled unlike some other "Found duplicated class" lines that also appears regardless of QuickSwitch.

Incidentally, "Found duplicated class" lines that compares the same file also appears for other apps that has MagiskHide enabled, whenever they are started.

This check happens in the function CheckClassCollision in oat_file_manager.cc. Here's the source of that line.. I can't really tell what is going on from just reading the source code. If someone happen to have a debug build (or is it the eng build) of Android they can perhaps try debugging it (maybe adding some printf is even more effective). They might not even need google apps installed to get the problematic behaviour.

alvinhochun commented 4 years ago

I sort of have an idea of putting a debug build of com.android.runtime on my device so that I might be able to get some more clues out of it. Now I have a generic arm64 AOSP eng build (that doesn't boot from emulator due to timeout issues so not very useful), but it does have what I want -- a debug build of com.android.runtime. However, since my device uses dynamic partitions it seems literally impossible to modify the system partition, not even if I manually unpack and repack system.img (that would change its size making it too large to fit in). A Magisk module wouldn't work either since apexd-bootstrap runs on early-init. I am thinking I might have to hack Magisk's init to play tricks to make it work.

So, what I think I want to do is to remove (hide) /system/apex/com.android.runtime.release.apex and add the directory /system/apex/com.android.runtime.debug from the AOSP build, and then hope that apexd-bootstrap will load it into /apex. If this doesn't work then I'll need to figure out how to pack a .apex file.

Any other ideas?

Edit: I have a feeling this will not work since the files are probably signed...

Efun commented 4 years ago

I'm actually getting the same thing when I patch OnePlus launcher on my OP7P, but with gms.persistent instead of regular gms. It was causing really severe Google Play Services battery drain and my phone was getting pretty warm. From reading logcat, the issue seems to go away when I disable Magisk Hide on specifically gms and gms.persistent. Before disabling hide on these, there would be bursts of 4-5 messages on logcat every couple of seconds.

skittles9823 commented 4 years ago

@Efun Correct. The only GMS process need to hide is com.google.android.gms.unstable

KevinMX commented 3 years ago

So, uh, this issue still exists? I'm also having stuttering, out of memory issues on my device, and that's not only for Google apps, non-Google apps have the same issue. Once enable Magisk Hide to them, they will eat up much more memory and can cause the system to freeze... Any solutions by this point?

skittles9823 commented 3 years ago

@KevinMX Not much to do on my side as it's a bug with MagiskHide.

In 3.1.6-3 I changed some stuffs which might have helped with the issue but I guess it didn't.

KevinMX commented 2 years ago

Seems I finally have a solution now: https://github.com/Magisk-Modules-Alt-Repo/magisk_overlayfs

Steps:

  1. Install this module and QuickSwitch
  2. Setup QuickSwitch as normal
  3. Enable OverlayFS for QuickSwitch (steps as in the overlayfs repo, I only tested with both overlay and skip_mount enabled)
  4. Reboot and enjoy.

So far, no more memory leaking (or some sort) on my Xperia XZ2 Compact. Google services are no longer eating up all my RAM.

It's been two years since Magisk 20 and Android Q and finally we can solve this. @skittles9823 Take a look on that overlayfs module. I'm not familiar with the code, maybe there's something you can do on your side. Thanks in advance.

DanGLES3 commented 2 years ago

Seems I finally have a solution now: https://github.com/Magisk-Modules-Alt-Repo/magisk_overlayfs

Steps:

  1. Install this module and QuickSwitch
  2. Setup QuickSwitch as normal
  3. Enable OverlayFS for QuickSwitch (steps as in the overlayfs repo, I only tested with both overlay and skip_mount enabled)
  4. Reboot and enjoy.

So far, no more memory leaking (or some sort) on my Xperia XZ2 Compact. Google services are no longer eating up all my RAM.

It's been two years since Magisk 20 and Android Q and finally we can solve this. @skittles9823 Take a look on that overlayfs module. I'm not familiar with the code, maybe there's something you can do on your side. Thanks in advance.

That module relies on setting an custom OverlayFS filesystem for the Quickswitch module (instead of using Magisk's magic mount), so while it does solve the issue it isn't a perfect fix as not all devices (specially older ones) support OverlayFS

The root of the issue is a combination of how magiskmount+magiskhide/denylist interact with a static framework overlay, that's something only Topjohnwu can fix (if it's even possible to fix without relying on OverlayFS)