Speed up Firefox by mounting the profile in tmpfs [Linux only]
tmpfs is a virtual, RAM-backed filesystem. It’s lightning-fast, but since it’s RAM-backed, any file written to tmpfs uses precious memory while it’s there, and the entire contents of the virtual partition are lost on shutdown or crash. The good news is that these detriments can be minimized, making tmpfs a viable choice for your profile directory. This document gives some tips on how to mount your Firefox profile in a tmpfs partition while minimizing the downsides of tmpfs.
Step 1. Reduce the size of your profile directory.
tmpfs is RAM-backed, so we want to conserve memory by trimming the fat from the profile. I recommend making the following config changes (enter ‘about:config’ in the Firefox address bar):
set browser.cache.disk.capacity to 20000 or thereabouts
set browser.safebrowsing.enabled to false
set browser.safebrowsing.malware.enabled to false
The first one reduces the size of the disk cache to about 20 MB, down from 50MB. It might be tempting to turn disk cache off entirely, but I’ve encountered poor performance doing that in the past; I think that the caching algorithm has to be able to push things into disk cache for best performance, even if they won’t stay there long.
The last two disable the collection of the information in the ‘urlclassifier*.sqlite’ files. These hold Firefox’s database of suspected malware or phishing sites, and while most users will feel comfortable turning this off, it does in theory leave you more vulnerable to these types of attacks. There’s a known bug in Firefox which can make these files grow quickly; on my system, they were 70MB total.
After you’ve changed these settings, clear the cache in Firefox and delete the urlclassifier*.sqlite files from your profile directory. (SQLite will recreate empty databases but they’ll stay at 32k.)
Step 2. Edit the fstab and prepare the backup tarball.
First, create a tarball of your profile as it currently stands.
| Code: |
| $ cd $ cd .mozilla/firefox $ tar cpf packed.tar abcd1234.default |
abcd1234.default should be replaced by your profile directory name here and below.
Now edit /etc/fstab and add a line like this:
| Code: |
| firefox /home/steven/.mozilla/firefox/abcd1234.default tmpfs size=128M,noauto,user,exec,uid=1000,gid=100 0 0 |
You’ll have to adjust path components, uid and gid.
Step 3. Set up a backup and restore script.
This is an example, but is by no means the only way to do it. I’ll assume you’ve named the script “${HOME}/.pack_ffox.sh” in future commands, so replace that with whatever you decide to do.
| Code: |
| #!/bin/bash# Change this to match your correct profile PROFILE=”abcd1234.default”cd “${HOME}/.mozilla/firefox”if test -z “$(mount | grep -F “${HOME}/.mozilla/firefox/${PROFILE}” )” then mount “${HOME}/.mozilla/firefox/${PROFILE}” fiif test -f “${PROFILE}/.unpacked” then tar –exclude ‘.unpacked’ -cpf packed.tmp.tar “$PROFILE” mv packed.tar packed.tar.old mv packed.tmp.tar packed.tar else tar xpf packed.tar &&\ touch “${PROFILE}/.unpacked” fi |
This script will load your firefox profile if it hasn’t been loaded, and save it otherwise (keeping one backup copy from a few minutes ago in case of file corruption or the like). Once you’ve got it saved, you’ll need to quit Firefox for this next step. Open in links, copy and paste to a text editor, or just remember the steps.
Step 4. Switch over.
With Firefox closed, you need to empty your profile directory. Either move the files currently in there to a new folder, or simply erase them (remember, a copy is in packed.tar as well). Be sure to leave the empty profile directory there for the tmpfs mount point.
Now, run the script:
| Code: |
| $ “${HOME}/.pack_ffox.sh” |
Verify that your profile directory is now mounted on tmpfs, that your files got correctly unpacked, and that the file .unpacked exists inside of your profile directory.
Now run the script again, exactly as before. This time, it will detect that your profile’s been unpacked and is ready to use, and create a new packed.tar. If it worked, you should now have the file “.mozilla/firefox/packed.old.tar” as well.
If both of those things checked out, you’re clear to start Firefox again.
I recommend adding the command to your .xinitrc or desktop-environment-specific startup settings, so that it’s ready to go when you log in. It’s also critical that you run it again before you shut down your computer, or you’ll lose all changes. One of the safest ways for users on media that doesn’t have limited write-cycles is to simply add an entry to the crontab which runs the script every five minutes. Run this command to edit the crontab:
| Code: |
| # crontab -u USERNAME -e |
which will bring up your editor. Add a line akin to this one:
| Code: |
| */5 * * * * $HOME/.pack_ffox.sh |
Check in five minutes to make sure the mtime of packed.tar has changed, indicating that the script is working [just right click the tarball and look when it was last modified].
Notes:
I use Ubuntu, and for me some of the steps above had to be changed a little. For example, my FF profile was much bigger because of the many extensions i have installed, so i change the partition size to 200, so you can change the size to your needs as well.
To set up the crontab in Ubuntu, i just wrote: “crontab -e” in a terminal and added the line “*/5 * * * * $HOME/.pack_ffox.sh” [without the quotes]
I found this on the gentoo.org forum.
See also:
How to install Firefox 3.1 beta 2 in Ubuntu from repositories
Export your Firefox 3.0 full profile to Firefox 3.1 (including all addons, themes, cookies, passwords, etc)
Other articles tagged with:
Trackbacks
- Speed Up Firefox (Linux Only)
- HowtoMatrix » Speed up Firefox by mounting the profile in tmpfs [Linux only]
- [Linux] Firefox performance tip « In Arid Glamor (IceHot)
Comentariile nu sunt permise.


This is a great article; I have one question, though: what happens if you have some sort of power failure after mounting your FF profile as tmpfs? Seeing as it is mounted in RAM, would you not lose a lot of information?
If you do everything as above, there is a backup made every 5 minutes in home/.mozilla/firefox called packed.tar. That backup is also used to populate your Firefox profile folder after each restart (since ram is cleared after shutdown/restart).
Oh, and also the old packed.tar is saved: packed.tar.old
Ah, I got you. How would the browser’s speed compare if you were to mount your FF profile as a loopback FS (to save RAM)? I know it wouldn’t be AS fast as tmpfs, since the file would still be mounted on your HDD, but would its speed be noticeably improved?
ok… that i do not know, but here is what i found:
it seems the SQLite is the main issue for speed and i don’t think it would make any difference using the HDD, but you can try…
the powersaving gui I’m working on has something similar to this. It copies your firefox folder to a backup and /dev/shm then symlinks the old folder to the copy in /dev/shm, then it uses rsync every five minutes to sync the backup. If you want to check it out instructions are here http://ubuntuforums.org/showthread.php?t=988309 .(I included it in the gui because it also helps keep your disk spun down, firefox is horrible with disk writes)
Wow. Nice. Tre’ sa-i dau o incercare zilele urmatoare.
web director