The problem

Smart phones tend to have flash storage. Memory cells in it have a finite number of writes. To avoid them being prematurely depleted there's a translation layer which redirects writes to unused cells.

Unfortunately this changes the problem to running out of cells, since the file system needs to say when it's stopped using a block.

This is done by either mounting the file system with the discard mount option, or running the fstrim program.

If you trim you need to do it periodically, but it makes individual writes faster.

Unfortunatey, such common desktop practices aren't followed in the mobile world. Android changed from its own file system, yaffs2, to ext4. Unfortunately it doesn't mount with discard.

Vold always mounts without any extra flags, and has no way to specify other flags.

If you're lucky, your phone's /fstab.$devicename has it specified, but my S3 does not, nor did my brother's Note 2 or my friend's S2.

How to know if you need this

  1. Install the Android Terminal Emulator.
  2. Run cat /proc/mounts.
  3. Inspect the output, if there's a line that has the word ext4 on it, but doesn't have discard in it, then you have a problem.

Failed attempts

Alter the fstab or initrc

initrc is able to remount devices with different options, and fstab changes how they're made in the first place.

Unfortunately these files come from the initramfs, so you can't modify them without intrusive changes to the bootloader; something I wasn't prepared to do.

Alter /system/etc/vold.fstab

vold.fstab is Android's abstraction layer over device mounting. Unfortunately there is no way to specify mount options in it. I looked at the source code, it always mounts with the data parameter to mount as NULL.

The solution

Root your phone

Unfortunately this requires rooting your phone, so do that first. For the S3 I followed this guide, except I recompiled Heimdall myself, as I don't trust executables downloaded from the internet.

I also needed to make multiple attempts, since I didn't reboot immediately into the recovery partition after flashing it, which caused it to be reflashed to stock formware.

Trim your file system

Download LagFix, it's advertised as a way to make your phone faster, since writes also get slower if you're running out of cells to write to.

Running this will discard any blocks your file system isn't using.

Pay attention to the warning on the app page, some phones have a broken discard operation that makes it brick immediately. Fortunately there's a way to tell if if would brick your phone without empirical evidence.

If you're willing to pay, you can get the Professional version and shcedule regular trims, which is sufficient to keep your phone going. If you're happy with this solution, you can stop here.

Remount with discard on boot

You need an app that starts at boot time and remounts, since at the time of writing this no such app existed, I had to find an alternative solution.

Here comes Script Manager to the rescue.

Script Manager lets you run shell scripts. You can set these scripts to be run with SuperUser, or at boot time. Writing this shell script requires more useful shell utilities than are usually installed on your phone; hence install Busybox.

After this, create the following boot script in Script Manager:

grep 'ext[34]' /proc/mounts | awk '{print $2}' | while read mp; do
    mount -o remount,discard "$mp"

It's probably possible to do this without the grep, but this is what I used.

How could this happen!

You can't test a whole product's life, but with sufficient instrumentation you could simulate the amount of wear the Flash is going to recieve.

If you're a conspiracy theorist, you could claim this is intentional, to ensure planned obsolecense; however my boss had his die in less than a year, which for a premium phone is just embarassing.

However this did happen not too long before the S4 started being advertised.