- Published on
Android LRU process eviction
- Authors
- Name
- Jay Shah
- @jay_shah_c
I was recently trying to understand how process eviction works in Android.
Android is a huge operating system now, and has evolved a lot over the years. Although we can see that the source code is open for everybody to see here
Why does process kill/eviction happen?
Like any other Operating System, the job of Android OS is to effectively manage resources like CPU and RAM, between a large number of applications. This way Android keeps track of the most relevant apps and their components via an LRU list.
What log do we see on process eviction/kill?
We see something like following in the logcat, when a process with PID 31323
gets killed.
I/Zygote: Process 31323 exited due to signal (9)
I/ActivityManager: Process com.example.backgroundwork (pid 31323) has died: cch+6CRE
How do I see the process LRU list?
Run the dumpsys
command, which holds all the state within the operating system.
adb shell dumpsys activity | grep 'Process LRU list' -A 50
How does the LRU list look like?
Here the sample app we are using has package name: com.example.backgroundwork
What happens as we open more and more apps?
Our sample app process with name com.example.backgroundwork
will keep moving down the LRU list and finally be evicted.
Now it is the second last entry in the screenshot, so If I open two more apps, our sample app with package name: com.example.backgroundwork
will be evicted from the process list and will be killed by the OS.
What do the different tags mean?
We see process level tags like : PER
, TOP
, SVC
, CAC
, CRE
etc. They signify process level states and can be found in more detail here in ActivityManager
: here