Without getting into a big complicated technical explanation, let's just say that running fstrim on flash storage is roughly equivalent to running defrag on your hard drive. In both cases your drive becomes more efficient and your device becomes more responsive.
So, how do you do this fstrim magic on your Android device?
Well, you can do it manually from a root command prompt
#> fstrim -v /data
#> fstrim -v /cache
but what fun is that? Let's automate the process.
IMPORTANT - WARNING - DANGER
Before running trim, you must make certain your device does not have a flawed memory controller which can cause your device to be permanently bricked if you run trim! Since that would suck, let's make sure it's safe to run trim on your device. To do that first install this app.https://play.google.com/store/apps/details?id=net.vinagre.android.emmc_check
Note that you must have root and you must grant the app root permission when it runs.
Run the app and look halfway down the output screen and see if you have the brick bug. If you're lucky and your phone doesn't have the brickbug, it will say
Brick Bug?
NO. Sane chip.
Note: Because brick bug is a serious device killer, you may want to search for info on your device plus brickbug with Google as well as on XDA to see if there are other methods of checking if your particular device contains a buggy memory chip.
OK, if you got this far, get excited, you're about to increase the responsiveness and overall buttery feel of your device a lot.
Next we need to install an app to make running fstrim easy.
To do that we're going to install Lagfix free from the Play store.
https://play.google.com/store/apps/details?id=com.grilledmonkey.lagfix
Once you've installed Lagfix, run it. You will again be asked to allow root access. It's important that you say yes, and always allow. If you say no, lagfix will fail.
So, swipe over to the lagfix tab and you'll see /system /data and /cache with /data and /cache checked.
This is fine. Click Run! and wait. Depending on your device, it's flash speed and the amount of work that has to be done, fstrim can take anywhere from a few minutes to a few hours to run. My GNex took about 10 minutes the first time. My Asus Transformer TF101 took several hours!
Obviously you need to plan to run this when you won't need your device for a while.
Once the fstrim run completes for both /data and /cache you'll see output messages confirming a successful run.
If this happens, yahoo, your device is now trimmed and you can move on to automating the process.
If there were errors, I'm sorry, but your device's flash probably doesn't support trim.
Automating
Now like defragging, flash trimming isn't a one time thing. We need to schedule it to run regularly. So, now that you know the Lagfix app works for your device, uninstall it and go purchase Lagfix premium from the Play store. Once you have it installed, run it, approve root always, and go to the Scheduler tab. Check /data and /cache again, and choose days and time to run fstrim, keeping in mind how long it takes to run on your device and when you can go without using it. For example, I set my GNex to run Tue, Thu, Sat at 03:00 (3 am).Now click install.
Boom. You're done. You'll now have an Android device that is always snappy and responsive.
Notes:
- It doesn't hurt to include /system in your manual run of Lagfix. In fact I suggest you run it at least once. I would then run it again any time you install a ROM update or flash a new ROM on your device.
- After your first run of Lagfix is complete I suggest you reboot your device. In fact some devices require it to complete the process.
- When we talk about flash storage here, we are not talking about SD-Cards but about your device's internal storage.
Disclaimer: I take no responsibility for any damage you may do to your device.


