If I run firefox unrestrected that crashes my system from time to time. I’ve been using the systemd-run command to run firefox whilst maintaining system stability like so:
systemd-run --scope -p MemoryLimit=20000M firefox &
I’d like to get some advice or suggestions of any better ways to do this and also the best way to automate it so that it happens even if I just click on the Firefox icon.
If I run Firefox in my default way then regularly, after some time, I run out of memory. This can cause multiple issues:
- firefox locks up for a time and then recovers
- The GUI locks up for some time but then recovers (recovery after over 1/2 hour has happened)
- firefox locks up and crashes
- X locks up for a long time and crashes, logging me out
- the system as a whole locks up for too long (I’ve tested up to 10 hours)
If I run in a cgroup with systemd-run like above, then I still have the problem that Firefox occasionally crashes, but when it does so at least the system seems to survive and so I can just restart Firefox. The cause of the crash when cgroups is active seems to be that firefox calculates memory usage in a way that is not cgroups friendly, using meminfo
I’d like to know if there’s a better way to protect the system against Firefox excessive memory usage and, also, as I said before, how to ensure this happens automatically.