Firefox and cache in RAM?

Discussion in 'all things UNIX' started by vasa1, Dec 26, 2011.

Thread Status:
Not open for further replies.
  1. vasa1

    vasa1 Registered Member

    Joined:
    May 1, 2010
    Posts:
    4,417
    What do folks think about Ramdisk Cache?
    I've been using it for a couple of days and my laptop hasn't exploded as yet.
     
  2. Mrkvonic

    Mrkvonic Linux Systems Expert

    Joined:
    May 9, 2005
    Posts:
    10,281
    Before you make such a change, did you check how much actual disk access you have? For example run Firefox for 30 min with sar in the background collecting IO info and then sum that and see how much actual disk access there really is?

    Now, what size is /dev/shm? This is a very specific device node. You can create any ramdisk and mount it anywhere you want, and probably better than /dev/shm, as some stupid programs may explicitly use /dev/shm for memory sharing rather than the internal kernel mechanism and you might end with weird problems. If /dev/shm is too large, you will effectively limit your ram and then you might start swapping out too early. Finally, upon reboot, the things stored there are lost, so you will need to recache your browsing sessions each time.

    Here's a decent read, minus the author's personal pondering:
    http://www.mjmwired.net/kernel/Documentation/filesystems/tmpfs.txt

    Don't make changes for the sake of change - verify whether you have a problem, and if so, how big it is and if you want to resolve it. If all your Firefox caching comes down to, say 200KB/sec read/write every minute, then this is completely useless, as data could also reside in the disk cache, which is also fairly large these days, several tens of MB and such.

    Even if you're writing to physical disk, seek times are ~100ms at most, if not reading from disk cache, and web pages and such loading are rather limited, both in actual size - how big are things online anyway in the sense you need them right now, not continuous downloads - plus your internet line. How much bandwidth do you have? 25Mbps - it's still 2MB/s write at most, for disks with typical speeds x30-40 more. And reading, 30-40KB html and some images and whatnot?

    Cheers,
    Mrk
     
  3. vasa1

    vasa1 Registered Member

    Joined:
    May 1, 2010
    Posts:
    4,417
    Oooh! Thanks, Mrk. I'll read your post very carefully but first I'll undo that about:config ASAP :D

    Edit: Done the undo thing!
     
  4. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    Bandwidth isn't really the issue. You can have 100GB bandwidth but your pages won't be instant because of bouncing requests back and forth aka RTT.

    With a cache you find it and that's it. If it's on the disk you're dealing in milliseconds and if you're on RAM you're dealing in Microseconds or Picoseconds. The difference is that searching a large amount of space in RAM will always be essentially just as fast but if you were to have a 10GB cache on the hard drive for Firefox (this would never happen, just an example) it would take a while to deal with the data.

    With RAM searching a 1MB file and a 10GB file is essentially the same amount of time (difference in less than picoseconds, random access going from 1GB of RAM to like... 256GB of RAM is going ot be discernable) and that's where your advantages come in. Large webpages and lots of them can be cached without a performance hit. And low access time is another plus.

    I used Cache to RAM for a while and didn't notice a huge difference but I have a fairly fast hard drive. I haven't really played around with it too much.

    At one point I set up a RAMDisk manually and moved my entire User_Data folder there for Chrome.
     
    Last edited: Dec 26, 2011
  5. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    After reading Hungry Man's viewpoint you may want to redo ASAP :D
     
  6. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    It really depends. IF you have the RAM to allocate to it, go for it. If you're running low on RAM you'll want to rethink it - the system overall may take a hit because it won't be able to cache more critical things.

    I personally have 8GB of RAM and could easily set up a RAMdisk - I don't because Chrome doesn't make it easy and their cache size/ replacement policy isn't clear.
     
  7. vasa1

    vasa1 Registered Member

    Joined:
    May 1, 2010
    Posts:
    4,417
    Stop pulling my leg! I thought I was doing something brilliant :(
     
  8. elapsed

    elapsed Registered Member

    Joined:
    Apr 5, 2004
    Posts:
    7,076
    Having a cache in RAM somewhat defeats the purpose of the cache in the first place. Otherwise, all browsers wouldn't bother with one and would live purely in RAM.
     
  9. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    wahhhhh no lol
     
  10. Mrkvonic

    Mrkvonic Linux Systems Expert

    Joined:
    May 9, 2005
    Posts:
    10,281
    Hungry man, have you ever tried to grab 10gb of ram, say write a value to every single bytes? It takes a while, and it's not the same for 1kb and 1gb or any other value.

    I agree that for super-heavy disk access, various caching techniques have their merits, but for the browser, which loads MB of data at most, and frankly how often do you open new pages - once every 10 sec? once every minute? How quickly can you really browse and read, really? Even if you're a compulsive user, you probably won't have more than 200-300 tabs open over the course of an entire day, so your access is really not that high.

    Mrk
     
  11. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    I was referring purely to seek time and reads. Finding a single file among 1MB of different files or 10GB (or 100GB or 200GB) of different files will take virtually the same time in RAM - microseconds, with a difference in picoseconds. Reads are going to be thousands of times faster than your HDD as well (22GB/s as opposed to 80MB/s) so if you for whatever reason had a cache of 100GB you could find the file almost instantly and if that file were 10GB you could read it almost instantly.

    That's not a realistic situation at all but it illustrates my point.

    It depends. A browser will cache images, which can be quite large. Thousands of them. You can easily hit 100MB of data.

    chrome://cache/ and you can view all of your cache files. Firefox probably has something similar.

    My cache is 300MB iirc but I can't check right now. I have seek times that jump between </.1ms and 13ms (SSD Hybrid) and reads are a few thousand MB below my RAM. If Chrome made it easier I definitely would use a RAMDisk because cache misses are very expensive for browsers. When you miss a cache hit on your CPU you go to RAM and then the HDD, each a few thousandths of the speed before it. It's the same thing when you miss a cache hit on your HDD and have to go to your internet for data - my internet is 10mb/s and it's not even just a simple read - HTTPS is going to take forever because of the million handshakes and even a regular HTTP site has significant RTT.

    I've also seen caches as large as 2GB. Chrome doesn't have a limit, it uses an algorithm based on disk size/speed to cache.
     
  12. elapsed

    elapsed Registered Member

    Joined:
    Apr 5, 2004
    Posts:
    7,076
    There's a reason IE9 pushed the default cache from 50MB to 250MB.

    You do realize RAM is flushed at reboot right? :D The ONLY advantage you gain from it is privacy.
     
  13. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    RAM is flushed any time power is cut to it. Last I checked computers didn't shut down by killing the power. You can easily make incremental backups, which are very quick to save and in the case of a cache wouldn't make much difference for startup times, maybe a few more seconds... but we do the same thing for superfetch.

    I don't know how Linux handles it but in Windows if you use RAMDisk you can set it to write backups every once in a while and every time you shut down.

    Computers are also moving away from shutting down and instead moving towards ultra low voltage states that maintain RAM but turn everything else off. This is actually a very much preferred method in a lot of cases and negates issues with RAM cache entirely.
     
    Last edited: Dec 26, 2011
  14. elapsed

    elapsed Registered Member

    Joined:
    Apr 5, 2004
    Posts:
    7,076
    !?! I think you need to check again.
     
  15. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    What I mean to say is that when you hit the power button there is a sequence of events that occurs. First certain tasks are killed, some things might get saved, etc. Only then is the power killed.
     
  16. elapsed

    elapsed Registered Member

    Joined:
    Apr 5, 2004
    Posts:
    7,076
    That's brand new information.

    At which point, RAM is lost.
     
  17. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    Yes... but the OS saves things to disk first. You can easily save the contents of the RAM to disk and then load it up at startup. This is how RAMDisk does it.

    RAMDisk is more designed for servers, which don't need fast startup/shutdown. Were Firefox to officially support this it's more likely that they'd use a different system involving incremental backups or storing part of the cache in RAM.

    If you don't use cache in RAM you just get writes to the hard drive. So why not write to the hard drive and RAM simultaneously? And then after a full shutdown you can just load it back up into RAM.
     
  18. elapsed

    elapsed Registered Member

    Joined:
    Apr 5, 2004
    Posts:
    7,076
    The overhead of creating a RAMDisk in the first place, and loosing that portion of RAM to be used as "storage" isn't even worth it considering anything that is frequently read becomes loaded into RAM anyway (Windows 7 uses as much of you RAM as it can to reduce disc I/O) At which point, you'd have contents of your RAMDisk being loaded into actual RAM and duplication happening.

    Again, the only reason to use a RAMDisk is "privacy". If you're storing contents that you purposely want removed and never recovered. Do you actually think that over the past 20 years the numerous browser vendors haven't considered using RAM instead of storage?
     
  19. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    Windows 7 won't necessarily load your cache into RAM because your cache may change frequently. That doesn't work well with Windows' cache replacement policy.

    It's important to note that what Firefox does is dynamic and what RAMDisk does is static. IF you have a Dynamic ram cache your OS won't have OOM issues.

    1) There are security implications, so we're talking post-DEP only, sooo about 12 years since XP was released and more like 10 years for mainstream usage and SP.

    2) We have not long lived in a world in which RAM has been so readily available to the point where the OS does not even know what to do with it.

    So yes, I think browser vendors haven't considered RAM instead of storage until recently - hence them only recently adding RAM storage of cache...
    http://windowstipoftheday.blogspot.com/2010/11/firefox-moving-your-cache-to-ram.html

    Firefox implements this as an experimental feature.
     
  20. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    Saying "They would have thought of it already" is silly.

    What about GPU acceleration? Everyone knows GPUs are better at things than CPUs in a lot of areas. Why are we only seeing it now?

    Hell, we only starteed seeing RAM caching on windows 4 years ago lol

    You seriously think we've just come up with everything we'll ever come up with? We haven't.
     
  21. elapsed

    elapsed Registered Member

    Joined:
    Apr 5, 2004
    Posts:
    7,076
    How would it change frequently? The whole point of a cache is to prevent re-downloading of objects thereby speeding up the rendering of a page. If it was "changing frequently" it would be somewhat pointless.

    Yet my response was clearly in response to you suggesting RamDisk and had nothing to do with firefox's option.

    10 Years ago firefox wasn't even called firefox, please... you say it like it's a short time.

    That has nothing to do with the browser cache which can range between 50-250Mb, which has been a standard since XP.

    Heh, firefox implemented that feature quite a long time ago and last I checked it was for privacy/security reasons. e.g. Tor, portable copies of firefox, etc. Not speed.

    Why does a discussion with you always feel like beating my head against a brick wall. You sidetrack from the discussion and dilute it so much in some attempt to seem correct it's just not even worth it. I didn't even say anything to suggest "we've come up with everything". :ouch:
     
  22. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    Cache replacement policy... if caches were static it would be pointless. They have to adapt to stay as small as possible while holding as much relevant info as possible. Your OS doesn't know what files are for your firefox cache and what files aren't. It just goes by least use. Firefox can manage its cache better than the OS because it knows which files are which. Same goes for the user to an extent.

    Different cache replacement policies will work differently. Some might prioritize size of files over usage of files and base size on disk space etc.

    I disagree with this even in the context of a RAMDisk. You can see how much your OS is caching in performance management. Have spare RAM? Throw it towards a RAMDisk.

    How else should I read this? It seems to me you're saying that if this idea were legitimate browser vendors would have already come up with it - they've had plenty of time.

    There are potential performance benefits to using RAMDisk. If you don't have a ton of RAM, don't do it. If you have excess RAM you may want to consider it - this is what I've said from the beginning.
     
    Last edited: Dec 26, 2011
Thread Status:
Not open for further replies.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.