Filesystem story on Android

Filesystem on Linux is always an interesting topic.

Since most of the bottleneck on a modern computer is I/O to disk,
playing around with filesystems can result in a pretty significant improvement,
both in reliability and performance(although those two tends to not go under a same sentence).

I personally use the following setup on my Linux desktop :
 - xfs on the root partition for best reliability
 - f2fs on the home partition for better performance
 - ext4 with writeback, nobarrier mode on the build output partition for best "I-don't-care-about-redundancy-level-performance".
 - btrfs with zlib compression on the back-up HDD for efficient space usage and snapshots.

While there is about a dozen different popular filesystems on Linux desktop/server setups, filesystem story on Android is somewhat boring.

YAFFS2

In the early days(we're talking Galaxy S1 era), most Android devices used yaffs2 filesystem.
One thing to note here, is that yaffs2 was not deprecated because ext2/3/4 is better. It is simply incompatible with the storage solution in that days and these days. yaffs2 is a fully NAND-aware filesystem, while most filesystems these days aren't. Flash storage manufacturer decided to make the optimizations private to their FTL(Flash Transition Layer) and emulate HDD(mostly) instead. This change makes filesystems such as yaffs2 incompatible.
While I want to see storage solutions that allow filesystems to be fully flash-aware again, the likelihood of flash storage vendors opensourcing their core technologies to comply with GPL, is extremely low. This would make Apple always on top of the storage performance game(at least on mobile), sad. But meh, this topic is for another day.

EXT4


The adoption of ext4 on Android was quite obvious. The underlying storage is now HDD-style with FTL, and ext4 until today, is known for its stability and "good-enough" performance.
But it's almost 10 years old. If it ain't broke, don't fix it. Booooring.

F2FS


Then, people turned their eyes onto f2fs. This "Flash-Friendly File System" was introduced just before 2013, and as the name implies, it's optimized for flash storage from scratch.
However, f2fs was not welcomed as much as ext4. Its data recovery and fsck tool was pretty bad(there wasn't even a functional fsck when it was first announced). This was a major drawback since most phones back then had a removable battery, and many people still think/thought plugging out the power source spontaneously won't cause much trouble.
And f2fs is still maturing. Its stability is not fully confirmed by the mass, and fsck is still receiving important changes up until this day. Each major Linux kernel releases brings big changes on f2fs. The head of f2fs, Kim Jaegeuk, is even offering backports of the latest mainline f2fs to LTS kernels used by Android.
Also, Google mentioned that adopting f2fs didn't gain much performance improvement. However, I'll throw some grain of salt here as Google have a history of screwing up storage performance and by the fact that f2fs outperforms ext4 on many micro-benchmarks, most importantly sqlite ones. It should be also noted that f2fs might cause a hit on battery life as it inherently suffers from high GC overhead, due to LFS(Log-structured File System) design. I saw f2fs-gc kthread consuming a noticeable amount of CPU myself as well.

I'd personally still recommend ext4 for non-techies as I'm still experiencing a GC issue with f2fs.
Basically, GC won't clean garbage properly and leave invalid blocks to a level that user can notice the huge performance drop. I've seen this GC issue occurring even on stock/unmodified phones by vendors, and I'm still in the middle of investigating this issue. This topic is also for another day.


Next-Gen


There are many filesystems that are gaining attractions these days. btrfs, zfs and bcachefs is one of them. (For Windows - ReFS, for Apple - APFS)
bcachefs is under heavy development and not even merged on mainline. While it seems like it's the best performing one that is also quite feature-packed, it would take a while until we can see it on a production Android device.
zfs is from Oracle. We don't want to upset Oracle or SFC. Jokes aside, zfs is quite heavy on RAM usage. RAM is quite precious on mobile, so it's very unlikely we would see it on Android.

btrfs in an interesting one. While it's almost 8 years old, its stability always has been a controversy. btrfs is probably the most feature-packed filesystem merged in Linux mainline, so maybe that's why.
The most interesting stuffs about btrfs are :
 - Fully transparent compression
 - (Theoretically)Awesome fault-tolerance with checksums.
 - Snapshots
All these 3 features can be a welcome to Android, which might be why Google is also interested...


The transition


Migrating to a new filesystem is a hard task.
Not only you need a fully stable kernel filesystem module, you need to take care of OTA in case of Android.
"If it ain't broke, don't fix it" concept on ext4 actually makes a lot of sense. After all, you don't want your precious family photos to be suddenly corrupted from gaining ~15% performance improvement. You need to see a clear advantage from an older one to a newer one, if you want to make such a big change. Moreover, you can't switch to an older filesystem after shipping your customer a new one. (Which might be why the OnePlus 5 uses ext4 while its predecessors used f2fs)
Converting a filesystem in an already-shipped device is even harder. You don't know what could go wrong, and a single line of code could corrupt an entire filesystem. Even Apple was quite conservative with this.

However, none of these matters for us, powerusers and tinker-ers ;)
Aren't we all familiar with manually calling mkfs and fsck directly from the recovery?


Next time, I'll talk about using btrfs and utilizing its features on Android.

Comments

Post a Comment

Popular posts from this blog

리눅스를 사용하는 노트북에서 전력 소모 낮추기

Saving power consumption on laptops with Linux

Experimenting around btrfs on Android