Difference between revisions of "Firefox/Profile on RAM"

From ArchWiki
Jump to: navigation, search
(wikify some external links, use https for archlinux.org)
(30 intermediate revisions by 14 users not shown)
Line 1: Line 1:
[[Category:HOWTOs (English)]]
+
[[Category:Scripts]]
[[Category:Scripts (English)]]
+
[[Category:Web Browser]]
[[Category:Web Browser (English)]]
+
[[de:Firefox-Profile in Ramdisk auslagern]]
 
+
 
Assuming that there is memory to spare, caching all, or part of [[Firefox]]'s profile to RAM using [[Wikipedia:tmpfs|tmpfs]] 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:
 
Assuming that there is memory to spare, caching all, or part of [[Firefox]]'s profile to RAM using [[Wikipedia:tmpfs|tmpfs]] 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 disk read/writes (ideal for [[Maximizing performance#Tuning for an SSD|SSD]])
+
*reduced disk read/writes
 
*heightened responsive feel
 
*heightened responsive feel
 
*many operations within Firefox, such as quick search and history queries, are nearly instantaneous
 
*many operations within Firefox, such as quick search and history queries, are nearly instantaneous
  
Both of previously mentioned options make use of native shared memory; [[/dev/shm]], a directory that behaves just as ordinary mounted file systems do, only with the notable exception that all of its content is stored in RAM.
+
Both of previously mentioned options make use of [[tmpfs]].
  
 
Because data placed therein cannot survive a shutdown, a script used when [[#Relocating the entire profile to RAM|moving the whole profile to RAM]] overcomes this limitation by syncing back to disk prior system shut down, whereas [[#Relocating only the cache to RAM|only relocating the cache]] is a quick, less inclusive solution.
 
Because data placed therein cannot survive a shutdown, a script used when [[#Relocating the entire profile to RAM|moving the whole profile to RAM]] overcomes this limitation by syncing back to disk prior system shut down, whereas [[#Relocating only the cache to RAM|only relocating the cache]] is a quick, less inclusive solution.
  
==Relocating only the cache to RAM==
+
==Method 1: Use RAM-only cache==
<small>''Adapted from [http://bbs.archlinux.org/viewtopic.php?pid=604369 this forum post]''</small>
+
Firefox can be configured to use only RAM as cache storage. Configuration files, bookmarks, extensions etc. will be written to harddisk/SSD as usual. For this
 +
* open {{Ic|about:config}} in the address bar
 +
* set {{Ic|browser.cache.disk.enable}} to "false" (double click the line)
 +
* set {{Ic|browser.cache.memory.enable}} to "true" (double click the line)
 +
* set {{Ic|browser.cache.memory.max_entry_size}} to the ammount of KB you'd like to spare, to -1 for [http://kb.mozillazine.org/Browser.cache.memory.capacity#-1 automatic] cache size selection
 +
Main disadvantages of this method are that your tabs won't survive a browser crash, and that you need to configure the settings each user individually. On the other hand on a personal system it probably is the easiest method to implement.
  
After entering {{codeline|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:
+
==Method 2: Use PKG from the AUR==
 +
Relocate the browser profile to [[wikipedia:Tmpfs|tmpfs]] filesystem, including {{ic|/tmp}} for improvements in application response as the the entire profile is now stored in RAM. Another benefit is a reduction in disk read and write 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.
 +
 
 +
*{{AUR|profile-sync-daemon}} - refer to the [[Profile-sync-daemon]] wiki article for additional info on it;
 +
*{{AUR|firefox-tmpfs-daemon}}
 +
*{{AUR|firefox-sync}}
 +
 
 +
==Method 3: Build your own system ==
 +
 
 +
===Relocating only the cache to RAM===
 +
<small>''Adapted from [https://bbs.archlinux.org/viewtopic.php?pid=604369 this forum post]''</small>
 +
 
 +
After entering {{Ic|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:
 
  browser.cache.disk.parent_directory
 
  browser.cache.disk.parent_directory
  
Line 21: Line 39:
 
  /dev/shm/''firefox-cache''
 
  /dev/shm/''firefox-cache''
  
Finally, create the directory and ensure its permissions have security in mind:
+
Upon restarting Firefox, it will start using {{ic|/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.
mkdir -m0700 /dev/shm/''firefox-cache''
+
  
Upon restarting Firefox, it will start using {{Filename|/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
  
==Relocating the entire profile to RAM==
+
  tmpfs    /home/<user>/.mozilla/firefox/default/Cache tmpfs mode=1777,noatime 0 0
===Before you start===
+
 
Before potentially compromising Firefox's profile, be sure to make a backup for quick restoration. Replace {{codeline|xyz.default}} as appropriate and use {{codeline|tar}} to make a backup:
+
===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 {{Ic|xyz.default}} as appropriate and use {{Ic|tar}} to make a backup:
 
  $ tar zcvfp ~/firefox_profile_backup.tar.gz ~/.mozilla/firefox/''xyz.default''
 
  $ tar zcvfp ~/firefox_profile_backup.tar.gz ~/.mozilla/firefox/''xyz.default''
  
===The script===
+
====The script====
 
<small>''Adapted from [http://www.verot.net/firefox_tmpfs.htm verot.net's Speed up Firefox with tmpfs]''</small>
 
<small>''Adapted from [http://www.verot.net/firefox_tmpfs.htm verot.net's Speed up Firefox with tmpfs]''</small>
  
The script will first move Firefox's profile to a new static location, make a sub-directory in {{filename|/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, {{codeline|xyz.default}}.
+
The script will first move Firefox's profile to a new static location, make a sub-directory in {{ic|/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, {{Ic|xyz.default}}.
  
Be sure that [[rsync]] is installed and save the script to {{filename|~/bin/firefox-sync}}, for example:
+
Be sure that [[rsync]] is installed and save the script to {{ic|~/bin/firefox-sync}}, for example:
{{file|name=firefox-sync|content=
+
{{hc|firefox-sync|2=
 
#!/bin/sh
 
#!/bin/sh
  
Line 43: Line 62:
 
link=''xyz.default''
 
link=''xyz.default''
 
volatile=''/dev/shm/firefox-$USER''
 
volatile=''/dev/shm/firefox-$USER''
 
  
 
IFS=
 
IFS=
Line 75: Line 93:
 
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.
 
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.
  
====From the AUR====
+
====Automation====
The script is available as a [http://aur.archlinux.org/packages.php?ID=41541 package].
+
This version automatically picks the first {{codeline|xyz.default}} directory in your {{filename|~/.mozilla/firefox}} (although that means you should install it with sudo, not as root).
+
 
+
The script also provides a firefox wrapper {{codeline|syncfox}}, which runs {{codeline|firefox-sync}} before and after {{codeline|firefox}}. This is an alternative to syncing with cron, or on login/logout (described below). Be careful with the "Restart Firefox" button within firefox, though, since this might not start the wrapper.
+
 
+
===Automation===
+
 
Seeing that forgetting to sync the profile can lead to disastrous results, automating the process seems like a logical course of action.
 
Seeing that forgetting to sync the profile can lead to disastrous results, automating the process seems like a logical course of action.
  
====cron job====
+
=====cron job=====
Manipulate the user's [[cron]] table using {{codeline|crontab}}:
+
Manipulate the user's [[cron]] table using {{Ic|crontab}}:
 
  $ crontab -e
 
  $ crontab -e
  
Line 93: Line 105:
 
  0 */2 * * * ''~/bin/firefox-sync''
 
  0 */2 * * * ''~/bin/firefox-sync''
  
====Sync at login/logout====
+
=====Sync at login/logout=====
 
Deeming [[bash]] is being used, add the script to the login/logout files:
 
Deeming [[bash]] is being used, add the script to the login/logout files:
 
  $ echo '<i>~/bin/firefox-sync</i>' | tee -a ~/.bash_logout ~/.bash_login >/dev/null
 
  $ echo '<i>~/bin/firefox-sync</i>' | tee -a ~/.bash_logout ~/.bash_login >/dev/null
{{Note| You may wish to use {{Filename|~/.bash_profile}} instead of {{Filename|~/.bash_login}} as bash will only read the first of these if both exist and are readable.}}
+
{{Note| You may wish to use {{ic|~/.bash_profile}} instead of {{ic|~/.bash_login}} as bash will only read the first of these if both exist and are readable.}}
  
== Resources ==
+
==See also==
* [http://en.wikipedia.org/wiki/Tmpfs tmpfs] on Wikipedia
+
 
* [[Fstab#tmpfs]]
 
* [[Fstab#tmpfs]]

Revision as of 16:11, 4 December 2012

Assuming that there is memory to spare, caching all, or part of Firefox's profile to RAM using tmpfs 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 disk read/writes
  • heightened responsive feel
  • many operations within Firefox, such as quick search and history queries, are nearly instantaneous

Both of previously mentioned options make use of tmpfs.

Because data placed therein cannot survive a shutdown, a script used when moving the whole profile to RAM overcomes this limitation by syncing back to disk prior system shut down, whereas only relocating the cache is a quick, less inclusive solution.

Method 1: Use RAM-only cache

Firefox can be configured to use only RAM as cache storage. Configuration files, bookmarks, extensions etc. will be written to harddisk/SSD as usual. For this

  • open about:config in the address bar
  • set browser.cache.disk.enable to "false" (double click the line)
  • set browser.cache.memory.enable to "true" (double click the line)
  • set browser.cache.memory.max_entry_size to the ammount of KB you'd like to spare, to -1 for automatic cache size selection

Main disadvantages of this method are that your tabs won't survive a browser crash, and that you need to configure the settings each user individually. On the other hand on a personal system it probably is the easiest method to implement.

Method 2: Use PKG from the AUR

Relocate the browser profile to tmpfs filesystem, including /tmp for improvements in application response as the the entire profile is now stored in RAM. Another benefit is a reduction in disk read and write 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.

Method 3: Build your own system

Relocating only the cache to 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:

browser.cache.disk.parent_directory

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

/dev/shm/firefox-cache

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:

firefox-sync
#!/bin/sh

static=main
link=xyz.default
volatile=/dev/shm/firefox-$USER

IFS=
set -efu

cd ~/.mozilla/firefox

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

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

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

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.

Automation

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