In this article, we’ll not only take an overview on Android RAM Management but will also offer tips and suggestions using which you can manage RAM on your Android yourself.
For computer and smartphone enthusiasts, more physical memory (RAM = Random Access Memory) means higher performance and better device responsiveness. RAM capacity and type are among the first things we look at when we try to pick the best device to buy. Truth is, whatever is the RAM capacity of a device without proper RAM management by the Operating System, the memory will become inadequate quite soon.
Android is an Operating System that is capable of running on a variety of devices, with varying physical memory capacity. Using the Linux kernel in its internals, it follows the UNIX philosophy that free RAM is wasted RAM. Instead of keeping RAM free, it tries to keep most used data and Apps in RAM, so they can be retrieved quickly when needed. In this article, we will try to provide some tips for tweaking your Android’s RAM management to get the best out of it.
Android RAM Management Tips
Tune Android Low Memory Killer
As Android usually keeps RAM highly occupied, it needs a tool that frees up memory when needed. This tool is Low Memory Killer and in general, it kills processes in respect to their priority (lowest first), until enough space is freed. Low Memory Killer is a kernel-space tool and its algorithm is configurable. You can learn more about tuning Android Low Memory Killer in the tutorial I wrote some time ago.
Change the extra_free_kbytes Kernel Tunable
This is a Kernel tunable that affects how much RAM is intentionally left empty by kernel at any time. Google engineers introduced it in Android kernels mainly to improve the performance of real-time tasks. It causes the Low Memory Killer to kick in and clean up RAM earlier. Having extra free memory always available allows the kernel to allocate any requested memory faster and avoid device lag in situations of high load.
Android Activity Manager calculates and sets a value for extra_free_kbytes tunable based on screen size on device boot. However, you can always change its value depending on your needs. You can find the extra_free_kbytes Kernel Tunable under /proc/sys/vm/extra_free_kbytes. Setting it to 0 will disable the mechanism completely. If the value is too low, it will make more RAM available to processes, but may cause lag in low-latency tasks (for example music or video playback and gaming). Setting the value too high will kick the Low Memory Killer more often, keeping the CPU busy and increasing battery consumption.
To change the extra_free_kbytes value, you can use a Terminal App (with root privileges) and enter the following command:
echo [value] > /proc/sys/vm/extra_free_kbytes
replacing [value] with a value in KB (for example 1024). You can also use a Kernel tuning App like Kernel Adiutor to tweak this and other Kernel parameters.
Tune the ART Heap Size
Android Apps are coded in Java or Kotlin. They are executed using a tool known as Virtual Machine(VM). Android’s VM is ART from Android Lollipop onward. ART assigns a special fix-sized area of RAM for every App, the heap. This is the total memory available to the App. When the App gets in an out-of-memory situation, the Garbage Collector runs. This tool gathers and frees up memory that is not referenced by the App anymore inside the heap. This makes room for storing new data by the App. However, garbage collection is an atomic operation, which means that the App blocks until garbage collection finishes. If it takes too long for it to finish, the App might suffer significant lag. There are two configuration options for ART heap size, and you can tweak them by editing the build.prop file:
- dalvik.vm.heapsize for large Apps. Large Apps are those that include ‘android:largeHeap’ in their manifest
- dalvik.vm.heapgrowthlimit for normal Apps
Generally, increasing the ART heap size will allocate more RAM to each App, allowing garbage collection to kick in less often and Apps to run faster. However, this also means that fewer Apps might run simultaneously since total device RAM might run out easier. Don’t forget to read my detailed tutorial about tuning the ART Heap Size on Android devices.
Swap and zRAM
Linux offers a large variety of solutions for low memory devices. Most notable among them are Swap and zRAM. Swap allows using parts or whole storage devices as virtual memory, to extend the total system memory (Total memory = Virtual memory + RAM).
Furthermore, zRAM (zipped RAM) is a compressed swap space that lives inside RAM. The idea is that portions of RAM that tend to remain static can be compressed before storing so their final size is smaller. Once they are needed by the Operating System, they can be uncompressed back to their original form. zRAM manages to clean up some more RAM space for Apps. The algorithm used for compressing objects is capable of reducing the final size to half the original. However, the whole method has the disadvantage of needing some processing power and thus battery capacity. For a better understanding of both Swap and zRAM, please read the dedicated article that we shared recently.
Last but not Least: Get Rid of any Task Killers/Memory Cleaners
These types of tools are completely useless on Android. Google has managed to offer a deeply sophisticated RAM management system for its Operating System so that any external efforts to improve it using Apps that just kill processes to make space actually get things worse. In simple words, an App that tries to clean up RAM by killing background processes will break Android’s RAM management algorithm. Out of the box, Android will free up RAM just when there is a need for more memory and also complete this task in the smallest time possible. Various improvements to Android’s memory management system have come through the years in terms of kernel and system patches.
Conclusion
To sum things up, if you feel that your Android device lacks in terms of Memory or RAM Management, there is always room for some improvement. This will come through tweaking Android’s own Memory Management, rather than using third-party tools. Did you find this article helpful? Let us know in the comments section below.
Join The Discussion: