Using tmpfs for high performance I/O

When you need high performance I/O, one thing to consider using is tmpfs.  tmpfs allows your to mount a folder of your filesystem in your system’s RAM.  Before using tmpfs there are somethings you must be aware of.  You need to have enough additional RAM available to hold your data.  Your data will be stored in memory which means that it is volatile.  If your system crashes or restartts then you will  lose everything stored in tmpfs.  With that in mind, use tmpfs at your own risk.  If you intend to keep your data save it to disk when you are done using tmpfs.

To mount a folder as tmpfs

$ sudo mkdir /mnt/tmp

$ sudo mount -t tmpfs -o size=1500m none /mnt/tmp

Every file that you put in /mnt/tmp will actually be stored in system RAM.  Reading and writing to those files will be extremely fast.

I’m going to create an image of a 1GB SD card in /mnt/tmp and use it with my Android emulator.

$ mksdcard -l stick1 1024m /mnt/tmp/sd_card_1g.img

$ emulator -sdcard /mnt/tmp/sd_card_1g.img @fakeDroid

This boosted the performance of my Android emulator because it’s using RAM for its SD card.  When I am finished with my Android emulator I will copy my data back to disk for safe keeping.

$ cp /mnt/tmp/sd_card_1g.img ~/sd_card_1g.img