Can't constrain Firefox memory with `systemd-run` and `MemoryMax`

Folks, I have an absolutely unjustifiably absurd number of tabs open across a few windows for which the only person to blame is moi!

Before enforcing some discipline on myself, I must discipline FF - because, at the moment, it won’t open for lack of memory on a 32Gig system! And, until it does open, I can’t begin the cull.

Optimisations made to about:config

browser.tabs.unloadOnLowMemory T
browser.low_commit_space_threshold_percent 75
browser.low_commit_space_threshold_mb 21292
browser.tabs.min_inactive_duration_before_unload 600000
browser.tabs.fadeOutUnloadedTabs T
browser.tabs.fadeOutExplicitlyUnloadedTabs T
dom.ipc.processCount 4
dom.ipc.processCount.webIsolated 2
layers.acceleration.force-enabled F
gfx.webrender.all T
browser.cache.memory.capacity 38106
browser.cache.disk.parent_directory /run/user/1002/firefox
media.hardware-video-decoding.force-enabled T

I’m running leap 16.1.

After the above optimisations I started following links (eg here and here) to constrain memory with cgroups and systemd and was puzzled by lack of success.

I added cgroup_enable=memory and swapaccount=1 to kernel options though my impression is those flags are turned on by default in recent kernels.

I then followed the testing section here and discovered that these systemd/ cgroup constraints are not working:

:~> systemctl --user show sd-firefox.scope | grep Memory
MemoryCurrent=[not set]
MemoryPeak=[not set]
MemorySwapCurrent=[not set]
MemorySwapPeak=[not set]
MemoryZSwapCurrent=[not set]
MemoryAvailable=[not set]
EffectiveMemoryMax=infinity
EffectiveMemoryHigh=infinity
MemoryAccounting=yes
DefaultMemoryLow=0
DefaultStartupMemoryLow=0
DefaultMemoryMin=0
MemoryMin=0
MemoryLow=0
StartupMemoryLow=0
MemoryHigh=infinity
StartupMemoryHigh=infinity
MemoryMax=infinity
StartupMemoryMax=infinity
MemorySwapMax=infinity
StartupMemorySwapMax=infinity
MemoryZSwapMax=infinity
StartupMemoryZSwapMax=infinity
MemoryZSwapWriteback=yes
MemoryLimit=infinity
ManagedOOMMemoryPressure=auto
ManagedOOMMemoryPressureLimit=0
ManagedOOMMemoryPressureDurationUSec=[not set]
MemoryPressureWatch=auto
MemoryPressureThresholdUSec=200ms
:~>

Why?

PS the command:
:~> systemd-run --user --scope --property=MemoryHigh=10G --property=MemoryMax=18G /usr/bin/firefox

The answer appears to be:-

:~> sudo cp /usr/lib/systemd/system.conf.d/20-defaults-SUSE.conf /etc/systemd/system.conf.d/20-defaults-SUSE.conf
:~> sudo nano /etc/systemd/system.conf.d/20-defaults-SUSE.conf
:~> sudo cat /etc/systemd/system.conf.d/20-defaults-SUSE.conf
[sudo] password for machine: 
# This drop-in contains specific defaults used by SUSE distributions.
#
# Do not edit this file, it will be overwritten on update.
#
# If you need to override one of the options, please create your own
# drop-in in /etc/systemd with a higher priority (preferably greater
# than 70).

[Manager]
# Memory accounting incurs performance penalties. Let's keep it
# disabled by default since the actual use case for enabling it is not
# clear (jsc#PM-2229).
DefaultMemoryAccounting=yes
:~>

Which I came across completely by chance looking to use system.conf for something completely unrelated.

1 Like

I discovered that compressed tabs in ‘tab groups’ might free up space in the tab bar but do not free up memory, instead they remain fully loaded in memory - so the answer, for me at least, is to not just group tabs, but to then right-click its label on the tab bar, then select ‘Save and close group’.

Your systemd/cgroup configuration is wrong. Follow:
https://forums.opensuse.org/t/tumbleweed-probleme-mit-gierigen-node-js-tasks/164083/17

# more /etc/systemd/system/user.slice.d/99-Desktop.conf |grep -v ^#

[Slice]
CPUAccounting=yes
IOAccounting=yes
MemoryAccounting=yes
TasksAccounting=yes
CPUQuota=180%
MemoryMax=80%
MemorySwapMax=0
TasksMax=2000
# systemctl status user.slice

● user.slice - User and Session Slice
     Loaded: loaded (/usr/lib/systemd/system/user.slice; static)
    Drop-In: /etc/systemd/system/user.slice.d
             └─99-Desktop.conf
     Active: active since Thu 2026-07-16 19:15:07 CEST; 12min ago
       Docs: man:systemd.special(7)
         IO: 993.3M read, 13.8M written
      Tasks: 556 (limit: 2000)
     Memory: 3.3G (max: 12.4G swap max: 0B available: 9.0G)
        CPU: 5min 50.015s
     CGroup: /user.slice
             └─user-1000.slice

Check:

# systemd-cgtop

I ran Firefox with 1000 pinned tabs. I simply started it without network connection. It took about 2-3 GB of RAM and ~ 30s to start. Then I used it - opened new tabs, etc. Then I closed it.

To fight OOM use swap + MGLRU.

@GrandDixence2 you’re referring to my Comment 3 above?

I came across that setting completely by chance while changing systemd LogLevel to debug. Far from its use case being unclear, it seems its use case is pretty basic to linux system management! Why would anyone turn off? And as a default!

Is the effect of the config you suggest is to confine the whole user to those limits?
If so, I’d assume every system has a different optimum? This is what the omniscient search engine returns for my system.

Also, why do you suggest systemd.unified_cgroup_hierarchy=1 and not =2?

@Svyatko very interesting, thank you - I found this helpful article:
Enable the magical Multi-Gen LRU AKA MGLRU on openSUSE Tumblewed, stay away from OOM today!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.