An application exits unexpectedly, yet monitoring shows that the server still has available memory. Simply raising its memory limit may hide the real cause. The Linux kernel, systemd-oomd and service control groups can all play a part in handling memory-related failures. Start with the termination time and the evidence trail, rather than restarting the service.
This guide uses Ubuntu Server 24.04 LTS, systemd and cgroup v2. In the commands, app.service stands for the service under investigation; replace it with the actual unit name before running them. AmdBit’s EPYC 7543P dedicated servers offer two memory options: 128GB and 256GB DDR4-3200 ECC. However, total server memory is not the same as the amount available to an individual service.
1. Distinguish three sources of termination
Kernel OOM events can be system-wide or confined to a memory control group. System-wide OOM involves difficulty allocating memory across the system; a control-group OOM may simply mean that one group has reached its hard limit while memory remains available to other services. Kernel logs usually identify the terminated process and include relevant memory information.
systemd-oomd is a userspace manager that selects control groups to terminate based on configuration and memory pressure. It may act before a kernel OOM occurs. Do not assume it is enabled on every system: check its service status and logs first.
MemoryMax is a hard control-group limit, not a separate program that sends signals. When the limit is reached, the kernel first attempts to reclaim memory. If it still cannot satisfy an allocation, an OOM event may occur within that control group. MemoryHigh primarily triggers reclaim and throttling; it does not mean immediate termination.
Exit code 137 usually corresponds to SIGKILL, but it does not prove that an OOM event occurred. Manual termination, management tools and memory managers can all produce this result.
2. Preserve evidence before restarting
First, record the approximate incident time, service name, request volume and recent changes. The following commands collect logs from the last half hour and the current state. The output directory is accessible only to the current account; reading system logs requires appropriate permissions.
umask 077
out="$HOME/memory-evidence-$(date +%s)"
mkdir -p "$out"
sudo journalctl -k --since "-30 min" --no-pager \
> "$out/kernel.log"
sudo journalctl -u app.service --since "-30 min" --no-pager \
> "$out/service.log"
sudo journalctl -u systemd-oomd --since "-30 min" --no-pager \
> "$out/oomd.log"
systemctl show app.service \
-p Result -p ExecMainCode -p ExecMainStatus -p NRestarts \
-p ControlGroup -p MemoryCurrent -p MemoryPeak \
-p MemoryHigh -p MemoryMax > "$out/unit.txt"
free -h > "$out/memory.txt"
cat /proc/pressure/memory > "$out/pressure.txt"
swapon --show > "$out/swap.txt"
Read through the raw logs before searching for clues such as oom, Killed process and Memory cgroup. Avoid keeping only a few filtered lines. A service log entry saying that a process was terminated by a signal must be matched against kernel or oomd records; timestamps that are merely close together do not establish causation.
Automatic restarts may mean that the current state describes a new process. Recreating a unit may also clear the original control-group counters. If the incident state is no longer available, explicitly document the gaps in the evidence. Do not treat a currently healthy state as a record of conditions during the incident.
3. Cross-check control-group counters and PSI
Confirm that the control-group filesystem is v2, then retrieve the service’s control-group path. These commands are read-only and do not change any limits. The directory may no longer exist after the service stops.
stat -fc %T /sys/fs/cgroup
cg=$(systemctl show app.service -p ControlGroup --value)
if [ -n "$cg" ] && [ -d "/sys/fs/cgroup$cg" ]; then
for name in memory.current memory.high memory.max \
memory.events memory.pressure; do
printf '\n%s\n' "$name"
sudo cat "/sys/fs/cgroup$cg/$name"
done
fi
In memory.events, an increase in high means that the high threshold was exceeded and reclaim or throttling occurred. An increase in max means that the hard limit was reached, not that a process was killed every time. oom records OOM conditions within the control group, while oom_kill counts processes belonging to that group that were terminated by the OOM killer.
These are cumulative counters and may include events from child groups. Compare differences over time within the lifetime of the same control group. To exclude child-group events, check whether the system provides memory.events.local. Also follow the control-group path upwards to inspect parent limits: a service’s own memory.max value of max does not mean that no limits apply higher up.
For PSI, some reports the proportion of time during which some tasks are stalled by memory pressure, while full reports the proportion during which all non-idle tasks are stalled simultaneously. These are not memory-utilization figures, and there is no single threshold suitable for every workload. Interpret sustained pressure alongside response latency, throughput and swap activity.
Identify oomd’s decisions
systemctl is-active systemd-oomd
systemctl show app.service \
-p ManagedOOMMemoryPressure -p ManagedOOMSwap
if command -v oomctl >/dev/null 2>&1; then
sudo oomctl
fi
A service may be affected by a parent slice’s policy even if the relevant policy is not enabled on the service itself. oomctl shows what is currently being monitored; attribution of an incident must still rely on oomd logs from the same time window. If oomd is not enabled or there are no records, do not assume it was responsible.
4. Make evidence-based changes, not blanket adjustments
If OOM occurs only within a control group and system-wide pressure is low, first check whether concurrency, per-worker memory use and the hard limit are appropriately matched. Before raising the limit, leave room for the kernel, other services and the file cache. Do not simply allocate the server’s entire memory capacity across service limits.
If the whole system is experiencing sustained reclaim or swapping, first reduce concurrency and investigate abnormal memory growth and queued requests. A low free-memory value in free does not by itself indicate a fault. MemAvailable is a better estimate of available memory, but it still cannot replace pressure and application metrics.
Swap can absorb short-lived peaks, but it does not fix a memory leak. Sustained swapping may leave a service unresponsive before it exits. Conversely, the absence of swap does not by itself prove a configuration error; the decision to configure it should depend on the workload’s latency requirements.
If the evidence points to oomd, inspect the monitored slices, pressure policies and service grouping. Disabling oomd merely removes one layer of protection; it does not guarantee that a kernel OOM will not occur later. Validate every adjustment in an isolated environment before scheduling changes to production.
5. Retest with the same workload
Keep software versions, input size and concurrency fixed during retesting. Record control-group paths and event counters before and after the changes. Do not deliberately exhaust memory on a server running production workloads, or run several stress tools at once and create results whose causes cannot be distinguished.
Acceptance checks should include at least the following:
- No new unexpected service restarts, and any exit reasons can be explained.
- No additional OOM or termination counts within the same time window.
- Headroom remains between peak memory use and the limits, with no sustained worsening of pressure.
- Response latency and throughput meet application requirements, rather than the process merely staying alive.
- Temporary workloads have stopped after testing, and configuration differences and rollback procedures have been archived.
If memory use continues to grow as the same task is repeated, move on to application heap analysis instead of repeatedly raising the allowance. The final record should answer “what terminated the process, which boundary was reached, and how was the change validated?”—not simply state “normal operation resumed after a restart.”
Frequently asked questions
Does exit code 137 prove that the kernel OOM killer ran?
No. It usually indicates termination by SIGKILL, which can come from kernel OOM handling, systemd-oomd, an administrator or a management tool. Correlate logs and cgroup counters from the same interval.
Why can a service be killed when the host still has available memory?
Its cgroup may have reached MemoryMax, or systemd-oomd may have selected it under a memory-pressure policy. Check service and ancestor cgroup limits and logs rather than relying on MemAvailable alone.
Dedicated EPYC 7543P Server from $460.4/month
Choose from two ECC memory options. Confirm the configuration and amount due on the configuration page.