Introduction

Android devices run the Linux kernel in the background. The memory on the devices is divided into pages where each page has a size of four kilobytes. These pages can be used for different purposes, including:

  • Used pages: Memory in use by the Android device.

  • Cached pages: Memory used by the Android device, but their data also resides on nonvolatile storage. It’s possible to reclaim this memory since we have a backup on the disk.

  • Free pages: Idle memory not in use by the Android device.

How Android reclaims memory

As we run more applications on the Android device, the percentage of used and cached pages increases while the number of free pages reduces. The device becomes slow or unresponsive if it has few free pages of memory. Android has two mechanisms for reclaiming memory, which are explained below.

Kswapd

If the number of free pages of memory reduces below a certain threshold, the Android system will initiate the kswapd process to reclaim some memory from the cached pages. The diagram below illustrates kswapd in action. The height of each colored section indicates the percentage of used, cached, and free pages.

Get hands-on with 1200+ tech skills courses.