Results 1 to 6 of 6

Thread: Moving a browsers cache to ram

  1. #1

    Default Moving a browsers cache to ram

    Noticing this comes from my concerns about disk noises and as a result I noticed for instance just how often and how much firefox writes to disk. If it was to ssd I really would be bugged about it. Most browsers seem to be well behaved and do use ~/.cache and keep settings related aspects some where else. I came across this comment on the arch wiki for firefox.

    Relocate cache only to 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.
    Can anyone explain the drawback further. Providing the addresses of the tabs that were loaded are retained I can't see why there is a problem. In fact if it caused firefox to refresh them when it was launched I'd see that as an advantage - save me doing it myself. Personally I would find loosing these rather painful. Refreshing when they had focus would be fine.

    I use more than one browser so wonder if the same thing can be done by replacing the cache directories with links to folders on a ram disk? That might leave some scope for writing some of the cache to disk.

    Better still replace the browser launch with a shell script that rsync's the on disk cache to ram, launches firefox and then rsync's the cache in ram to disk when firefox exits. I'd assume shell scripts can function like this on Linux as kde doesn't offer a facility to run commands after an application closes. That just leaves crashes or users forgetting to close it before shutting down. Maybe pending jobs can be made to run?
    Linux / kde crash - 'cause it doesn't.

    John
    -
    Leap 42.2 KDE 5.26
    3.6gig Xeon, 64bit SATA Raid home - Linux Raid 1
    All software on a flash drive, SATA swap & Temp files,

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    10,934
    Blog Entries
    2

    Default Re: Moving a browsers cache to ram

    I look at browser caching as either a remnant of a time long ago when broadband wasn't available, servers didn't have today's capacity, web technologies weren't as efficient or if even today you don't have access to broadband and your connection to the Internet is limited (eg dialup or ISDN).

    If you have a broadband connection, you should probably set your browser caching to the minimum possible if not disable it altogether(which is also described in your reference) so that the browser fetches every object on the web page every time the page is accessed.

    There is no drawback really for disabling or minimizing a browser disk cache... or for that matter if you re-directed to RAM except that the objects cached are non-persistent... But, that's the nature of everything in the cache, anyway. Even if your browser caches objects, simply reloading or refreshing the page over-rides the cached objects anyway.

    If you have a dialup or ISDN connection, then <maybe> caching will benefit you, but there are many variables that affect its effectiveness.

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  3. #3
    Join Date
    Sep 2008
    Posts
    2,997

    Default Re: Moving a browsers cache to ram

    a page from mozillazine
    http://kb.mozillazine.org/Browser.ca...ory#Background
    if you have the RAM do move your cache to it
    or are you asking how to move your cache to RAM?
    I'm not really sure how to do it in Linux
    on Windows you'd install a driver that would allow you to create a virtual hard drive from your ram and you'd set it's address in browser.cache.disk.parent_directory preference but I have no idea if something like this is easily done in Linux

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,869

    Default Re: Moving a browsers cache to ram

    Quote Originally Posted by I_A View Post
    on Windows you'd install a driver that would allow you to create a virtual hard drive from your ram and you'd set it's address in browser.cache.disk.parent_directory preference but I have no idea if something like this is easily done in Linux
    Is that what a tmpfs brings?
    That is a file system in RAM.

    I have e.g. in one of my systems /tmp as tmpfs (faster then revolving disk and automatic cleaning at shutdown):
    Code:
    tmpfs        /tmp    tmpfs    size=25%,uid=root,gid=root,mode=1777 0 0
    For the parameters see of course
    Code:
    man mount
    You should take some care in the naming however. When several users would use this, they can not all use the same path to the cache of course.
    Henk van Velden

  5. #5
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    10,934
    Blog Entries
    2

    Default Re: Moving a browsers cache to ram

    AFAIK for Firefox, the cache directory is also the location for temporary files
    https://support.mozilla.org/en-US/questions/773444

    It is also important to know that any files that you download are first downloaded to a temporary file, then copied to the Downloads folder with the correct file name.

    So, if you are in the habit of doing HTTP downloads of very large files... like openSUSE DVD installs, if your cache directory is in RAM that much RAM must be available for the temporary file... plus of course everything else your machine needs to operate and run any other applications which may be running concurrently.

    Example:
    If you have 8GB RAM in your machine, and you decide you want to download a 4.7GB ISO file while also doing your mail, web surfing and maybe watching a video... You'll be in trouble.

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  6. #6

    Default Re: Moving a browsers cache to ram

    I've used the normal firefox setting to set the cache to zero. That's worked. There are some thumbnails retained, a startupCacje.8.little - 5.8mb, directoryLinks.jason - 2.3kb, frquencyCap.json - 2bytes and one directory safebrowsing. Firfox's behaviour has changed, for the better as far as I am concerned. My tabs are retained when it's relaunched and are refreshed when each one is bought into focus - saves me doing it.

    I've been using iostat, iotop and dstat to look at this on my /home as it's on a separate disk. This can show what is actually doing the writes, Virtually all by kernal services which is rather frustrating and some of it may just be down to ext4.

    Then I had a thought. What I really wanted to know was which files were being regularly updated.

    Code:
     find /home/john -cmin -2
    /home/john/.mozilla/firefox/rs5sesxw.default/cookies.sqlite-wal
    /home/john/.mozilla/firefox/rs5sesxw.default/sessionstore-backups
    /home/john/.mozilla/firefox/rs5sesxw.default/sessionstore-backups/recovery.bak
    /home/john/.mozilla/firefox/rs5sesxw.default/sessionstore-backups/recovery.js
    /home/john/.mozilla/firefox/rs5sesxw.default/cookies.sqlite
    /home/john/.mozilla/firefox/rs5sesxw.default/cookies.sqlite-shm
    another over 1 min this time
    Code:
    find /home/john -cmin -1
    /home/john/.xsession-errors-:0
    /home/john/.mozilla/firefox/rs5sesxw.default/cookies.sqlite-wal
    /home/john/.mozilla/firefox/rs5sesxw.default/sessionstore-backups
    /home/john/.mozilla/firefox/rs5sesxw.default/sessionstore-backups/recovery.bak
    /home/john/.mozilla/firefox/rs5sesxw.default/sessionstore-backups/recovery.js
    /home/john/.mozilla/firefox/rs5sesxw.default/cookies.sqlite-shm
    I'm assuming the -cmin option is updates. Hope I'm correct? The entire directory has about 50mb in it. This is a typical update rate when firefox is in use, bytes written.

    Code:
    30-05 14:23:00|   0    76k
    30-05 14:23:03|   0    32k
    30-05 14:23:08|   0   136k
    30-05 14:23:09|   0   548k
    30-05 14:23:11|   0    16k
    30-05 14:23:13|   0   504k
    30-05 14:23:24|   0   644k
    30-05 14:23:26|   0    56k
    30-05 14:23:34|   0   356k
    30-05 14:23:39|   0   568k
    30-05 14:23:45|   0    44k
    I've set ext4 to data=writeback mode.I had been using noatime but this is not shown as an option on the kernel org page. Initially the disk was being accessed every 5 sec (default) until I added that. It's mentioned as an ext4 option all over the place on the web. Writeback prevents the 5 sec accesses as well There is also a lazy update option but to be of much use it would need to be set to a rather long period just for fifefox.

    It looks to me like the entire directory needs running in ram as the updated files are generally in it's root. If they were all in a directory that could just be mounted to ram.

    Any thoughts?

    John
    -
    Leap 42.2 KDE 5.26
    3.6gig Xeon, 64bit SATA Raid home - Linux Raid 1
    All software on a flash drive, SATA swap & Temp files,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •