What is virtual memory and how it works on Android
Virtual memory, a crucial component of modern operating systems including Android, is often misinterpreted as a ploy to convince users that their devices have more RAM than they actually do. This misconception is further fueled by marketing terms like Virtual RAM or RAM Plus, implying virtual memory is an extra feature rather than a standard method for managing memory. Understanding how virtual memory operates on Android can shed light on the management and performance of smartphones under heavy memory loads.
The inception of virtual memory
The concept of virtual memory was first revealed in 1959 at the University of Manchester's computer lab, as part of a collaborative project with Ferranti Computers and Plessey. This innovative system played a key role in the Atlas Computer system, which was then the world's fastest computer. Before the advent of virtual memory, programmers had to manually code data transfers between a computer's main memory (RAM) and secondary storage (like hard drives), a process that was both time-consuming and restrictive.
A revolutionary approach to data management
Virtual memory revolutionized data management by automating much of the transfer process. It enabled programmers to code applications as if they had access to all of a computer's primary memory, without being concerned about its allocation. This was achieved by using secondary storage to map virtual memory addresses stored in its memory, to physical addresses in the primary memory. On Android devices, this critical system task is handled by the kernel.
Concept of virtual memory in simple terms
Consider a library scenario where you can have a limited number of books on your desk. This represents your device's RAM—data that's readily available with minimal effort to retrieve it. Before virtual memory, whenever you needed another book from a library shelf, you had to find it and bring it back to your desk. If there was no space left on your desk, you had to decide which books to return even if you weren't done referencing them.
A personal shelf in the library
With virtual memory, you have your own personal shelf (SSD storage or hard drive) and a library assistant ready to fetch the book you need at any moment. This is similar to the memory mapping technique used for virtual and physical addresses, known as a page table. The process occurs seamlessly and invisibly, allowing you to focus on your work without interruptions.
A shift in the concept of 'address'
The team at the University of Manchester introduced a groundbreaking idea called one-level storage, now known as virtual memory. This concept gives programmers the illusion of having a large primary memory (RAM) at their disposal, even when the computer has a relatively small main memory. At its core is the idea that "address" is separate from "physical location." With virtual memory, your address can refer to any book in the library, regardless of where it is physically stored.
Virtual memory's role in Android
Virtual memory on Android works similarly to the library analogy. However, it involves complex software/hardware mechanisms to manage memory efficiently. In Android, as in other operating systems, a memory address is a way for applications to reference memory locations. Because of virtual memory, these addresses don't have to correspond to physical locations in device's RAM. Instead, Android uses virtual memory to give applications the illusion of having their own large block of continuous memory by leveraging additional secondary storage space.