8

Can anyone elaborate or provide a link to android memory management. I am confused about Android virtual memory scheme. How is paging done in Android? Without a hard disk, how do they do it? Do they have caching?

Jim G.
  • 15,141
  • 22
  • 103
  • 166
agent.smith
  • 9,134
  • 9
  • 37
  • 49
  • 1
    Regular Android devices with stock ROM do not have a SWAP file or partition. Only some custom roms do have/allow/require them. If Android has low memory it stops and destroys unused apps. – Robert Jul 13 '15 at 19:51

2 Answers2

4

Here are some links about memory management on android

A detailed post http://mobworld.wordpress.com/2010/07/05/memory-management-in-android/

And a nice blog post for memory analysis http://android-developers.blogspot.com/2011/03/memory-analysis-for-android.html

How to avoid memory leaks http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html

Sean O'Toole
  • 4,304
  • 6
  • 35
  • 43
Yekmer Simsek
  • 4,102
  • 3
  • 21
  • 19
  • thanks for your reply. But this is a view from Application level. I want to know more about the kernel level. How paging is done? How pages are swapped out in the absence of hard disk. I have general idea about how it is done. But want to know more in depth. – agent.smith Apr 13 '11 at 20:19
  • Since Android uses linux kernel, i would assume the linux information for the appropriate kernel version(s) would apply. The application details are equally important because you must keep in mind that your applications are going to be executing in a Java Virtual Machine (Dalvik's Virtual Machine), which has its own specificities and works in a relatively isolated way from the Android-linux OS – Luis Miguel Serrano Apr 13 '11 at 22:03
2

The linux kernel and the jvm should be treated as apples and oranges. Confusing the two can be disastrous.

For example, the linux kernel's virtual memory is essentially a swap file, and does not set limits on individual process size, which results in "thrashing" or endless swapping when the file is full.

In stark contrast, the jvm (which is just another linux process) sets a common maximum size for its applications (eg 256MB). Android apps generally run in their own jvms, preventing any given jvm from "thrashing". Rather the GC will throw an OOM and exit.

Android will further kill off apps (jvms containing tasks that are groups of activity threads) when running out of kernel virtual memory, and restart them later if required. It can still freeze up (thrash), but not as often as, for eg. an unattended linux database or web server.

The solution for a thrashing (frozen) android is exactly the same as a thrashing linux server. Bounce (cycle the power). Because it is a linux server.

It is somewhat profound to consider that Android has given the world millions of fully connected yet mostly idle pervasive linux servers that can host endless swarms of multithreaded processes (jvms are only one type).

It has the bones of the ultimate super computer, dwarfing even the most elaborate data centre.

That is not even mentioning that most androids have parallel processors (GPUs) that are 100s of times faster than their CPUs, again just sitting idle. Except for a few gamers who know how to fire them up.

Just intended as an overview, there are already excellent links on this thread.

Dominic Cerisano
  • 3,522
  • 1
  • 31
  • 44