Difference between revisions of "Firefox/Profile on RAM"

From ArchWiki
Jump to: navigation, search
m (Relocate cache only to RAM: not a Warning according to Help:Style; change to Accuracy flag because if confirmed, that must be merged better into the section text)
(recategorize to avoid redirect (https://github.com/lahwaacz/wiki-scripts/blob/master/recategorize-over-redirect.py))
Line 1: Line 1:
[[Category:Web Browser]]
[[Category:Web browser]]
[[de:Firefox-Profile in Ramdisk auslagern]]
[[de:Firefox-Profile in Ramdisk auslagern]]

Revision as of 16:30, 26 July 2015

Merge-arrows-2.pngThis article or section is a candidate for merging with Firefox.Merge-arrows-2.png

Notes: please use the second argument of the template to provide more detailed indications. (Discuss in Talk:Firefox/Profile on RAM#)

Assuming that there is memory to spare, placing Firefox's cache or complete profile to RAM offers significant advantages. Even though opting for the partial route is an improvement by itself, the latter can make Firefox even more responsive compared to its stock configuration. Benefits include, among others:

  • reduced drive read/writes;
  • heightened responsive feel;
  • many operations within Firefox, such as quick search and history queries, are nearly instantaneous.

To do so we can make use of a tmpfs.

Because data placed therein cannot survive a shutdown, a script responsible for syncing back to drive prior to system shutdown is necessary if persistence is desired (which is likely in the case of profile relocation). On the other hand, only relocating the cache is a quick, less inclusive solution that will slightly speed up user experience while emptying Firefox cache on every reboot.

Note: Cache is stored separately from Firefox default profiles' folder (/home/$USER/.mozilla/firefox/): it is found by default in /home/$USER/.cache/mozilla/firefox/<profile>. This is similar to what Chromium and other browsers do. Therefore, sections #Place entire profile in RAM and #Relocating the entire profile to RAM don't deal with cache relocating and syncing but only with profile adjustments. See the note at Profile-sync-daemon#Benefits of psd for more details. Anything-sync-daemon may be used to achieve the same thing as Option 2 for cache folders.

Relocate cache only to RAM

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: It is not recommended to use this method; instead, leave the disk cache enabled and move it (or the complete profile) into RAM with a tmpfs. The maximum capacity of the memory cache is only 32MB. This can be checked by looking at about:cache. It's easy to fill this (memory) cache, and without any other (disk) cache, Firefox tends to crash often. (Discuss in Talk:Firefox/Profile on RAM#)

When a page is loaded, it can be cached so it doesn't need to be downloaded to be redisplayed. For e-mail and news, messages and attachments are cached as well. Firefox can be configured to use only RAM as cache storage. Configuration files, bookmarks, extensions etc. will be written to drive as usual. For this:

  • open about:config in the address bar
  • set browser.cache.disk.enable to "false" (double click the line)
  • verify that browser.cache.memory.enable is set to "true" (default value)
  • add the entry (right click->new->integer) browser.cache.memory.capacity and set it to the amount of KB you'd like to spare, or to -1 for automatic cache size selection. (Skipping this step has the same effect as setting the value to -1.)

Main disadvantages of this method are that the content of currently browsed webpages is lost if browser crashes or after a reboot, and that the settings need to be configured for each user individually.

A workaround for the first drawback is to use anything-sync-daemon or similar periodically-syncing script so that cache gets copied over to the drive on a regular basis.

Place entire profile in RAM

Relocate the browser profile to tmpfs so as to globally improve browser's responsiveness. Another benefit is a reduction in drive I/O operations, of which SSDs benefit the most.

Use an active management script for maximal reliability and ease of use. Several are available from the AUR.

Manual method

Relocating only the cache to RAM

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: This sections mentions the /home/<user>/.mozilla/firefox/default/Cache folder, which doesn't exist as of 2014.02 and has been superseded by /home/$USER/.cache/mozilla/firefox/<profile>. (Discuss in Talk:Firefox/Profile on RAM#)

Adapted from this forum post

After entering about:config into the address bar, create a new string by right-clicking in the bottom half, selecting New, followed by String. Assign its value:


Now, double-click the newly created string and direct it towards the RAM directory:


Upon restarting Firefox, it will start using /dev/shm/firefox-cache as the cache directory. Do mind that the directory and its contents will not be saved after a reboot using this method.

Alternative way: in /etc/fstab

 tmpfs     /home/<user>/.mozilla/firefox/default/Cache tmpfs mode=1777,noatime 0 0

Relocating the entire profile to RAM

Before you start

Before potentially compromising Firefox's profile, be sure to make a backup for quick restoration. Replace xyz.default as appropriate and use tar to make a backup:

$ tar zcvfp ~/firefox_profile_backup.tar.gz ~/.mozilla/firefox/xyz.default

The script

Adapted from verot.net's Speed up Firefox with tmpfs

The script will first move Firefox's profile to a new static location, make a sub-directory in /dev/shm, softlink to it and later populate it with the contents of the profile. As before, replace the bold sections to suit. The only value that absolutely needs to be altered is, again, xyz.default.

Be sure that rsync is installed and save the script to ~/bin/firefox-sync, for example:



set -efu

cd ~/.mozilla/firefox

if [ ! -r $volatile ]; then
	mkdir -m0700 $volatile

if [ "$(readlink $link)" != "$volatile" ]; then
	mv $link $static
	ln -s $volatile $link

if [ -e $link/.unpacked ]; then
	rsync -av --delete --exclude .unpacked ./$link/ ./$static/
	rsync -av ./$static/ ./$link/
	touch $link/.unpacked

Close Firefox, make the script executable and test it:

$ killall firefox firefox-bin
$ chmod +x ~/bin/firefox-sync
$ ~/bin/firefox-sync

Run Firefox again to gauge the results. The second time the script runs, it will then preserve the RAM profile by copying it back to disk.


Seeing that forgetting to sync the profile can lead to disastrous results, automating the process seems like a logical course of action.

cron job

Manipulate the user's cron table using crontab:

$ crontab -e

Add a line to start the script every 30 minutes,

*/30 * * * * ~/bin/firefox-sync

or add the following to do so every 2 hours:

0 */2 * * * ~/bin/firefox-sync
Sync at login/logout

Deeming bash is being used, add the script to the login/logout files:

$ echo '~/bin/firefox-sync' | tee -a ~/.bash_logout ~/.bash_login >/dev/null
Note: You may wish to use ~/.bash_profile instead of ~/.bash_login as bash will only read the first of these if both exist and are readable.

See also