Remix.run Logo
rwmj 9 hours 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.

0xbadcafebee 8 hours ago | parent | next [-]

Linux 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-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-accountin...)

pmontra 8 hours ago | parent | prev | next [-]

I'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 7 hours ago | parent [-]

There 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.

delamon 8 hours ago | parent | prev | next [-]

You 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.

jauntywundrkind 8 hours ago | parent | prev [-]

If 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/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#prefe...

Your concerns are very addressable.

ajb 5 hours ago | parent [-]

Yeah 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.