How to Configure Systemd Out-of-Memory Daemon (systemd-oomd) in Ubuntu

When physical RAM and swap space become exhausted on a Linux system, the kernel’s native Out-of-Memory (OOM) killer kicks in as a last resort. Historically, the kernel OOM killer intervenes only when memory allocation fails entirely, often after the operating system has spent minutes thrashing disk swap, leaving desktop environments completely frozen and servers unresponsive.

Ubuntu modernised memory pressure management by integrating systemd-oomd. Leveraging Linux kernel Control Groups version 2 (cgroups v2) and Pressure Stall Information (PSI), systemd-oomd monitors memory and swap pressure continuously in user space, gracefully terminating rogue processes before system-wide unresponsiveness occurs.

Understanding PSI Metrics and systemd-oomd Operation

Unlike legacy mechanisms that evaluate raw free megabytes, systemd-oomd monitors how long CPU threads spend waiting for memory allocations (Pressure Stall Information):

  • Memory Pressure (PSI): Measures the percentage of wall-clock time that tasks are stalled waiting for memory pages to swap in or cache to reclaim.
  • Swap Usage Ceiling: Monitors the percentage of total system swap consumed. When swap approaches full saturation, systemd-oomd intervenes early to prevent kernel livelock.
  • Targeted cgroup Termination: Rather than picking processes at random, systemd-oomd terminates an entire cgroup slice (such as an errant browser tab process group or runaway build container) to cleanly reclaim resource headroom.

Checking systemd-oomd Status and Pressure Metrics

To verify that systemd-oomd is running on your Ubuntu installation, query its service status:

systemctl status systemd-oomd

To inspect live memory pressure thresholds and active cgroup monitoring statistics, run the dedicated inspection command:

oomctl

The oomctl output lists all cgroup slices currently monitored (such as [email protected] or system.slice), their configured pressure limits, and current 10-second, 60-second, and 300-second pressure averages.

Customising Global systemd-oomd Configuration

Global monitoring thresholds are defined in /etc/systemd/oomd.conf. To fine-tune behaviour:

  1. Open the configuration file in a text editor:
    sudo nano /etc/systemd/oomd.conf
  2. Adjust the primary operational directives under the [OOM] section:
    [OOM]
    SwapUsedLimitPercent=90%
    DefaultMemoryPressureLimitPercent=60%
    DefaultMemoryPressureDurationSec=20s
    • SwapUsedLimitPercent: Initiates intervention when swap consumption exceeds this percentage (default is 90%).
    • DefaultMemoryPressureLimitPercent: The memory pressure threshold that triggers intervention if sustained (default is 60%).
    • DefaultMemoryPressureDurationSec: The duration that memory pressure must remain above the threshold before systemd-oomd acts (default is 20s).
  3. Save the file and restart the daemon:
    sudo systemctl restart systemd-oomd

Configuring Per-Service OOM Directives in Unit Files

You can selectively protect critical production services (like databases) or enforce aggressive memory termination on background workers using drop-in service overrides:

  1. Edit your target service using systemctl edit:
    sudo systemctl edit worker.service
  2. Add specific ManagedOOM directives under the [Service] section:
    [Service]
    ManagedOOMMemoryPressure=kill
    ManagedOOMMemoryPressureLimit=50%
    ManagedOOMSwap=kill
  3. Save the drop-in. Systemd will monitor that specific service’s cgroup and terminate its processes if memory pressure exceeds 50% for the configured interval.

Auditing systemd-oomd Action Logs

When systemd-oomd terminates a process or cgroup, it logs detailed forensic diagnostics to the systemd journal. To review recent kill events:

journalctl -u systemd-oomd --since "24 hours ago"

The log details the exact cgroup slice targeted, memory pressure statistics at the moment of action, and the specific processes killed to restore system responsiveness.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.