Limit Firefox (nightly) resource usage with systemd
Created:
Introduction
I have been using Firefox for a long time and I love it. However, I have noticed that it can be a resource hog sometimes, especially when I have multiple tabs open with websites that pull a lot of data frequently. So I decided to look for a solution to limit Firefox's resource usage.
Systemd
Systemd is a simple solution for limiting Firefox's resource usage. It allows you to limit the resources that Firefox can use, such as memory and CPU. Like Docker, which uses the same Linux kernel features (cgroups) to limit container resources, systemd can do the same for individual applications.
Since Debian 11 (Bullseye), Fedora 39, and Arch Linux made cgroups v2 the default, you can use systemd to limit Firefox's resource usage without any additional kernel configuration. Otherwise, you will need to enable cgroups v2 on your system by following the instructions in the systemd documentation.
Create a user service file in ~/.config/systemd/user/firefox-nightly.service with the following content:
[Unit]
Description=Firefox Nightly with Memory Limits
[Service]
ExecStart=/usr/bin/firefox-nightly %u
MemoryHigh=5G
MemoryMax=6G
MemorySwapMax=0
This service file will start Firefox Nightly with a memory limit of 6GB. The %u parameter allows passing a URL to Firefox when launching it.
MemoryHigh sets a soft memory limit that triggers warnings and memory reclamation, while MemoryMax is the hard limit—Firefox will be killed if it exceeds this value. I find 6GB to be a good limit for most use cases (machines with 16GB to 64GB of RAM), but you should adjust it based on your needs and available RAM. For example, use 4G for machines with 8-16GB of RAM, or 8G for machines with 64GB+ RAM.
The MemorySwapMax=0 option will prevent Firefox from using swap space, which can help improve performance.
After creating the service file, reload the systemd daemon:
systemctl --user daemon-reload
You can now test the service by starting firefox-nightly in the terminal:
systemctl --user start firefox-nightly.serviceLauncher
Alternatively, you can edit your launcher to start Firefox with the systemd service instead of directly starting the Firefox binary. Create or edit a desktop entry file in ~/.local/share/applications/firefox-nightly.desktop with the following content (this works across most Linux desktop environments):
[Desktop Entry]
Version=1.0
Type=Application
Name=Firefox Nightly
Exec=systemctl --user start firefox-nightly.service
Icon=firefox-nightly
StartupWMClass=firefox-nightly
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss;application/rdf;x-scheme-handler/http;x-scheme-handler/https;
Terminal=false
StartupNotify=true
Actions=new-window;new-private-window;
This desktop entry ensures that Firefox will be started with the resource limits defined in the systemd service file whenever you launch it from your application menu. Note: This only applies to newly launched instances; if Firefox is already running, stop it first with systemctl --user stop firefox-nightly.service.
Check limits
Check if the limits are applied using:
systemctl --user status firefox-nightly.service
This command will show you the current resource usage and limits for the Firefox Nightly service. You should see the memory usage limited to the values you set in the service file:
❯ systemctl --user status firefox-nightly.service
● firefox-nightly.service - Firefox Nightly with Memory Limits
Loaded: loaded (/home/exiguus/.config/systemd/user/firefox-nightly.service; static)
Active: active (running) since Tue 2026-02-17 17:48:38 CET; 1h 14min ago
Invocation: 9b325d84058b4b2da87e40a1c6db847a
Main PID: 39095 (firefox-bin)
Tasks: 461 (limit: 18637)
Memory: 2.4G (high: 6G, max: 6G, swap max: 0B, available: 3.5G, peak: 2.5G)
CPU: 35min 54.267sNotes
This approach limits Firefox at the user level. When memory limits are exceeded, Firefox may experience performance degradation or be killed by the system. If you need to limit Firefox system-wide (for all users), you would need to create a system service file in /etc/systemd/system/ instead. The desktop entry method ensures the systemd service is always used when launching Firefox from your application menu.
Feedback
Have thoughts or experiences you'd like to share? I'd love to hear from you! Whether you agree, disagree, or have a different perspective, your feedback is always welcome. Drop me an email and let's start a conversation.