PCsuggest

  • Quick tip
  • SECURITY
  • NETWORKING
  • OpenWrt
  • HARDWARE

Speed up firefox with RAM cache and tmpfs in Linux

Updated - August 24, 2017 by Arnab Satapathi

Firefox, the second most popular web browser, the default pre installed browser in many GNU/Linux distributions. It is really great in terms of it's customization capability and large collection of add-ons.

Though many users find firefox frustratingly slow and sluggish, so they switch to other browsers like Google Chrome or Chromium etc. There are many reasons for it's sluggish performance, like storing cache to disk, using slow sqlite databases, frequent disk access by other processes, no DNS cache and like so many of them.

But there are many of ways to make it faster and improve page load time. In this tutorial we are going to do this by modifying the firefox about:config configurations, moving all profile data to a tmpfs partition on RAM and moving the cache to RAM instead of hard disk. This guide will work all GNU/Linux Distributions like Ubuntu, Fedora, Debian, Arch Linux etc. etc.

Contents

  • Optimize the about:config configurations
  • Move the cache to RAM
  • Move profile data to a tmpfs partition
    • 1. clear all cache and cookies
    • 2. backup default profile data
    • 3. mount the tmpfs on profile folder
    • 4. sync any changes to the profile folder with the backup folder
  • Conclusion

Optimize the about:config configurations

Open up firefox, type about:config in the URL bar , hit Enter and press the I’ll be careful, I promise! button, now you can edit the configurations. Use the search bar to find configurations easily.

speed up firefox linux about:config

  • Search for browser.cache.use_new_backend , if the value is 0 , modify it to 1 , this makes the caching efficient.
  • Search for network.http.pipelining.ssl toggle it value to true .
  • Search for network.http.pipelining , toggle the value to true .
  • Search for network.http.proxy.pipelining , toggle its value to true .
  • Search for network.http.pipelining.maxrequests , modify the value , set any thing above 100 , like 120 .
  • If you are not using IPv6, then search for network.dns.disableIPv6  and toggle its value to true .
  • Search for browser.safebrowsing.enabled and browser.safebrowsing.malware.enabled , toggle the value to false, in both of them, though this is a little bit dangerous.

Move the cache to RAM

As RAM is much much more faster than hard disk, so moving cache to RAM will increase the user experience greatly. Recent computers have plenty of free RAM, so moving the cache to RAM will not be a problem. But avoid this if you have less than 1 GB RAM.

  1. Again, open up firefox and type about:config in the URL bar, hit Enter and press the I’ll be careful, I promise! button. Now edit few thing in this section.
  2. Search for browser.cache.disk.enable  in the filter bar, toggle the value to false , this will disable cache to disk.
  3. Now it is the time to enable cache to RAM, search for browser.cache.memory.enable , if the value is true leave it else toggle it to true.Now assign how much memory could be used as RAM cache, search for browser.cache.memory.capacity , if not found create it.speed up firefox browser.cache.memory.capacityRight click on blank area, then select "New" > "Integer"  , set the preference name browser.cache.memory.capacity , enter the integer value in KB, like 204800 for 200 MB , and done . Check it with about:cache .

Move profile data to a tmpfs partition

Finally move all profile data to a tmpfs partition on RAM , tmpfs is a incredibly fast special type of  file system that uses a part of RAM to store data. Firefox stores almost every information in SQLite databases, but SQLite is inherently slow and disk I/O dependent. This process will make Firefox blazing fast and disk I/O independent.

1. clear all cache and cookies

Perhaps you know how to do that, if not, click Edit > Preferances go to Privacy and clear cookies, then go to Advanced > Network clear Cached Web Content and done !

2. backup default profile data

Create a backup archive of your current data, before doing this close Firefox and look at the commands bellow.

cd .mozilla/firefox/

cp -a profile_name.default/ profile.bac

rm -rf profile_name.default/*

must replace profile folder name with your own profile folder name.  This will create a folder named profile.bac containing all profile data and clear all data inside the default profile folder.

amazon prime logo
Try AmazonPrime for free
Enjoy free shipping and One-Day delivery, cancel any time.

3. mount the tmpfs on profile folder

Add the line bellow to the /etc/fstab file,

tmpfs /home/$USER/.mozilla/firefox/profile_name.default tmpfs size=128M,user,exec,uid=1000,gid=1000 0 0

My firefox default profile name was p3iyxcse.default , so the line at /etc/fstab looks like bellow.

tmpfs /home/b00m/.mozilla/firefox/p3iyxcse.default tmpfs size=128M,user,exec,uid=1000,gid=1000 0 0

Make sure that the /home/$USER/.mozilla/firefox/profile_name.default directory exists, otherwise tmpfs mounting will fail .

Now mount the tmpfs at profile directory , i.e. at /home/$USER/.mozilla/firefox/profile_name.default and copy all the backup data to the default profile folder.

sudo mount -a

cd .mozilla/firefox/

cp -a profile.bac/* profile_name.default/

Do not forget to replace profile_name.default with your own profile name. And now start Firefox, if you have a slow HDD like me, then you will notice a much faster start up time and no sluggish performance .

4. sync any changes to the profile folder with the backup folder

In order to keep the changes intact after a reboot or shutdown, we need to sync the profile folder with the backup folder time to time.

To do this without any user interaction in later, save the script bellow as ff_profile_sync and add it to crontab  . Before doing this if you do not have rsync , run sudo apt-get install rsync on Ubuntu, Debian  or Linux Mint etc. the script is below.

#!/bin/sh
cd /home/$USER/.mozilla/firefox/
if test -d *.default;then
if test -d profile.bac;then
rsync -a --delete *.default/ profile.bac/
fi;fi

Do not forget to replace $USER with your username, save this script at /usr/local/bin or wherever you like, make it executable, and add to crontab with crontab -e , set the cron interval 5-10 minute or whatever you like.

crontab -e

Put the line bellow for a 5 minuite  update interval .

*/5 * * * * /usr/local/bin/ff_profile_sync > /dev/null 2>&1

Finally add the line bellow to the /etc/rc.local file just before the exit 0 , to restore the previous changes after a reboot .

cp -a /home/$USER/.mozilla/firefox/profile.bac/* /home/$USER/.mozilla/firefox/profile_name.default/

Again, Do not forget to replace $USER with your username and profile_name with your firefox profile name.

This setup will backup all changed profle data to the profile.bac folder automatically, so forgot about it , and enjoy super fast firefox.

Conclusion

If you have any question or need further assistance just leave a comment, we’d be happy to assist you.
Also feel free to share this tutorial with your friends.

Filed Under: how to, networking Tagged With: firefox, RAM cache, tmpfs, Ubuntu

Your comments
  1. viviz says

    January 15, 2018

    thanks ! nice how to.
    regards

    Reply
  2. Julius Thijssen says

    December 2, 2017

    Just so you know, I've been using Anything Sync Daemon (works fine in debian and ubuntu too: https://github.com/graysky2/anything-sync-daemon ), this is a great ram-disk usage script, mitigating all the problems mentioned here with maintaining a steady-state ff profile despite reboots, crashes etc.

    Reply
    • Arnab Satapathi says

      December 2, 2017

      Thanks Julius for mentioning the script, much appreciated.

      Reply
  3. Bill says

    November 17, 2017

    Thanks, however, my firefox(56.0) keeps using ~/.cache/mozilla/firefox/XXX.user/ directory. I took your ideas and create 2nd tmpfs for it, now my hard drive truly stays quiet while i'm using firefox, and feel a lot faster.

    and I put the script in .bash_logout to update cache to bac folder in disk.

    Reply
  4. Andrea says

    March 27, 2017

    Hi Arnab,
    what if the folder /home/$USER/.mozilla/firefox/profile_name.default does not exist?
    I'm operating in a fresh installation of Linux Mint 18 and I can't find it, even when displaying hidden items...

    Thanks for you advice,

    Andrea

    Reply
    • Arnab Satapathi says

      March 27, 2017

      Run firefox for once, the profile folder will be created.

      Reply
      • pattap says

        September 20, 2017

        Mine exists but mount -a refuses to mount claiming:

        root@HelloMotto:~/.mozilla/firefox# mount -a
        mount: mount point /home/$USER/.mozilla/firefox/bfyxu7lk.default does not exist
        root@HelloMotto:~/.mozilla/firefox# ls
        bfyxu7lk.default Crash Reports profile.bac profiles.ini

        Reply
        • Arnab Satapathi says

          September 20, 2017

          Are you sure you're using all paths correctly?

          Typing commands as root@HelloMotto:~/.mozilla/firefox# While using the fstab entry as /home/$USER

          Reply
          • pattapn says

            September 22, 2017

            Hi Thanks for the response,

            what do you mean by typing as root@HelloMotto:~/.mozilla/firefox#

            as being in that location while typing mount -a?

            and should my entry in fstab be

            tmpfs /home/$USER/mozilla/firefox/bfyxu7lk.default.....

            or

            tmpfs /home/HelloMotto/mozilla/firefox/bfyxu7lk.default.....

            total linux noob,

            thanks in advance

          • pattapn says

            September 22, 2017

            OK I've managed to use the right path, in fstab it had to be
            /root/.mozzila.....

            Now I'm stuck at rc.local which doesn't exist on my linux, instead i have:

            rc0.d
            rc1.d
            rc2.d
            rc3.d
            rc4.d
            rc5.d
            rc6.d
            rcS.d

          • Arnab Satapathi says

            September 22, 2017

            rc.local file is now obsolete with systemd, but if there's no rc.local file, then create it, and make it executable with chmod +x.
            Also don't forget to add the exit 0 line at the end of file. It will be automatically called by systemd after next reboot.

            However why you're using linux as root? I presume you're using Kali linux.

          • pattap says

            September 23, 2017

            OK I think all worked, it is definitely quicker.

            Just wondering if the fact that in about:cache there's no location for storage disk location as per the below
            "Storage disk location: none, only stored in memory"
            would be a good indicator of browser using RAM(assuming other things have been set correctly)?

            Yes it kali

            Thanks for you help 🙂

  5. GOGI says

    February 22, 2017

    Great work but one remark : you don't have to do a cronjob for new data being kept after a reboot, shutdown or even a crash (especially dealing with rc.local isn't the most proper way to do the job but rather a workaround).

    Instead of doing a cronjob through an rsync script, you can just write a --bind mount in fstab just after the previous one where you mounted firefox profile folder on tmpfs... The line would look like this :

    /home/$USER/.mozilla/firefox/profile.bac /home/$USER/.mozilla/firefox/profile_name.default none bind

    Reply
    • Arnab Satapathi says

      February 23, 2017

      Thanks ! Very good tip, I'll try it and update the tutorial.

      Reply
      • GOGI says

        February 24, 2017

        Well I withdraw what I said about binding folders, after some tests it doesn't behave as expected... The two mounts are still there but the second when binding folders overwrites all specs of tmpfs mount... So it wasn't a good tip at last 🙁 My bad.

        Reply
        • Arnab Satapathi says

          February 25, 2017

          Awe, It was a great idea, but sadly refused to work properly.

          Reply
  6. Pablo says

    August 29, 2016

    This is an excellent idea! Is there a way of checking that the profile was successfully mounted to tmpfs? And a way of checking it's synching properly?

    Reply
    • Arnab says

      August 29, 2016

      Hi Pablo, good questions 🙂

      1. If the machine was shutdown, perhaps there is no way to check if the profile folder was mounted as tmpfs or not, unless you run some script to monitor that activity. But you can easily check if the folder is currently mounted by the mount command.

      2. You can check if the profile folder was synced properly or not by monitoring the crond logs, use this grep -i 'cron' /var/log/syslog

      Reply
      • Pablo says

        August 29, 2016

        Thanks!
        1. It says tmpfs on /home/pablo/.mozilla/firefox/blahblah.default type tmpfs (rw,nosuid,nodev,size=128M,uid=1000,gid=1000). Is that alright?
        2. Yes, it's working!

        Reply
        • Arnab says

          August 29, 2016

          Yeah Pablo, it's alright.

          Reply
          • Pablo says

            September 2, 2016

            And what abour adding a line to /etc/rc6.d to make it sync at shutdown or reboot?

  7. Michel says

    May 19, 2016

    Hi, almost works fine, except my when I want to copy my default.profile shows me a lot error messages :
    #cp -a k02hcabe.default.back k02hcabe.default
    I got these messages:
    cp: no se puede crear el fichero regular «k02hcabe.default/k02hcabe.default.back/sessions/backup-70.session»: Permiso denegado

    Reply
    • Arnab says

      May 19, 2016

      What's the language ? Spanish ? It seems like that you don't have proper permission to create the folders/files.

      Try this cp -a k02hcabe.default k02hcabe.default.back

      And thanks for your feedback.

      Reply
  8. mad slackw says

    May 16, 2016

    h11i ARNAB

    i'm experiencing some trouble with your tutorial regarding the backup of default profile data

    if you say :

    cp -a profile_name.default/ profile.bac

    and after that

    rm -rf profile_name.default/*

    what happens is that the profile_name.default is removed, right ? so when i try to mount the profile_name_default i see the message :

    /home/$USER/.mozilla/firefox/3x9htqj8.default does not exist

    and the subsequent steps fails, so right now i have a kind of a new firefox install everytime i reboot the laptop

    am i doing something wrong on this steps ?

    thanks in advance

    Reply
    • Arnab says

      May 16, 2016

      Hi,

      Does the folder 3x9htqj8.default exists ?
      I tested the procedure again just before writing this comment, and it's working with Firefox 45 .

      You may try to temporarily mount the profile folder, for testing purpose,

      sudo mount tmpfs -t tmpfs -o size=128M /home/$USER/.mozilla/firefox/3x9htqj8.default

      Hope this helps, and please don't forget to notify me when you're done.

      Reply
  9. Sajesh says

    April 27, 2016

    I followed your guide and there's definitely some improvement. Thank you!

    One question: Will the tmpfs changes hold with Firefox updates? Do I need to do this again after the next update?

    Reply
    • Arnab says

      April 27, 2016

      Thanks Sajesh for comment !
      You don't need to worry about firefox update, all changes are hold on disk, inside the ~/.mozilla/firefox/profile.bac/ folder.

      Reply
  10. Siddhartha says

    August 21, 2015

    Thank u so much for sharing this tricky job...very helpful

    Reply
    • Arnab says

      August 25, 2015

      Thanks Siddhartha, I hope now your firefox is running blazing fast !! Stay connected with us.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © PCsuggest.com · All rights reserved.

  • Home
  • About
  • Contact
  • Privacy Policy
  • Sitemap