Course contentsShow
← Linux
Lesson 614 of 1,8196. Systemd Internals and Unit OrchestrationFree lesson

Debugging Cgroup Resource Leaks

Use systemd-cgtop to monitor real-time resource allocation and process leaks.

In this lesson, you will learn how to use systemd-cgtop to identify runaway processes and pinpoint hidden cgroup resource leaks in real-time.

The "Leak" Problem

When a service or unit consumes memory or CPU in a way that never returns to baseline, we often call this a resource leak. While standard tools like top show you individual processes, they often fail to account for the hierarchical structure of Linux Control Groups (cgroups). If a background service spawns sub-processes that "orphan" themselves or remain trapped in a specific cgroup slice, top might hide the cumulative impact.

Visualizing Cgroups with systemd-cgtop

To see the big picture, we use systemd-cgtop. It provides a top-like interface, but instead of sorting by process ID, it sorts by cgroup path. This allows you to see exactly which service unit is consuming the most resources, regardless of how many child processes it has spawned.

Run the command in your terminal:

systemd-cgtop

Once running, you will see columns for Tasks, %CPU, Memory, and Input/Output. If a specific unit's memory usage is climbing steadily over time, that is a clear indicator of a leak within that service's scope.

Interpreting the Output

If you suspect a leak, watch the MEMORY column for your target unit. If you see a unit consuming significantly more memory than its defined configuration or historical baseline—and that number never decreases—you have found your culprit.

Because systemd-cgtop groups by the unit hierarchy, you can quickly identify if a "transient unit" (which you learned about in Lesson 14) or a nested service is the source of the bloat. Once identified, you can compare this against your unit's status (Lesson 24) to confirm if the leak is tied to a specific executable or a configuration error in your service file.

Key Takeaway: Use systemd-cgtop to monitor aggregate resource consumption by unit, allowing you to catch memory and CPU leaks that are otherwise hidden by standard process-level monitoring.