4 ms·
The annoying thing I've found with Linux under memory stress (and still haven't found a nice way to solve) is I want it to always always always kill firefox fir
by rwmj 8mo ago
The annoying thing I've found with Linux under memory stress (and still haven't found a nice way to solve) is I want it to always always always kill firefox first. Instead it tends to either kill nothing (causing the system to hang) or kill some vital service.
- pmontra 8mo agoI'm not sure that I'd want the OS to kill my browser while I'm working within it. Of course the browser is the largest process in my system, so when I notice that memory is running low I restart it and I gain some 15 GB. Basically I am the memory manager of my system and I've been able to run my 32 GB Linux laptop with no swap since 2014. I read that a system with no swap is suboptimal but the only tradeoff I notice is that manual OOM vs less writes on my SSD. I'm happy with it.
- robinsonb5 8mo agoThere are two pillars to managing RAM with virtual memory: the obvious one is is writing one program's working set to disk, so that another program can use that memory. The other one - which isn't prevented by disabling swap - is flushing parts of a program which were loaded from disk, and reloading them from disk when next needed. That second pillar is actually worse for interactivity than swapping the working set, which is why disabling swap entirely isn't considered optimal. By far the best approach is just to have an absurd amount of RAM - which of course is a much less accessible option now than it was a year ago.
- jauntywundrkind 8mo agoIf using systemd-oomd, you can launch Firefox into it's own cgroup / systemd.scope, that has memory pressure control settings set to not kill it. ManagedOOMPreference=avoid. https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html#Memory%20Pressure%20Control https://www.freedesktop.org/software/systemd/man/latest/syst... There's a variety of oom daemons. bustd is very lightweight & new. earlyoom has been around a long time, and has an --avoid flag. https://github.com/rfjakob/earlyoom?tab=readme-ov-file#preferred-processes https://github.com/rfjakob/earlyoom?tab=readme-ov-file#prefe... Your concerns are very addressable.
- ajb 8mo agoYeah sytemd-oomd seems tuned for server workloads, I couldn't get it to stop killing my session instead of whichever app had eaten the memory. Honestly on the desktop I'd rather a popup that allowed me to select which app to kill. But the kernel doesn't seem to even be able to prioritize the display server memory.
- 0xbadcafebee 8mo agoLinux being... Linux, it's not easy to use, but it can do what you want. 1. Use `choom` to give your Firefox PIDs a score of +1000, so they always get reaped first 2. Use systemd to create a Control Group to limit firefox and reap it first (https://dev.to/msugakov/taking-firefox-memory-usage-under-control-on-linux-4b02 https://dev.to/msugakov/taking-firefox-memory-usage-under-co...) 3. Enable vm.oom_kill_allocating_task to kill the task that asked for too much memory 4. Nuclear option: change how all overcommiting works (https://www.kernel.org/doc/html/v5.1/vm/overcommit-accounting.html https://www.kernel.org/doc/html/v5.1/vm/overcommit-accountin...)
- man8alexd 8mo ago3. vm.oom_kill_allocating_task is a footgun. It kills the last task that asked for memory and it could be any random task in the system. 4. disabling overcommit is another footgun, it makes malloc fail long before the memory is exhausted. See for a detailed explanation https://unix.stackexchange.com/a/797888/1027 https://unix.stackexchange.com/a/797888/1027
- delamon 8mo agoYou can bump /proc/$firefox_pid/oom_score_adj to make it likely target. The easiest way is to make wrapper script that bumps the score and then starts firefox. All children will inherit the score.