What are OOM priorities?

Someone brought it to my attention that OOM Priority wasn’t explained in the Help on AMM.  And it seems I haven’t written about it on this blog either.   So I thought I would just do a quick explanation of my understanding.  I don’t profess to be an expert on the subject so please feel free to correct me if anything I mention isn’t correct.

So to start OOM (out of memory) priority is a priority that the Android kernel sets for each process on the Android system.  So when the system is out of memory processes will get killed in descending order i.e. from low priority to high priority to release memory.  The priorities start at -16 at the highest to to +15 at the lowest.  -17 is a special value that is supposed to exclude the process from the oom-killer.  More on the “suppose” later.

These OOM priorities are split into 6 groups that loosely translate to the 5 levels of importance hierarchy in the Andriod SDK.  The 6 groups and their associated priorities are:

  • Foreground Application: -16 to 0
  • Visible Application: 1
  • Secondary Server: 2
  • Hidden Application: 3 to 7
  • Content Provider: 8 to 14
  • Empty Application: 15

OOM Grouping

In AMM you can look at apps grouped into their OOM priorities by looking at the Running Proceses list in the OOM grouping view.

Now about that “suppose” mentioned earlier.  After I implemented the functionality to change the priority of the app I noticed (and numerous people reported) that the priorities weren’t sticking after they were changed.  This included the keep-alive value i.e. -17 OOM priority.  It seems the Android kernel still manages the priorities even if you change them.  What makes this even more confusing is that different users seem to be getting varying mileage when they change.  For some people the kernel changes the priorities back immediately while for others it seems to stick for a long time.

So with that explanation I would suggest that you change these priorities carefully.  Obviously changing them will have could have real effect for how the phone and app runs.

If you still have question on this topic feel free to contact me via the usual channels i.e. comment, email, google group.  Not comments in the Market.