Google made a lot of small tweaks to the way Android works with version 4.3, which has only hit the unlocked Nexus devices so far. There is the new OpenGL ES 3.0 support, restricted profiles, a notification handler, and various other bits and pieces. The engineers at Mountain View also managed to sneak a significant low-level change into the platform that could vastly improve the user experience of Android devices going forward. Android now has native TRIM support to combat device slowdowns.
Mobile devices use NAND flash for storage, which can become sluggish over time as blocks of data are added and removed. This is due to the way deleted data is actually removed, or rather isn’t. It’s the same problem early desktop solid-state drives (SSDs) had, which are also composed of NAND flash storage.
I/O lag has been an on-going issue for Android devices, but was perhaps most evident on the original Nexus 7. Google’s first 7in tablet went from incredibly snappy to painfully slow as the storage controller got bogged down over the course of a few months. But what went wrong, and how does TRIM fix it?
Every time data is written to flash storage in your Android phone or tablet, the storage controller makes a note of where the blocks are located physically and logically. Let’s say you decide later you don’t want that data anymore and you delete it. It’s gone right? Not really. The data is actually only deleted from the user’s perspective. The data blocks are still there, but are available to be reused.
Over time, this leads to fragments of files scattered across the storage that are “deleted” but not overwritten by new data. The storage controller has to keep an increasingly detailed map of where all that deleted data is stored, even though from the user’s perspective those bytes are long gone. TRIM goes through the storage and frees up those blocks by telling the controller to stop tracking them. The leftover chunks of long-gone files can then be swept up in the regular garbage collection cycles.
TRIM support became common in desktop operating systems shortly after SSDs gained traction. Microsoft began supporting TRIM at the OS level with Windows 7 in 2009, whereas Apple didn’t implement TRIM until 2011 with Mac OS X 10.6.8. It was added to the desktop Linux kernel in 2008. Android is just now getting around to implementing the feature, though.
Google didn’t make an official announcement about TRIM support – it was simply discovered in the Android Open Source Project (AOSP) code. A series of commits in platform/system show fstrim (TRIM) being added to the volume daemon. This should make TRIM part of all Android devices going forward (not just the Nexus series), unless an OEM decides to remove it for some reason.
Supported Android devices will automatically run the fstrim command in the background periodically when one of a few conditions are met. This should keep the storage in tip-top shape over the long term. In fact, it seems to be slowly reversing some of the damage done to the Nexus 7 with its questionable storage controller. Users are reporting the Android 4.3 update is giving their devices a much needed boost.
This one small change could rescue many handsets from the trash, and make future phones and tablets last longer. The only problem is that most existing devices will never see an Android 4.3 update – unless you dip into the custom ROM scene, anyway. Alternatively, if you don’t have access to Android 4.3 or custom ROMs, formatting your phone and starting again is a good way to de-crud the NAND flash.