Is this behaviour normal on linux/fedora/gnome, it allows an app fill all the ram?

I remember that in windows this never happened , im using fedora workstation for like 2 years, and for me this is the biggest issue (i dont know if is a gnome/fedora or linux in general problem). Basically it allows the app (usually browsers ) to fill all the ram (16gb here and 8gb zram) and become unresponsive, needing to force close apps or turn off pc to reboot

Shouldnt be a way to prevent a misbehaviour app fill all the ram and crash the pc ?

1 Like

I think if your browser eats 16 gb of RAM there is something wrong with the browser.
Anyway, you may find this useful:

1 Like

I agree with OP, the issue is that a single app can take down the whole desktop by running out of memory. Somehow systemd-oomd on a default install doesn’t seem to be able to kill the offending process, and performing a hard reboot appears to be the only solution.

You didn’t say which browser, but I’ve been seeing a similar issue for several months where Firefox will become un-responsive and is using up all my memory (32G). When this happens, Firefox can’t be killed and if I have other apps running they are often the same. So I was suspecting a Firefox memory leak or something. So I’ve tried changing to Chrome and so far have not seen the problem. Hopefully Firefox will eventually fix it and I can move back to Firefox. So you might want to see if using another browser makes the problem go away.

My browser is firefox, the same behaviour happens with rpm or flatpak version

well, its the one shipped default with fedora, i just added essential extensions like ublock and dark reader. I think firefox has memory leak

Exactly, a single app takes down the whole system

Glad is not only me , did you use extensions with firefox , like dark reader and ublock ?

Its enabled by default, but dosnt make any difference in this issue

I’m not sure systemd oom service being enabled by itself will do what you want. Looking at the output of oomctl dump the oom memory pressure duration settings for what i think is my desktop session is like 20seconds. So the oom default settings might not actually be tuned to respond quickly enough. oom is complicated. To get the oom to respond faster, may require some tuning.

But that being said, here is how I would test to see if I could set a hard memory limit for firefox or other application running under my GNOME desktop.

First I’d identify the systemd unit name for my current firefox.
systemd-cgls | grep firefox | grep scope
This should show you the systemd scope associated with a firefox application started from either the gnome or kde destops i think.
For me its gnome, so I then run this to see the systemd configuration
systemctl --user cat app-gnome-org.mozilla.firefox-XXXX.scope
XXXX is a think the control group identifier or PID of the parent process in the control group. The point is its an unique tacked on to the end of the discoverable name.

There’s nothing in the configuration that suggests any hard memory limits. I can start trying to figure out what limits will work using systemd-run.

Using systemd-run from a console to play test hard memory limit settings.
systemd-run --quiet --user --scope -p MemoryMax=500M /usr/b-p MemorySwapMax=0 in/firefox

We these settins firefox crashes immediately.. that 500M with no swap is not enough.
So i tune those 2 a bit so I can get firefox up and running with a max on memory, but using some swap if it needs.
systemd-run --quiet --user --scope -p MemoryMax=4G /usr/b-p MemorySwapMax=1G in/firefox

I can then check the generated scope and see that the MemoryMax property is set
systemd --user cat run-XXXXX-YYYYY.scope

Cool, now I can edit the gnome session managed firefox and add the settings I want just as they appear in my test under systemctl-run

systemd --user edit app-gnome-org.mozilla.firefox-XXXX.scope
and add as directed:

[Scope]
MemoryMax=4G
MemorySwapMax=1G

That file gets saved and now if I do systemctl --user cat again I see the properties as active.

But if I want to make this work for all future firefox instances managed by gnome all i need to do is rename the directory holding the generated override file to app-gnome-org.mozilla.firefox-.scope.d
And when I logout and back into the desktop all firefox instances started by gnome will have those memory and swap limits applied!

Heres a good write up on what that looks like in the context of KDE.

Following that writeup, I’d just need to change the config filename to:

~/.config/systemd/user/app-gnome-org.mozilla.firefox@.scope.d/override.conf

And place the systemd scope properties I want to make sure are enabled into this file. systemd should read that file when my gnome desktop fires up an firefox application.

You could go even further and have everything listed under app- with similar hard memory limits.

2 Likes

I had been running into several cases of system freezes using Fedora’s default swap layout, which relies entirely (and only) on zram. For a system with a limited amount of memory as mine (16GB), it regularly experienced system lockups by filling up RAM with games, applications, and local LLMs. However, the crashes weren’t specifically tied to Firefox as seems to be your case…

I managed to make my system much more stable by creating an additional 8GB swap partition on an HDD and enabling that as lower priority swap.

The system’s OOM never did properly work preventing me from having to restart the unresponsive PC.

hi
i use fedora 42 mate in an old laptop with only 4gb of ram and a desktop with 16gb of ram both encrypted luks2. for safety, in addition to the zram automatically activated during installation I always create a luks2 swap partition. in the end finding a swap fedora configures zram priority 100 and swap -2. in extreme cases it could be useful. however, lately, i noticed a somewhat high cpu and ram consumption with firefox and for this reason i am using chrome much more…

thanks to your detailed answer jef, do you know a easier approach to make this happens to all apps (even flatpak) ?

In my case im sure most of the times is the firefox the culprit since i use it more, but not always, and as others answered here, looks like is something with zram and the oomkiller not working as expected

I think if you have an override config file in ~/.config/systemd/user/app-.scope.d/ then systemd will apply to all apps even flatpaks, well anything that follows the naming convention for a scope that starts with the app-

Looking real quick when I open up flatpak based zoom and see that in the systemd-cgls list there is app-flatpak-us.zoom.Zoom-XXXXXXXX.scope so systemd should take the app-.scope.d/override.conf into effect and apply it to any the flatpaks as well.

So far I’ve just played with setting hard mem/swap limits. The oom stuff is a bit trickier for me to understand how it works in order to tune. But you should be able to set oom related properties as well and get systemd to be more aggressive about oom conditions for specific app scopes… i think.

I would caution you about setting very narrow limits for all apps though, because that can get weird really fast.

Just did a quick confirmation. If I set up the app- override it applies to flatpaks just fine.

I do have to logout and log back in to get the systemd user session manager to reload the on disk configs. there’s probably a way to have it do that without the logout but no biggie.

Here’s what I have

$ cat ~/.config/systemd/user/app-.scope.d/override.conf 
[Scope]
MemoryMax=16G
MemorySwapMax=4G

And after logout/login here is what flatpak zoom systemd scope has for hard limits

$ systemctl --user cat app-flatpak-us.zoom.Zoom-3630860376.scope
...
# /home/jspaleta/.config/systemd/user/app-.scope.d/override.conf
[Scope]
MemoryMax=16G
MemorySwapMax=4G
...

The output of the systemctl cat gives a hint as to which config file on disk properties are being pulled from. So if you go through these steps and use the systemctl cat command to check you will be able to verify that your changes are being taken up.

I have a suspicion that the zram swap is “too fast” in some respect for the userspace oom service to react with the existing default tuning.

The oom stuff is a little weird because its meant to sort of be conservatively proactive. Limits have to be breached for long enough before it takes action. And I think “long enough” may be relative to how efficient the swap activity is.

Did you ever experience the oom service taking an action once you setup physical disk swap to use?

thanks, i set almost the same here, just adjusted memorymax to 8gb since i have a 16gb system, gonna run with this config these days and see if it solve the issue

Not really, I don’t usually have that much stuff running simultaneously on my PC and the extra swap on the hard drive made it very stable, never crashed again, but I didn’t test it to its limits (OOM) as it’s a relatively old HDD and just filling up the 8GB of it would take ages. I didn’t put that swap partition on my SSD due to wear concerns.

I am typing in Firefox on a low end Celeron system with 4G of RAM. It doesn’t hang or crash. My max load is Firefox + TorBrowser (Firefox ESR) + Thunderbird + GIMP. When I do something heavy like web mail with Tor Browser, Youtube video on Firefox stops for a moment. It happens also if I run DNF update. It doesn’t seem like a big issue like the one described above and I guess it is the CPU, not the RAM.

Anyway, if there is something wrong with Firefox there aren’t many options besides using Chromium or trying a clean new FF profile. Or hope for a fix with next updates.