I want to know if android supports virtual memory concept.I know windows supports virtual memory but what about android? Do our android phones store less used data out of RAM?
2 Answers
Android doesn't use virtual memory (in the sense you mean) by default, because it has a higher-level mechanism. Transparently writing pages of memory to flash storage is bad for battery life (and for the life of your flash storage, which can only handle a certain number of writes) and performance, especially since the application has no control over which parts of memory are "paged out".
Instead, Android manages memory using the same mechanism it uses to decide when to terminate apps that are no longer running. When it finds it needs to free up some RAM, it chooses an app that was cached (one that isn't currently in use). It terminates this app to free its RAM, but first, it gives that app's activities a chance to save some state by writing it to storage.
By making the app explicitly choose what to save to storage, instead of just saving the whole of that app's RAM contents, Android can reduce the amount it has to write from storage and later read back. This saves storage, and saves battery power and time, because each write to and read from storage costs time and power.
Of course, Android is based on Linux, and uses virtual memory in other ways not visible to the user. Android systems must have an MMU, so apps use virtual, not physical, addresses. This protects apps from having their private data in RAM read by other apps, which is necessary for a secure system. It also uses Linux's delayed-commit to save memory: when a process asks for more memory, it only gets pages of physical memory when it actually uses them. Virtual memory also allows memory-mapped access to files in the filesystem and to memory-mapped hardware. None of this is anything to do with swap files, but it means it's not quite accurate to say that Android doesn't use virtual memory.
You can enable swap on Android: see this related question for more details. It's not recommended to do so in most cases, because it defeats the memory-saving mechanism described above. Adding a swap partition will make the battery run down faster, wear out your flash storage faster, and make the system less responsive. You'd only want to do it if you absolutely must run an app that requires more RAM than your device has.
-
Ok,but can
t Android use internal memory as virtual one?And also does Android limit multitasking if you say it kill some processes to make up space?And how much multitasking Android supports as our windows pc
s? Commented Jan 31, 2014 at 18:50 -
1
-
but can`t we make swap in device internal memory,not in flash memory? Commented Feb 1, 2014 at 7:48
-
@WSS The internal storage is flash too, just like an SD card. Commented Feb 3, 2014 at 10:17
-
Enabling real swap would be good idea to handle native processes leaking memory (e.g. Cyanogenmod Nightlies every now and then). However, because Dalvik really does not like real swap, there would be need for additional hacks to keep all dalvik processes out of swap... Commented Jul 4, 2014 at 8:45
I do not know if i am right but i think that androif kinda contains a virtual memory just like a pc. Equal to the size of the RAM. If it were not so i do not think that the android devices would be slow once the hard disk is nearly full. Yeah. any comments are welcome
-
You mean swap. But that's mentioned in the other answer already. Also, if you're not sure about your answer it is always better to research more before answering since this site doesn't entertain discussion/commentary (unless it meets the criteria of a partial answer IMO). I hope you understand my point why this website strives for only quality and to the point answers. Have a nice day for research and please, do come back with it for a better answer. :-)– Firelord ♦Commented May 14, 2015 at 7:07