New PeriodicCleaner killing processes "randomly"


crok.bic

Members
12 Sep 2017
246
67
Hi Everyone..

So I hope this is a bug and not a feature..

Xiaomi Redmi Note 9 Pro (joyeuse) && Android 12 && MIUI 13
xiaomi.eu_multi_HMNote9ProEU_V13.0.2.0.SJZMIXM_v13-12-fastboot

This issue is persistent since ages, really. I can't really tell when I figured this out (like 2 years ago) but the thing is:
There's a kind of service running in the Xiaomi.EU ROMs of Joyeuse called "PeriodicCleaner".

Code:
Date Time            PID  TID   APP TAG Text
09-11 01:27:56.824  1000  2075  2123 I ProcessManager: Kill reason PeriodicCleaner(4|2|pressure) from pid=2075
09-11 01:27:56.849  1000  2075  2123 I ProcessManager: PeriodicCleaner(4|2|pressure): kill com.facebook.orca Adj=400 State=10
09-11 01:27:56.850  1000  2075  2123 I ActivityManager: Killing 7223:com.facebook.orca/u0a275 (adj 400): PeriodicCleaner(4|2|pressure)
09-11 01:27:56.861  1000  2075  2123 I ProcessManager: PeriodicCleaner(4|2|pressure): kill com.facebook.orca:fwkstartlog Adj=935 State=19
09-11 01:27:56.861  1000  2075  2123 I ActivityManager: Killing 8249:com.facebook.orca:fwkstartlog/u0a275 (adj 935): PeriodicCleaner(4|2|pressure)
09-11 01:27:56.866  1000  2075  2123 I ProcessManager: PeriodicCleaner(4|2|pressure): kill dev.sasikanth.pinnit Adj=250 State=5
09-11 01:27:56.866  1000  2075  2123 I ActivityManager: Killing 5329:dev.sasikanth.pinnit/u0a240 (adj 250): PeriodicCleaner(4|2|pressure)
09-11 01:27:56.870  1000  2075  2123 I ProcessManager: PeriodicCleaner(4|2|pressure): kill com.life360.android.safetymapd Adj=400 State=10
09-11 01:27:56.870  1000  2075  2123 I ActivityManager: Killing 6709:com.life360.android.safetymapd/u0a542 (adj 400): PeriodicCleaner(4|2|pressure)
09-11 01:27:56.876  1000  2075  2123 I ProcessManager: PeriodicCleaner(4|2|pressure): kill com.google.android.webview:sandboxed_process0:org.chromium.content.app.SandboxedProcessService0:0 Adj=905 State=10
09-11 01:27:56.877  1000  2075  2123 I ActivityManager: Killing 9589:com.google.android.webview:sandboxed_process0:org.chromium.content.app.SandboxedProcessService0:0/u0a542i2 (adj 905): PeriodicCleaner(4|2|pressure)
09-11 01:27:56.879  1000  2075  2123 I ProcessManager: PeriodicCleaner(4|2|pressure): kill com.life360.android.safetymapd:service Adj=500 State=10

As you can see it is killing processes.. the problem with this is that these are actually locked apps, battery optimization of MIUI is set to "no restriction" to ALL of them and even Autostart, etc. is enabled as well. As you can see it is killing Facebook Messenger at night even though it is running with ADJ 400(!!!), Pinnit with ADJ 250(!!! this app actually has a permanent notification just to keep itself alive!), Life360 running with ADJ 400, etc. The above sandboxed chromium processes are all opened webpage tabs in a browser I'm using. This is not okay.

This is how the help looks like of the service:
Code:
joyeuse:/ $ cmd periodic
Periodic Cleaner commands:
  help
    Print this help text.

  dump
    Print fg-lru and clean history.

  clean [-r REASON]
    Trigger clean action.
      -r: select clean reason
          REASON is one of:
            periodic
            pressure-low
            pressure-min
            pressure-critical
            pressure-low time
            pressure-min time
            pressure-critical time
          default reason is periodic if no REASON

  enable [true|false]
    Enable/Disable peridic cleaner.

  debug [true|false]
    Enable/Disable debug config.

  updatelist
    Update highfrequencyapp and highmemoryapp list.

This is how a sample stat of the service looks like:
Code:
joyeuse:/ $ cmd periodic dump                                                                                                                                                            

---- Foreground-LRU ----
Settings:
  Enable=true Ready=true FgTrim=false Debug=false mOverTimeAppNum=4 LruLengthLimit=8
  AvailableLow=1450000Kb AvailableMin=1370000Kb AvailableCritical=1290000Kb
Package Usage LRU:
  CurLength:9 CurrentPressure:low
  u0/10275:com.termux:(non-trimed):1970-01-01 01:00:00
  u0/10246:com.dp.logcatapp:(non-trimed):2023-01-07 16:43:53
  u0/10279:com.mycompany.app.soulbrowser:(non-trimed):2023-01-07 16:43:36
  u0/10287:eu.faircode.email:(non-trimed):2023-01-07 16:42:50
  u0/10272:com.facebook.orca:(non-trimed):2023-01-07 16:15:33
  u0/10239:com.beemdevelopment.aegis:(non-trimed):2023-01-07 16:13:40
  u0/10153:com.google.android.gms:(non-trimed):2023-01-07 16:12:25
  u0/10317:com.life360.android.safetymapd:(non-trimed):2023-01-07 15:46:43
  u0/10232:com.google.android.webview.dev:(non-trimed):2023-01-07 15:39:46
High Memory Usage List:
High Frequency Usage List:
---- End of Foreground-LRU ----

---- CleanHistory ----
#0 16:43:53.609 critical 4 pressure {0=[com.facebook.orca]}
#1 16:42:50.048 critical 4 pressure {0=[com.life360.android.safetymapd]}
#2 16:13:40.721 critical 4 pressure {0=[com.facebook.orca]}
#3 16:13:23.572 critical 4 pressure {0=[com.facebook.orca]}
#4 16:12:20.762 critical 4 pressure {0=[com.life360.android.safetymapd]}
---- End of CleanHistory ----


It is part of the ActivityManager of the ROM, started by the system_server (not an AOSP code for sure):
Code:
com.android.server.am.PeriodicCleanerService

Code:
DUMP OF SERVICE system_server_dumper:
SystemServer:
  Runtime restart: false
  Start count: 1
  Runtime start-up time: +17s960ms
  Runtime start-elapsed time: +17s960ms

SystemServiceManager:
  Current phase: 1000
  Current user not set!
  1 target users: 0(full)
  137 started services:
  [..omitted..]
    com.android.server.am.PeriodicCleanerService

It can be disabled with the below ADB command temporarily (until you reboot..):
Code:
adb shell cmd periodic enable false

or with root -if you have- you can disable it permanently with:
Code:
su
setprop persist.sys.periodic.enable false


But obviously starts at each and every reboot again so I have to disable it after every reboot (I'm using termux && web adb) to get rid of it. I know how to disable it with root quasi permanently (setting "persist.sys.periodic.enable" to "false" with a small script using Magisk's "resetprop" or using MHPC.. or simply set it with setprop persist.sys.periodic.enable false and you won't need to set it anymore because it remains in the system) but this is going for like 2 years or so.. my problem is: even though you can technically disable it you can't disable it permanently without root.. and the adb way is a bit clunky for normal users. But the benefit of disabling it is huge if you ask me, saves you from A LOT of headaches..

How can one completely disable it without root? Why it's included anyways?
May I ask you to simply remove it from the ROM builds, please?

The other thing is: Camera boost.. does the same thing.. killing processes.. why on earth MIUI is killing my lightweight browser and other, small footprint apps (like Pinnit) when I simply start the camera? Why it is actually killing anything? If the memory pressure is high just go ahead, I understand.. but when I have 2 apps in my recent list and simply starting the camera.. even the launcher says there's 2.9GB of RAM free.. I know how the android memory management is working (and thus I know that 2.9GB "free" is fake..) but hey, this behavior is not acceptable.

Thank you if you can look into or guide me regarding this.

____
crok
 
Last edited:
  • Like
Reactions: Birraque
Cleaned your text a bit, relax with the CODE tags, it's not working in-line and just creates needless blocks. It's unreadable.
I'm aware of PeriodicCleaner, but it's not our service and we never touched it. Not sure what to tell you here, it's a stock MIUI service that has existed for ages.
It's a very interesting research you've done there though, well done.
 
  • Like
Reactions: crok.bic
Cleaned your text a bit, relax with the CODE tags, it's not working in-line and just creates needless blocks. It's unreadable.
I'm aware of PeriodicCleaner, but it's not our service and we never touched it. Not sure what to tell you here, it's a stock MIUI service that has existed for ages.
It's a very interesting research you've done there though, well done.
Thanks and sorry for the code tags. Probably it worth a try to make some test builds and setting persist.sys.periodic.enable to false. Since /system is not RW anymore build time is the time to change it :) It's kind of an annoying feature.. isn't it? Even though memory management of MIUI can be "fine".. this PeriodicCleaner is messing it up totally.
 
  • Like
Reactions: Miguilista
Thanks and sorry for the code tags. Probably it worth a try to make some test builds and setting persist.sys.periodic.enable to false. Since /system is not RW anymore build time is the time to change it :) It's kind of an annoying feature.. isn't it? Even though memory management of MIUI can be "fine".. this PeriodicCleaner is messing it up totally.
I'm not sure I can afford the time to "experience" the long-term effects and side-effects of permanently disabling it.
I'm also not ready for the "battery life is even worse" spam that would follow such change, if pushed to public releases.
 
I'm not sure I can afford the time to "experience" the long-term effects and side-effects of permanently disabling it.
I'm also not ready for the "battery life is even worse" spam that would follow such change, if pushed to public releases.
Okay, I understood and it's understandable.. and I stick with my above mentioned solutions then.. I'm disabling it for like 2 years now already but I feel I don't experience any side-effect (other than the fact that my apps which I want to run.. just are running - which is nice).

Anyway, thanks for your time to look into this and sharing your thoughts, really, and keep up the good work you do, even at 1AM :D
 
  • Like
Reactions: Miguilista
Hey crok.bic or others,

I have been experiencing this same problem for over 2 months in my Xiaomi mi9T. It is rooted with magisk. I did every single possible setting config, added magisk modules to stop killing the apps in the background but to no success.

This is very important for me. Could u further help me how to solve temporarily or permanently this problem?
Thanks!
 
..then how did you come to the conclusion that PeriodicCleaner is what killing your app? Logs?
I do not know what is cleaning my apps but I saw your post and thought that could be the same. Every night my apps are killed and usually arround the same time. I am trying everything to fix it to no success. I have a xiaomi 9t rooted with magisk. I just disabled com.miui.powerkeeper with adb to try if that helps
 
I do not know what is cleaning my apps but I saw your post and thought that could be the same. Every night my apps are killed and usually arround the same time. I am trying everything to fix it to no success. I have a xiaomi 9t rooted with magisk. I just disabled com.miui.powerkeeper with adb to try if that helps
"I have been experiencing this same problem" -- so perhaps no, you aren't experiencing the same problem. Logcat or never happened, grep (look for) "kill".

btw if you really see that PeriodicCleaner kills your processes and have root open any terminal app and:
su
setprop persist.sys.periodic.enable false
or simply:
su -c setprop persist.sys.periodic.enable false

This will add persist.sys.periodic.enable with value false to /data/property/persistent_properties
and whatever was set in prop files in the ROM will be overriden during booting.
If you don't really need root you can even remove Magisk after you added the prop. Cheers.
 
Last edited: