Modern mobile devices have an impressive amount of RAM, but the algorithms for managing it Android often do not work as performance enthusiasts would like. One of the key parameters, but hidden from the average user, is swappiness. It determines how aggressively the operating system will offload active applications to the swap file or zRAM, freeing up physical RAM.

Understanding how this mechanism works can significantly speed up the interface and reduce the number of โ€œrestartsโ€ of background applications. Standard kernel settings are often focused on saving battery power or compatibility with a wide range of hardware, which does not always mean maximum speed.

In this article we will look at what exactly is hidden behind this term, how to find the current value and how changing it can affect the operation of your smartphone. You will learn when it is worth interfering with system processes, and when it is better to leave everything as is.

The principle of virtual memory in the Linux kernel

The operating system Android is based on the kernel Linux, which uses a complex memory management scheme. When physical random access memory (RAM) becomes scarce, the system must decide which processes to keep active and which to unload. This is where the paging mechanism comes into play.

Parameter vm.swappiness is an integer value between 0 and 100 that tells the kernel how often to use swap space. The higher the value, the more aggressively the system will move memory pages from fast RAM to slower swap (or zRAM).

It is worth noting that in mobile devices the role of swap is often performed by technology zRAM. It compresses data and stores it in a dedicated partition of the same RAM, which is faster than writing to a flash drive, but requires CPU time to compress and decompress.

  • ๐Ÿ“‰ Low value (0-10): The system will unload applications, trying to keep as much data as possible in the physical RAM.
  • ๐Ÿ“ˆ High value (60-100): System will actively dump background processes into swap, freeing up space for caching files and current tasks.
  • โš–๏ธ Balance: The standard value is usually in the middle, but may not be optimal for specific use cases.

โš ๏ธ Attention: Changing this parameter on devices without root access is impossible using standard means. Attempts to use third-party applications without root access will only result in the value being displayed, but not changing it.

It is important to understand that uploading to swap does not always mean slowdown. If physical memory is full, having fast zRAM with the right swappiness ratio can prevent a complete system freeze (OOM Killer) that simply kills processes.

The impact of zRAM on smartphone performance

Technology zRAM has become the de facto standard for modern versions Android. It creates a block device in RAM where data is compressed. The interaction of swappiness and zRAM is critical for multitasking.

When you open a heavy application, such as a game or a graphics editor, the system requires a lot of free memory. If vm.swappiness is configured correctly, less important background processes (messengers, mail) will be compressed and moved to zRAM, freeing up space for the active task.

However, if the value is too high, the system may begin to โ€œdriveโ€ data back and forth even if there is free memory. This phenomenon is called thrashing and leads to an increase in processor power consumption and heating of the device.

๐Ÿ’ก

If your smartphone has less than 4 GB of RAM, experimenting with zRAM and swappiness can give a noticeable increase in multitasking, allowing you to keep more applications open.

On devices with large amounts of RAM (8 GB and above), aggressive swapping is often redundant. In such cases, reducing swappiness can make switching between applications more immediate, since data does not need to be decompressed from a compressed state.

Swappiness Value System Behavior Recommended Usage
0 - 10 Minimum swap usage Devices with a large amount of RAM (8-12 GB)
30 - 50 Moderate use Standard scenario, balance of speed and memory
60 - 80 Aggressive uploading to zRAM Devices with a small amount of RAM (2-3 GB)
90 - 100 Maximum swap Extreme cases of memory shortage, risk of lags

Thus, the setting depends on the hardware characteristics of your gadget. There is no universal value, and finding the optimal balance requires testing.

How to find the current value of swappiness

Before changing anything, you need to know the current state of the system. To view the parameter value vm.swappiness you will need access to the command line.

The easiest way is to use the terminal application on the device itself or connect via ADB (Android Debug Bridge) from a computer. Without root access, you can only read the value, but not change it.

Enter the following command in the terminal or ADB console:

cat /proc/sys/vm/swappiness

The system will return a numeric value. On most stock firmware Android the default value is 60 or 100. This indicates that the manufacturer has configured the system to actively use swap mechanisms.

๐Ÿ“Š What is the swappiness value you currently have?
0
10
60
100
I donโ€™t know / Havenโ€™t checked

You can also get more detailed information about memory by entering the command cat /proc/meminfo. The output will contain a line SwapTotal and SwapFree, which will show the total volume and free space in the swap partition, respectively.

Instructions for changing the parameter via ADB and Root

To make changes, superuser rights are required (Root). If your smartphone is rooted, you can change the value on the fly (until the next reboot) or fix it permanently.

A temporary change is made through a terminal with root access. First gain privileges, then write the new value:

su

echo 10 > /proc/sys/vm/swappiness

This command will set the value 10, which will force the system to use swap very rarely. The effect is noticeable immediately, but after a reboot the settings will be reset to factory settings.

For a permanent change, you need to edit the system configuration file. Most often this is a file /system/build.prop or creating a startup script. Add the line:

vm.swappiness=10

to the file build.prop or use specialized modules Magiskthat apply the settings automatically when the system starts.

โ˜‘๏ธ Check before changing

Done: 0 / 4

โš ๏ธ Attention: Editing system files build.prop manually can lead to a cyclic reboot (bootloop). Always have a working recovery on hand to restore access to the file system.

There are also tweaker applications from Google Play that automate this process, but they still require root access. The use of such snails is more convenient for beginners, but less transparent.

Optimal values โ€‹โ€‹for different scenarios

The choice of the ideal number depends on how you use the smartphone and what its technical characteristics are. There is no point in setting the value 10 on a device with 2 GB of memory, as this will lead to constant killing of background processes.

For gaming smartphones with large amounts of RAM, it is recommended to reduce swappiness to 10-20. This will ensure maximum response speed and allow games to take up more physical memory without crowding out system services.

For budget devices, where every megabyte counts, the value 60-80 can be justified. It will allow the system to โ€œsurviveโ€ when there is a lack of resources, albeit with some loss of interface smoothness.

Impact on the battery

Reducing swappiness can have a positive effect on autonomy, since the processor does not need to constantly compress and decompress data in zRAM. However, if there is critically little memory, the system will begin to use OOM Killer more often, which is also resource-consuming.

If you use the phone as a server or for specific tasks (terminal, emulators), setting up paging becomes critical for the stability of long-lived processes.

You should experiment carefully. Start by changing the value to 30 or 40 and observe the behavior of the system throughout the day. If the lags have disappeared and applications have stopped crashing, you are on the right track.

Possible risks and side effects

Interfering with the kernel Linux always carries risks. Incorrect swappiness settings can lead to unstable operation of the operating system.

The main problem with a too low value on devices with small amounts of memory is frequent operation of OOM Killer (Out Of Memory Killer). The system will simply close applications without attempting to save their state in swap, which will lead to data loss in unfinished tasks.

On the other hand, too high a value on a fast device will force the processor to constantly work in compression mode, causing heat and reduced battery life with no visible performance gain.

โš ๏ธ Attention: Interfaces and paths to system files may vary depending on the version of Android and manufacturer's shells (MIUI, OneUI, ColorOS). Before making changes, check the documentation for your specific model.

It is also worth remembering that some manufacturers strictly block changing these parameters even with root access, using SELinux policies. In such cases, standard methods may not work.

๐Ÿ’ก

The main risk is destabilization of the system. If after changing the settings the phone starts to behave strangely, return the default value (usually 60 or 100) or reset the settings via recovery.

Frequently asked questions (FAQ)

Is it safe to change swappiness on Android?

Yes, it is safe if you understand what you are doing and you have root access. The setting changes memory management behavior but does not affect physical components. However, there is always a risk of software failures if you choose extreme values.

Is root necessary to change vm.swappiness?

Absolutely necessary. Without superuser rights, you will only be able to read the current value through the terminal, but any attempt to write a new value will result in an access error (Permission denied).

Will the setting be reset after a reboot?

If you changed the value via the echo command in the terminal, it will be reset immediately after the reboot. To save the setting, you need to register it in the system file build.prop or use the startup script (init.d / service.d).

Will this help if I only have 2 GB of memory?

On devices with a small amount of memory (2 GB), reducing swappiness can worsen the situation, since the system there will be nowhere to place background processes. In such cases, it is better to leave the standard values โ€‹โ€‹or even increase them, relying on zRAM.

Where can I find the build.prop file?

The file is located on the path /system/build.prop. To edit it, you need not only root access, but also a mounted system partition in write mode (R/W), since by default it is read-only.