Speed up Web Browsing in Linux

In modern computer systems, the biggest bottleneck of information tends to be in communicating with the hard disks. High seek times and relatively slow transmission rates when compared to RAM speeds can add up quickly. This was a necessary evil back when RAM space and costs were at a premium, but now it is not uncommon to see 4GB of RAM on laptops, and even 12GB on desktops. For  users whose primary computer use is browsing the internet (either for work, writing articles, or lolcats) and have some extra RAM, moving the browser cache to the RAM from the hard disk is a definite option for increasing speed.

In Linux systems (specifically Fedora and Ubuntu systems), this can be achieved for Chrome and Firefox by creating a larger ramdisk, mounting the ramdisk after boot, and then setting the browser of choice to use that ramdisk as a cache. The necessary commands to do this are readily available on the internet, which makes life easy. Using ramdisks for performance boosts are not exclusive to browsers, and can be used for other software such as Nagios for example.

We have previously covered a tool called Espérance DV for moving cache to RAM in Mac OSX, and for any Windows users feeling left out, there are ways of making Firefox bend to your will. Obviously you will see an increase in RAM use (duh), but this shouldn’t be a problem unless you are running out of free RAM on your system. Remember, free RAM is wasted RAM.

Comments

  1. osgeld says:

    this should help a lot on my work pc! never mind its like 30 people on a 1mb dsl line

    that seems to be the biggest bottleneck in my experience, at least when it comes to web browsing

  2. Jose Pereira says:

    If you have a good amount of RAM, the best would be to mount the whole /tmp as ramfs.

    Cheers

  3. Jef says:

    yeah, let’s piss away a gig of ram just for FF to use as disk cache to save a second or two when loading pages. never mind mencoder trying to cache 4.5gb of VOB’s, this will certainly speed up my system!

  4. PaoloC says:

    While this hack might speed up repeated visits of the same content within the same “uptime” session, the whole cache will be lost when the machine is switched off.

    IMO who is on a slow/shared link will benefit more from a permanent disk cache rather than a hyperfast file access while waiting for the remaining content to load.

    Neither page load speed increase is provided (firefox can do it with a plugin) nor it is mentioned that the cache is lost in either article.

    My 2c worth.

  5. pascal says:

    I thought the browsers automatically cached things in RAM first? Having the browser decide what to keep in RAM and what to write to the disk is better since they are usually quite good at that, but if they fill the ramdisk with useless stuff, things that really should be in RAM get swapped out to disk, making the problem worse.

  6. pascal says:

    (also the Linux tools display this quite nicely: there usually is no “free RAM”. The kernel fills the space not used by applications with the disk cache. And having 2GBytes of disk cache also helps the browser using that cache to write to the disk)

  7. infl00p says:

    It is the most stupid way to use a ramdrive in linux since 2002. If you want a ram space in linux just use tmpfs, it has variable maximum size and doesn’t grab a chunk of memory, since it has the same size as the files stored in it.
    Nowadays you can use even compressed ram (ramdrive) with compcache.

  8. Pete says:

    The reason that moving the cache to RAM helps is not so much that it keeps it in RAM as that it can carry out file sync operations without having to wait for them to complete on disk. This can give you a striking speedup on some applications – at the cost of losing data in the event of a crash or power failure.

  9. gzo says:

    This hacks sounds that you want to do the job of the OS, and I bet that the final result is not worth the effort. The kernel already keep disk data cached in memory. Forcing data to be held in memory, will increase memory pressure on other apps, and obviously lead to start a browsing session with the cache empty, unless you save memory data to disk before shutting down and reload at them at boot. IMHO: not worth the effort.

  10. Pete says:

    tmpfs has a couple of strange limitations which I forget. I have a system which involves a tmpfs which contains a single large file, which is loopback mounted as an ext2 filesystem. This is used for ccache.

  11. Pete says:

    (and I find it amusing that people are saying this won’t improve performance in theory when other people are discovering it does in practice!)

  12. Motoma says:

    Not only did you post this tip two years ago, but this technique is neither novel nor new; I first heard about this technique back in the Windows 98 era.

  13. Jim Bauwens says:

    Today I moved my WHOLE ubuntu system to ram (except the my home directory). I have 1gb of ram, and my system takes 500mb. So I have 500 mb left to do stuff, which is enough for me (I never go over 300mb).

  14. daenris says:

    I used a RAM disk on my Apple IIGS after I put an expansion card in that allowed me to play MSDOS games because the disk load time was atrocious, especially for sounds.

  15. Matt says:

    Or you could just increase Firefox’s memory cache limit to keep data in RAM:

    http://kb.mozillazine.org/Browser.cache.memory.capacity

  16. GZ says:

    Win98? Ram drives were standard issue on the Amiga OS back in the late 80s. They would auto expand/contract as well. Ah the good old days.

    ;-)

  17. BP says:

    I used ram disk to speed things up when I was running DOS. I found that my COBOL compiler fit in RAM and that by moving everything to a ramdisk I could get compiles of over 30K lps, too bad the compiler had a 500 line limit, but it sure beat using punch cards.

    There are a lot of things that can be done to speed up a general purpose OS when you want to only run a few applications. Removing unused applications (modules, xinetd, rc.d, inittab, window manager) frees resources for the application that you want to run, You can bypass DNS if you only want to use a few site like facebook ,Youtube and hackaday and put the IP’s into hosts. I also use this trick to block E-Bay.

  18. Bob says:

    This seems like a good hack to cover your tracks online. Deleted cache files on disk can be recovered. Not the same with ram. That’s the only advantage I see. Who visits the same xxx content more than once anyways?

  19. John says:

    Looking at my 2Gb machine, it is already using ~1Gb for disk cache with less than 100Mb of free RAM. If I permanently steal some of that RAM for a disk is that not going to make everything else a bit slower?
    I think that the only real way this could speed things up is if the browser was doing something stupid like calling lots of fsync on it’s cache files if not then Linux will just hold them in RAM until it has some free time to write them to disk.
    I suppose you are forcing the OS to give that RAM to the browser cache and that could help as long as it does not have to start to swap out or flush some of the browsers memory to make space. If it has to read the browsers code from disk because it does not have enough RAM to hold it all in it’s cache then it could be a little counter productive.

  20. Zish says:

    You’re going to have to load all that stuff from a disk somehow. Why not just leverage the filesystem cache inherent in the Linux kernel already? You could even go so far as doing a makeshift “readahead” (cat, dd, or something. pipe to /dev/null) during boot time. That way, when it comes time to start your browser, most stuff will be in your FS cache.

    If you have a log of RAM, by default Linux will use the unused portions for cache.

    Just my 2c.

  21. xyz says:

    A browser cache must be a relativly simple case for the OS cache to handle.

    The files go in the cache and then are read occasionally. The files are not edited and only the browser process is touching the files.
    Plus the browser cache handing code is likely to be mature, optimised and not do anything stupid.

    The sqlite database stuff in firefox on the other hand. Especially the awesome bar. I have an old netbook with a glacially slow SSD and that’s where I really feel the pain of disk accesses. Perhaps sticking them in a RAM disk would be a good idea.

  22. Jim says:

    In ubuntu dev/shm is already a ramdisk(looks like a normal folder). By default it limits the size of the directory to half of your system’s RAM. This also works very well for torrents if you have enough RAM.

  23. gunner says:

    amiga ftw, i’ve got an a1200 with DKB cobra card (68030@28mhz, 128mb of ram) and can easily fit all of workbench 3.1 and some of my more frequently used apps in the ramdisk with room to spare, maybe even WB3.5

  24. DerAxeman says:

    If you want a speed increase the first thing to do is ditch ubuntu and switch to Gentoo. Tuning your applications , kernel, and libraries to your specific processor makes a big difference. Another thing you can do that helps is to run a kernel with the transparent hugepage support patch.

    current git tree of the kernel source with the patch applied. http://git.kernel.org/gitweb.cgi?p=linux/kernel/git/andrea/aa.git;a=summary

    Also I might point out that unused ram in linux is used as disk cache.

  25. MrX says:

    @DerAxeman
    Hugepage now also supports memory compaction.

  26. Jen says:

    That’s a silly thing to do. The most important single factor in speeding up browsing on a Linux machine is disabling Flash. Ever since Adobe got their hooks into it, the Linux Flash plugin has become an abysmally slow CPU hog. Even on a multi-core machine, expect Flash to eat a single core per instance.

    After that, just make sure that Linux has enough free RAM to use for disk cache. Ubuntu comes with so much extra cruft that you need a good few gigs before it stops touching the higher memory pages for application memory. Metacity and all the various Gnome plugins and whatnot take a fair amount of memory and CPU cycles. I run vtwm. Nice and lean.

    My machine has 16GB, and after the initial load, browsing doesn’t touch the disk at all. Plenty fast for me, at least until some “brilliant” marketroid decides that I really need to see another talking Flash ad.

  27. John says:

    I used ramdisk on vinyl

  28. jbx says:

    It’s much more efficient to use the hosts file to block pics/javascript/flash ad servers before it floods you cache. This useless content forms actually the main part of a web page.

    Ie : check this page html code and see by yourself…

    I’ve stopped playing with ramdisks after I graduated.

  29. wernicke says:

    @Zish “If you have a log of RAM, …”

    I wish! I have only a couple of sticks of RAM in my system :)

  30. drew says:

    I want to say, I consider this issue a hack, and I hope people agree.

    My main and only computer is a 2005 Dell Inspiron 9300 with the super duper Ge Force Go 6800 256 Ram video card and 2 GB of RAM. It’s also dual boot with XP and linux, the 80% of the upgraded hard disk is linux.

    My computer is limited severely to only 120 GB and 2 GB max RAM by BIOS, and stuff like this really helps me get the best from my old laptop, as I can’t even afford a new netbook!

  31. Firebelcher says:

    http://www.speedguide.net/articles/ramdisk-guide-131

    http://www.wikihow.com/Speed-Up-Firefox-by-Running-It-In-RAM

    RamDisk for Windows as well… Works great if you have a lot of ram. I haven’t tried this on Windows 7 / Vista though.

  32. cantido says:

    @DerAxeman

    >>If you want a speed increase the
    >>first thing to do is ditch ubuntu

    Have you actually done any benchmarks?
    When the whole Gentoo craze was kicking off all the benchmarks actually suggested that only a few specific applications showed any difference and some actually performed worse..

    http://www.phoronix.com/scan.php?page=article&item=calculate_gentoo_benchmarks&num=3

    From this page I can see that the difference is usually marginal.. is it really worth spending all that time building stuff from source (wasting energy etc in the process) when there is little to no net gain?

    >>kernel, and libraries

    Kernel and clib are the only parts that really matter here.. and specific applications like VLC that really benefit from knowing what SIMD instruction set, if a hard floating point unit etc in available. The applications that matter should have run-time detection of anything that is useful strangely enough.

    >>specific processor makes a big difference.

    Yes, if you have a ARM processor with a hard FPU and everything is compiled for softfloat.. on most x86 boxes. No.

    @Thread

    If you’re visiting a page enough to warrant having its files cached in RAM surely it will be in your disk cache already or in the browsers in-memory cache. Chromium is plenty fast enough here on my Atom machine… hardware H264 decoding and 100mbit connecttion FTW.

  33. Erik Johansson says:

    You can use a compressed ramdisk to lower the RAM requirements, sadly that means making a filesystem on top of the a block device that is compressed. http://code.google.com/p/compcache/

  34. killasmurf86 says:

    I’ve been doing this on FreeBSD with Opera for quite some time now.

  35. jean says:

    …??? sorry if i sound rude, but this is silly. Don’t you think that bottleneck for common plain mortals in this case is the NET speed? …and: free ram is not wasted ram, since it means that new processes will find some without triggering paging: the average user is not so rich he can afford a machine with so much RAM that paging is not needed.

  36. HackJack says:

    There has always been people proposing to disable virtual memory. It is simply not a good idea. There are always junk that you are not going to use again. Why waste the RAM to store them? What’s wrong with caching algorithm?

  37. Ugly American says:

    Firefox & Flash are not really 64 bit so they can’t use more than 2G of RAM directly. Firefox & Flash are not really multi-threaded so they can’t use multiple CPU cores directly. Get a modern browser like Chrome or Safari instead.

    The performance problem with Firefox on Linux is mostly because it uses SQLite and sync() calls that force it to flush the disk cache and wait until done. It’s not obvious on Windows because Windows fakes the sync() calls. That improves performance but means you have no actual guarantee of data integrity on Windows. Putting the files in RAM subverts the data integrity checks and makes Linux emulate Windows, favoring speed over data integrity. Firefox also has other legacy single threaded chokepoints.

    The performance problem on Windows is primarilty that the OS has fractional RAM allocation by design and many apps still have 32 bit limits. You may have 16G of RAM and Windows 7 64 bit but if you’re using a 32 bit browser it can only get 2G of RAM and Windows will automatically try to page part of that out to disk. Creating a RAM disk as another process with it’s own RAM and helps keep that data in RAM instead of on the drive. Similar limits happen when people run the 32 bit version of Firefox on 64 bit Linux so they can run 32 bit plug-ins like Flash. Even though you have 16G of RAM, using the 32 bit Flash in the 32 bit browser limits it to 2G of RAM.

    Obvious solutions to these problems are to avoid legacy single threaded and 32 bit programs like Firefox & Flash. Those codebases will die off eventually. They were useful in their day but they are the past.

    • Chris says:

      “Favoring speed over data integrity”? When was the last time your RAM lost data integrity? The solution presented in this article is very good and should be adopted by the designers of browsers.

  38. brem69 says:

    I have been running I.E from RAM disk for some time now moving file in internet option’s settingsto RAM.

    Also moving I.E Cache and flash player data to RAM disc also.

    One of the best things i did for Internet Explorer.

  39. Squirrel says:

    ImDisk works like a charm on Windoze

    http://www.ltr-data.se/opencode.html/#ImDisk

  40. Lagato says:

    Whenever I open firefox, this message appears “Your Firefox profile cannot be loaded. It may be missing or inaccessible.”. This happened after I foolishly decided to try to move the cache to RAM disk, which I have miserable failed to do so and effed up firefox in the mean time. I entered command lines
    “$ rm -r ~/Library/Caches/Firefox
    $ ln -s /Volumes/RamDisk/Firefox ~/Library/Caches/Firefox”
    and
    “rm -r ~/library/caches/firefox mkdir /volumes/ramdisk/firefox\ \(\cache\) ln -s /volumes/ramdisk/firefox\ \(\cache\) ~/library/caches/firefox”
    which it said will
    -removes cache folder -makes new cache folder in RamDisk -creates symlink from HD to RamDisk
    I’ve got nothing in my profile folder, and I get the same message when I attempt to open the profile manager. I’ve did re-installation, cleaned my profile folder, and still get the same thing. Tried the home access command line too. I sincerely thank you for your help, I know I’m really stupid when I messed with stuff I shouldn’t, I’ve already presumable loss all my bookmarks and saved passwords. I just want to use firefox again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 96,756 other followers