TRIM optimization in Android 4.3
TRIM optimization in Android 4.3

The storage I/O performance of the old version of Nexus 7 was not enough, which affected the smoothness of the system. In particular, as the use time increased and the number of applications increased, it was easy to become very slow. The new version of Nexus 7 greatly improved the storage performance. In fact, with the help of the new Android 4.3, all Nexus devices can solve this problem through TRIM.

To understand the performance improvement of Android 4.3 TRIM support, we must first understand TRIM.

What is TRIM?

Trim - An ATA instruction sent by the operating system to the SSD master controller to tell it which data addresses are "invalid". When you delete a file in the computer, the operating system does not really delete it. The operating system just marks the address of this file as "empty" so that it can be used again, which means that the address occupied by this file has been "invalid". But this will lead to a problem. The hard disk does not know that the operating system has marked this address as "empty". It does not matter if the mechanical disk is used, because the next time the system asks it to write data on this address, it can directly overwrite the write on it, but the problem will occur on the SSD. Flash memory needs to be erased before writing data again. To get free flash memory space, SSD must copy all "valid" pages to a new "blank block" and erase the old block (garbage collection). If there is no Trim, it means that the SSD master controller will not know that this page is "invalid" unless it is required by the operating system to overwrite the data again. In this way, it is impossible to make the best optimization at the most appropriate time, which affects both the efficiency of garbage collection (indirectly affecting performance) and the durability of SSDs (that is, the life that many people care about). It should be emphasized here that Trim is just a command to let the operating system tell the SSD master controller that the page is "invalid" and that there are no other redundant operations.

TRIM working in Android

The Linux kernel has introduced TRIM in the 2.6.33's, but not all Linux file systems natively support TRIM, and ext4, which is widely used in Android, natively supports TRIM. For Android 2.3, ext4 has been set as the default file system. Previously upgraded Android may still use YAFFS2. Most phones or tablets with Android 4.0 or above preinstalled use ext4.

There are two ways to call TRIM to defragment NAND. One is to add the discard option when mounting the ext4 partition, and the other is to use the fstrim command. The TRIM in Android 4.3 is implemented with fstrim, but the general Linux distribution does not recommend using fstrim, but uses the method of adding the discard option to the mount ext4 partition. Because the discard option will execute the TRIM command at the same time during each disk operation, it may affect the performance when deleting files.

It is reported that Android 4.3 requires the following conditions to execute fstrim. The device has not been used for more than one hour, there has been no idle maintenance window event in the past 24 hours, the remaining battery power is not less than 80%, and the device is charging and the power is not less than 30%. If you are used to plugging in and charging every night, fstrim will be executed once every 24 hours. Google's approach is to send TRIM instructions only after various sensors meet the conditions.

For non Android 4.3 users, a Lagfix software in the Google Play store can enable non Android 4.3 devices to use TRIM, requiring Root. In fact, the root phone can also directly modify the Android file system mount table, add the discard parameter, and then restart the phone. The modification method is roughly the same as that of the Linux system.

Execute the following command in ADB to verify whether fstrim works:

adb logcat -d | grep -i fstrim

Share:
Related articles
Igao7 fork
edit
Back to Mars! (…………%……&%G2&¥(@#*&)&%*————%&*¥)
Share Weibo Share WeChat
 Aigoji WeChat

Aigoji WeChat

 WeChat

WeChat

Recommended products

Sorry, the product you are looking for is not available in the product library

on trial