• Badabinski@kbin.earth
    link
    fedilink
    arrow-up
    25
    ·
    1 month ago

    The problem is that the extra RAM used by a browser is held on an exclusive basis and so is not nicely reclaimable by the kernel. I love that Linux caches the shit out of files in RAM, it’s great. It’s also great that it can release that memory when I launch a chundering dumpster fire application that eats all of my RAM. If a browser had been holding that memory, then the godawful Linux OOM killer would have launched, halted all threads on the system, walked the entire process tree, and SIGKILLed something (probably not a browser tab) before letting everyone else resume.

    With the way memory is currently managed, a bloated browser is a liability. Cached state needs to be stored in something like a mmaped file so that the kernel can flush pages out of memory if someone else comes along with a malloc. Alternatively, there needs to be communication between a browser and a userspace OOM daemon. If the system started hitting a soft limit, then the browser could start unloading background shit more aggressively.

    Free memory is wasted memory, but so is memory that can’t be used for anything else when it’s needed.

    • otacon239@lemmy.world
      link
      fedilink
      arrow-up
      12
      ·
      edit-2
      1 month ago

      Yeah, I agree. Browsers all seemed to act like they are the only thing running on the computer at some point, practically resembling their own OS with the amount of containerization and complexity. There should definitely be a way for the OS to request some RAM be released from the browser.

      • Draconic NEO@lemmy.dbzer0.com
        link
        fedilink
        arrow-up
        3
        ·
        30 days ago

        That’s why I just prefer to limit the RAM available to the browser to an amount that I feel is necessary for good performance while not so much that it causes issues with other things running. To some people that might sound like a bad or stupid idea but think of it this way. You just said that modern browsers are complex and resemble their own Operating System, right? Well if you were running a VM you probably wouldn’t give the virtualized OS complete access to all your RAM, that’s asking for the VM to crash or freeze your PC. So why should general practice be any different for a browser then, they may be less aggressive than a Kernel managed VM but they can still be problematic when they eat to much RAM. Which is why I choose to limit mine so it doesn’t get more than 8GB, which I feel is perfectly reasonable on most systems where that’s half of all the memory available, and even on bigger ones you’re not missing out on much. Firefox performs just as well with 8GB as it does with 16GB, but with 16GB it’ll eat way more than it uses.

        Here’s the script I used. Should work for most linux users. I don’t know how to do it on Windows since I don’t use Browsers there for long enough periods for this to become problematic.\

        Desktop file to limit Firefox to 8GB of RAM
        [Desktop Entry]
        Version=1.0
        Name=Firefox RAM limit 8GB
        GenericName=Firefox Ram limit 8GB
        Comment=Limit RAM for Firefox to 8GB;
        Exec=systemd-run --user --scope -p MemoryLimit=8G firefox
        Icon=firefox
        Type=Application
        Terminal=false
        Categories=Utility;Development;
        StartupWMClass=Firefox
        

        CC: @[email protected]