exiguus.blog

Personal blog

Limit Firefox (nightly) resource usage with systemd

Created: 2026-02-17

Introduction

I have been using Firefox for a long time and I love it. But 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 this. It allows you to limit the resources that Firefox can use, such as memory and CPU. Docker uses the same Linux kernel features (cgroups) to limit the resources of containers, so we can use systemd to limit Firefox's resource usage without any additional configuration.

Since Debian 11 (Bullseye), Fedora 39 and Arch 2021, cgroups v2 is the default. If you run a system with cgroups v2, you can use systemd to limit Firefox's resource usage without any additional configuration. Else you will need to enable cgroups v2 on your system by following the instructions in the systemd documentation.

First, we need to create a systemd service file for Firefox. We will 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=6G
MemoryMax=6G
MemorySwapMax=0

This service file will start Firefox Nightly with a memory limit of 6GB. You can adjust the memory limits as needed. Personally, I find that 6GB is a good limit for my use case (machines from 16GB to 64GB of RAM), but you can set it to a different value based on your needs and the amount of RAM you have available. The MemorySwapMax=0 option will prevent Firefox from using swap space, which can help improve performance.

After creating the service file, we need to reload the systemd daemon:

systemctl --user daemon-reload

Now we can start firefox-nightly in the terminal with:

systemctl --user start firefox-nightly.service

Launcher

Alternatively, you can edit your launcher to start Firefox with the systemd service instead of directly starting the Firefox binary. You can do this by creating or editing a desktop entry file in ~/.local/share/applications/firefox-nightly.desktop (for GNOME) with the following content:

[Desktop Entry]
Version=1.0
Type=Application
Name=Firefox Nightly
Exec=systemctl --user start firefox-nightly.service
Icon=firefox-nightly
StartupWMClass=firefox-nightly
Categories=GNOME;GTK;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 will ensure that Firefox is always started with the resource limits defined in the systemd service file.

Check limits

To check if the limits are applied, you can use the systemctl --user status firefox-nightly.service command, which will show you the current resource usage and limits for the Firefox Nightly service. You should see that the memory usage is 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.267s

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.

<​​​​limit-firefox-resource-systemd​​​@exiguus​.​​blog​​​>

Tags