Apart from huge camera megapixels and high refresh rate displays, the biggest trend in the smartphone world seems to be Virtual RAM. Some refer to it as Dynamic RAM expansion, while others call it Extended RAM. Regardless of what it’s called, the idea remains the same. Allow users to use some part of their storage as RAM to help multitask.
We will discuss in this guide how memory management in Android works and how the idea of Virtual RAM differs from it. We will try to ponder whether Virtual RAM is even required on Android or not. So let’s get to it.
How Memory Management Works on Android
First things first, it’s important to understand how Android manages your memory. Within Android, there are 3 types of memory. First is your RAM, then you have zRAM, and finally your storage. RAM is the basic memory module inside which all apps run. Then there’s your onboard storage, either UFS or eMMC on budget devices. Finally, we have zRAM. Essentially, zRAM is a partition inside of RAM.
The idea behind zRAM is that low-priority data on RAM is compressed and stored inside zRAM. Because RAM is any day faster than your normal storage, having compressed data inside zRAM, which is a part of RAM, is still going to be faster than accessing it off your storage, even if you count the compressing and uncompressing times.
Now that we’ve established the 3 different types of memory available to Android let’s understand how the OS handles it all. So Android makes use of paging techniques. How it functions is that RAM is broken into pages, where each page is typically of 4KB. Whether that page is free or actively used, they combine to show used RAM and unused RAM, respectively. Then, the kernel’s task is to convert used memory into free memory. It does so by shifting the data on those used pages to your storage.
What Is Paging and How It Works
To understand how it works, let’s understand the kinds of pages. You can classify Pages into two types – Clean and Dirty pages. The clean pages have an unmodified copy saved in the storage space. Meanwhile, dirty pages have a modified copy of data stored in storage. Now, what is this modified and unmodified? Let’s call it dynamic use of your memory.
Unmodified copies are static data, while modified copies are dynamic data changes every second. Android can purge the clean pages when needed since they’re not dynamically accessing the resources. That helps to free up the RAM and make more of it available. That might sound a bit too technical, so let’s make it simpler to understand using real-world applications.
Suppose you open Twitter, browse through your feed, and then switch to something else. Twitter is still there in your RAM. But if you don’t open it for a while, its priority decreases. Later on, if you launch something new, Android will have to free the memory that Twitter is using. So what it does is that it shifts its values and data to the storage, and gives you free space. This is why when you launch Twitter again, it will first show you the timeline that it was hibernated at, and then refresh. The same is for Facebook, Reddit, or similar apps like Calculator or Notes. These apps use Clean pages since a copy of their data is statically saved inside your storage.
Now, for dirty pages, consider Spotify or any music player. You start some music inside the player and then keep it running in the background without opening the app. However, the system cannot close it since it’s dynamically using your memory. As a result, Android compresses the app and shifts it to zRAM when more free RAM is required.
What Is Virtual RAM
Now that you’ve know how Android manages memory, you must wonder – where does the Virtual RAM feature comes in? Remember how we said that zRAM is also a part of RAM? The way Virtual RAM works is that it creates a swap partition on your storage space, and uses it as extra zRAM.
Because zRAM is stored on your RAM only, there’s a limit to the number of pages you can compress and store in it. With a swap partition, you can use your storage space as extra zRAM, for compressing and shifting apps, while making space available in your actual RAM.
Is This Feature New
So, is all of this new? Well, not really. Linux has been using swap partitions since the beginning. For Android, custom kernel users have been using their SD Cards to create additional swap partitions to improve memory management.
As such, brand manufacturers are just giving you the same feature baked inside their Android skins. However, it does beg the question – if the feature is so helpful, why hasn’t it been a part of Android’s source code?
Is Virtual RAM Good or Bad
The answer lies in the very basic working of Virtual RAM itself. While the feature does allow you to run more apps on your device by compressing hibernated apps and shifting them to your storage, it does more harm than good. Because swap partitions are essentially storing active apps, there’s a higher sense of reading and writing involved.
This works fine on traditional storage, but flash memory has a limited number of reads and writes. So by using SWAP or Virtual RAM, you are technically lowering your device storage’s life span.
This is also highlighted well on Android’s developer page. “On Android, storage isn’t used for swap space like it is on other Linux implementations since frequent writing can cause wear on this memory and shorten the life of the storage medium.” Another example of this is in the new Apple M1 MacBooks. Those machines use a swap partition on Apple’s SSDs, for which users have been complaining quite a lot.
Does Virtual RAM Matter and Should You Use It
Essentially, it all depends on how you define multitasking. If it is juggling between just two to three active apps, then sure, virtual RAM does help with that. But if you keep switching between 5-6 heavily active apps, virtual RAM won’t do anything because it would keep shifting the apps.
At its core, the virtual RAM feature does allow you more RAM space available for apps to run. However, it comes at the cost of your storage. If you intend to keep using your device for more than two years, we reckcon that using virtual RAM might not make much sense.