[TECH] Android's Internal Task Killer - and the effect of modifying it (ROOT ONLY)
I wanted to explain how Android's internal Task Killer works to help people understand how it wokrs. After I stumbled across an app, Auto Memory manager, and posted a thread asking for questions, I was pointed toward another thread with a lot of good technical information about the inner workings of Android's internal Task Killer. (thx JonKyu) Here's what I took from the 20+ pages of that thread, and I'll try to break down what I learned with the high points, and feel free to visit that thread if you want the bits and pages of it.
How to configure Android's *internal* taskkiller - xda-developers
And this is meant to be informative, so just as a CYA, please do what you will with this knowledge at your own risk.
Android has a task killing system in place where it groups processes into 1 of 6 types. The type that is assigned depends on how important that process is to what the phone is actively running. Here are the 6 types that Android uses with definitions, which neatly correspond to the sliders in the Auto Memory Manager application I found.
FOREGROUND_APP: // This is the process running the current foreground app. We'd really rather not kill it! Value set in system/rootdir/init.rc on startup.
VISIBLE_APP: // This is a process only hosting activities that are visible to the user, so we'd prefer they don't disappear. Value set in system/rootdir/init.rc on startup.
SECONDARY_SERVER: // This is a process holding a secondary server -- killing it will not have much of an impact as far as the user is concerned. Value set in system/rootdir/init.rc on startup.
HIDDEN_APP: // This is a process only hosting activities that are not visible, so it can be killed without any disruption. Value set in system/rootdir/init.rc on startup.
CONTENT_PROVIDER: // This is a process with a content provider that does not have any clients attached to it. If it did have any clients, its adjustment would be the one for the highest-priority of those processes.
EMPTY_APP: // This is a process without anything currently running in it. Definitely the first to go! Value set in system/rootdir/init.rc on startup. This value is initalized in the constructor, careful when refering to this static variable externally.
So what happens is when the free memory (ie: what your taskiller reports) gets below a certain predetermined value, it starts killing the least important processes off, starting with the bottom of that list. (ie: at 20MB free kill empty processes, at 15MB free kill Content Provider processes).
For people with root, there are applications in the market that let you change the predetermined values that Android starts killing off process types. The one I used and reference in this post is Auto Memory Manager, but MinFree is another one by one of the guys over at XDA. Same idea, just a different look. The reason you might want to modify this, is to force Android to be more strict with it's application policing.
The consensus over there, is that people are getting generally better performance, battery life, response, etc. by tweaking these values. The upside over a normal task killer, is this is something that is already running in the Android OS, so it's not adding any additional resource usage, just modifying how it already acts.
So for example, on the app if you wanted to make it so whenever the free memory got below 70MB, it would kill off all the empty processes, in the application, you would simply drag the Empty Applications slider up to 70MB. It's just a matter of fine tuning the right mix. I would recommend not putting the top 2 or 3 values very high, as those processes are things that are actively running, and may have a user impact. Generally speaking, you want to try to play with the bottom 3, if you do touch the top 3 please understand what you're doing.
Also, it doesn't change the values permanently, as it requires the values be reset on reboot (not built into the application at this time). But you also don't have to worry about permanent changes to the system if you decided to uninstall or anything.
If anyone has any questions I'm sure we can all help each other out. I'm also interested to see after people start using this, what they're finding good results with as far as settings for our devices. If you find something that works particularly well for you, please feel free to post your numbers for other users to experiment.