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

The Android emulator

Launching the emulator

In my previous post I demonstrated how to install the Android SDK, how to create a virtual Android device and how to install an Android application.  Once you have created an Android virtual device and named it, you don’t have to run the full SDK manager each time.  You can run your android device directly by starting just the emulator.   The emulator is another tool in the SDK.

First, lets add the tools folder from the android SDK to our $PATH for convenience.   Add the following to the end of your ~/.bashrc file.

export PATH=${PATH}:~/android-sdk-linux_86/tools

Run the emulator from the cmdline and give it the name of your saved Android virtual device.  If you remember from my previous post, I named mine fakeDroid.  Notice that you have to use the @ symbol with the name of your device.


$ . ~/.bashrc

$ emulator @fakeDroid

To make this even easier you can create a launcher on your Gnome desktop.  Right click on your Gnome desktop and select “Create Launcher…”.  For the command, put the full path to the emulator program and then the name of your saved Android device @fakeDroid.

That will create an icon on your desktop, that will launch your Android virtual device.

Creating SD cards

If you want to create virtual SD cards to use with your Android emulator, there is a tool for doing that called mksdcard.  The tool will create a blank FAT32 image file, that will emulate an SD memory stick.

The following command creates a 1GB SD card with a label “stick1”.


$ mksdcard -l stick1 1024M ~/sd_card_1G.img

You can copy files into your SD card by mounting it with the loop device.


$ sudo mount -oloop ./sd_card_1G.img /mnt

$ sudo mkdir /mnt/Pictures

$ sudo cp /opt/Pictures/*.jpg /mnt/Pictures

$ sudo umount /mnt

You can start your Android device with your SD card already mounted


$ emulator -sdcard ~/sd_card_1G.img @fakeDroid

One thing you may notice is the poor performance you get reading and writing the virtual SD card with your emulator.  You can boost performance dramatically by storing your SD image file in tmpfs.  I’ll demonstrate that in my next post.